Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 888 Bytes

instructions.md

File metadata and controls

56 lines (42 loc) · 888 Bytes

Register provider

The provider must be registered inside start/app.js file and after @adonisjs/validator/providers/ValidatorProvider.

const providers = [
  '@adonisjs/validator/providers/ValidatorProvider',
  '@jayrchamp/adonis-strict-validator/providers/ValidatorProvider'
]

Usage

Create a Validator file in App/Validators/ (ex.: App/Validators/Example) and set strict getter to true.

// App/Validators/Example/index.js

class ExampleValidator {
  
  get strict () {
    return true
  }

  get rules () {
    return {
      gender: 'string'
    }
  }
}

module.exports = ExampleValidator
// Request body example
{
  gender: "male",
  pogo: "yolo"

}

// Response example
{
  code: "E_VALIDATION_FAILED",
  errors: [
    {
      message: "strict validation failed on field",
      field: "pogo",
      validation: "strict_fields"
    }
  ]
}