Wondering what’s next for npm?Check out our public roadmap! »

@jayrchamp/adonis-strict-validator

2.1.2 • Public • Published

Adonis Strict Validator

This package adds the ability to Validators to enforce requests to contain only the fields present in the rules getter.

Getting Started

Install the package using the adonis CLI.

> adonis install @jayrchamp/adonis-strict-validator

Follow instruction that are displayed (or read them here).

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"
    }
  ]
}

Install

npm i @jayrchamp/adonis-strict-validator

DownloadsWeekly Downloads

20

Version

2.1.2

License

none

Unpacked Size

8.98 kB

Total Files

9

Last publish

Collaborators

  • avatar