@@ -50,9 +50,9 @@ var { Validator, ValidationError } = require('express-json-validator-middleware'
5050var validator = new Validator ({allErrors: true });
5151```
5252
53- 3 . * Optional* - Define a shortcut function. Bind is necessary here in order to pass ` this ` correctly
53+ 3 . * Optional* - Define a shortcut function.
5454``` js
55- var validate = validator .validate . bind (validator) ;
55+ var validate = validator .validate ;
5656```
5757
58584 . Use the function as an Express middleware, passing in an options object of the following format:
@@ -96,10 +96,12 @@ var app = express();
9696var bodyParser = require (' body-parser' );
9797
9898var { Validator, ValidationError } = require (' express-json-validator-middleware' );
99+
99100// Initialize a Validator instance first
100101var validator = new Validator ({allErrors: true }); // pass in options to the Ajv instance
102+
101103// Define a shortcut. It is perfectly okay to use validator.validate() as middleware, this just makes it easier
102- var validate = validator .validate . bind (validator) ;
104+ var validate = validator .validate ;
103105
104106// Define a JSON Schema
105107var StreetSchema = {
@@ -167,7 +169,7 @@ validator.ajv.addKeyword('constant', { validate: function (schema, data) {
167169 : schema === data;
168170}, errors: false });
169171
170- // free to use validate() here
172+ // free to validator in middleware now
171173```
172174
173175More info on custom keywords: [ ajv#customs-keywords] ( https://github.com/epoberezkin/ajv/blob/master/CUSTOM.md#defining-custom-keywords )
@@ -208,7 +210,7 @@ In `express-jsonschema`, you could define a required property in two ways. Ajv o
208210 foo: {
209211 type: ' string'
210212 },
211- required: [' foo' ] < --
213+ required: [' foo' ] // <-- correct way
212214 }
213215}
214216
@@ -218,7 +220,7 @@ In `express-jsonschema`, you could define a required property in two ways. Ajv o
218220 properties: {
219221 foo: {
220222 type: ' string' ,
221- required: true
223+ required: true // nono way
222224 }
223225 }
224226}
0 commit comments