# @jayrchamp/adonis-strict-validator

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

Latest version **2.1.5** (published 2022-07-25) · 0 weekly downloads

## Install

```sh
npm install @jayrchamp/adonis-strict-validator
pnpm add @jayrchamp/adonis-strict-validator
yarn add @jayrchamp/adonis-strict-validator
bun add @jayrchamp/adonis-strict-validator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.5 |
| Published | 2022-07-25 |
| First published | 2020-11-19 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | jayrchamp |
| Maintainers | jayrchamp |
| Keywords | validator, schema-validation, adonis, strict |

## Links

- npm: https://www.npmjs.com/package/@jayrchamp/adonis-strict-validator
- Repository: https://github.com/jayrchamp/adonis-strict-validator
- Homepage: https://github.com/jayrchamp/adonis-strict-validator#readme
- Issues: https://github.com/jayrchamp/adonis-strict-validator/issues
- npm.io page: https://npm.io/package/@jayrchamp/adonis-strict-validator

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [@adonisjs/validator](https://npm.io/package/@adonisjs/validator.md) ^5.0.6
- [@adonisjs/generic-exceptions](https://npm.io/package/@adonisjs/generic-exceptions.md) ^2.0.1

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 2.1.5 (latest) — 2022-07-25
- 2.1.2 — 2021-01-22
- 2.1.1 — 2020-12-16
- 2.1.0 — 2020-11-19
- 2.0.1 — 2020-11-19
- 2.0.0 — 2020-11-19

## README

# 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.

```bash
> adonis install @jayrchamp/adonis-strict-validator
```

Follow instruction that are displayed ([or read them here](https://github.com/jayrchamp/adonis-strict-validator/blob/master/instructions.md)).

## Usage

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

```js
// 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

```

```js
// 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"
    }
  ]
}

```

---
_Source: https://npm.io/package/@jayrchamp/adonis-strict-validator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
