2.1.5 • Published 2 years ago

@jayrchamp/adonis-strict-validator v2.1.5

Weekly downloads
7
License
-
Repository
github
Last release
2 years ago

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 {
  
  /**
   * Deny requests containing an unspecified query string or body in the rules object
   */
  get strict () {
    return true
  }

  /**
   * Deny request without query string or body
   */
  get noEmpty () {
    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"
    }
  ]
}
2.1.4

2 years ago

2.1.3

2 years ago

2.1.5

2 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago