express-json-validator-middleware
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "express-json-validator-middleware", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "An Express middleware to validate requests against JSON Schemas", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -149,5 +149,33 @@ # express-json-validator-middleware | ||
## Custom keywords | ||
Ajv supports custom keywords out of the box. They must be defined only after you initialize a Validator, but before you any validate() middleware. Example: | ||
```js | ||
var { Validator, ValidationError } = require('express-json-validator-middleware'); | ||
var validator = new Validator({allErrors: true}); | ||
validator.ajv.addKeyword('constant', { validate: function (schema, data) { | ||
return typeof schema == 'object' && schema !== null | ||
? deepEqual(schema, data) | ||
: schema === data; | ||
}, errors: false }); | ||
``` | ||
More info on custom keywords: [ajv#customs-keywords](https://github.com/epoberezkin/ajv/blob/master/CUSTOM.md#defining-custom-keywords) | ||
## Ajv instance | ||
The Ajv instance can be accessed via validator.ajv. | ||
```js | ||
var { Validator, ValidationError } = require('express-json-validator-middleware'); | ||
var validator = new Validator({allErrors: true}); | ||
validator.ajv // ajv instance | ||
``` | ||
## Tests | ||
```js | ||
``` | ||
npm install | ||
npm test | ||
@@ -160,3 +188,3 @@ ``` | ||
- [scpacetelescope's understanding json schema](http://spacetelescope.github.io/understanding-json-schema/) | ||
- [spacetelescope's understanding json schema](http://spacetelescope.github.io/understanding-json-schema/) | ||
@@ -163,0 +191,0 @@ ## Notes |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14511
217