@ssense/restify-request-validator
Advanced tools
+1
-0
@@ -5,2 +5,3 @@ export class RequestValidator { | ||
| public validate(req: any, res: any, next: Function): void; | ||
| public disableFailOnFirstError(): void; | ||
| } |
+1
-1
| { | ||
| "name": "@ssense/restify-request-validator", | ||
| "version": "1.0.6", | ||
| "version": "1.0.7", | ||
| "description": "Restify requests validator", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
+35
-0
@@ -118,2 +118,36 @@ # Restify request validator | ||
| #### Behavior | ||
| By default the validator will throw an error on the first validation failure, if you want to change this behavior to get all the validation errors, you can call the `disableFailOnFirstError` method on your `validator` object: | ||
| ##### For javascript project | ||
| ```js | ||
| // Require module | ||
| var restifyValidation = require('@ssense/restify-request-validator'); | ||
| ... | ||
| // Create restify server | ||
| var server = restify.createServer(); | ||
| ... | ||
| // Add middleware | ||
| var validator = new restifyValidation.RequestValidator(); | ||
| validator.disableFailOnFirstError(); | ||
| server.use(validator.validate.bind(validator)); | ||
| ``` | ||
| ##### For typescript project | ||
| ```js | ||
| // Import module | ||
| import {RequestValidator} from '@ssense/restify-request-validator'; | ||
| ... | ||
| // Create restify server | ||
| const server = restify.createServer(); | ||
| ... | ||
| // Add middleware | ||
| const validator = new RequestValidator(); | ||
| validator.disableFailOnFirstError(); | ||
| server.use(validator.validate.bind(validator)); | ||
| ``` | ||
| ## Development | ||
@@ -146,2 +180,3 @@ | ||
| * **Rémy Jeancolas** - *Initial work* - [RemyJeancolas](https://github.com/RemyJeancolas) | ||
| * **Mickael Burguet** - *Add `disableFailOnFirstError` behavior* - [rundef](https://github.com/rundef) | ||
@@ -148,0 +183,0 @@ ## License |
@@ -20,3 +20,3 @@ import {ParamValidation} from './ParamValidation'; | ||
| public disableFailOnFirstError(): any { | ||
| public disableFailOnFirstError(): void { | ||
| this.failOnFirstError = false; | ||
@@ -23,0 +23,0 @@ } |
50827
2.2%827
0.12%184
23.49%