@@ -50,9 +50,9 @@ var { Validator, ValidationError } = require('express-json-validator-middleware'
50
50
var validator = new Validator ({allErrors: true });
51
51
```
52
52
53
- 3 . * Optional* - Define a shortcut function. Bind is necessary here in order to pass ` this ` correctly
53
+ 3 . * Optional* - Define a shortcut function.
54
54
``` js
55
- var validate = validator .validate . bind (validator) ;
55
+ var validate = validator .validate ;
56
56
```
57
57
58
58
4 . Use the function as an Express middleware, passing in an options object of the following format:
@@ -96,10 +96,12 @@ var app = express();
96
96
var bodyParser = require (' body-parser' );
97
97
98
98
var { Validator, ValidationError } = require (' express-json-validator-middleware' );
99
+
99
100
// Initialize a Validator instance first
100
101
var validator = new Validator ({allErrors: true }); // pass in options to the Ajv instance
102
+
101
103
// 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 ;
103
105
104
106
// Define a JSON Schema
105
107
var StreetSchema = {
@@ -167,7 +169,7 @@ validator.ajv.addKeyword('constant', { validate: function (schema, data) {
167
169
: schema === data;
168
170
}, errors: false });
169
171
170
- // free to use validate() here
172
+ // free to validator in middleware now
171
173
```
172
174
173
175
More 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
208
210
foo: {
209
211
type: ' string'
210
212
},
211
- required: [' foo' ] < --
213
+ required: [' foo' ] // <-- correct way
212
214
}
213
215
}
214
216
@@ -218,7 +220,7 @@ In `express-jsonschema`, you could define a required property in two ways. Ajv o
218
220
properties: {
219
221
foo: {
220
222
type: ' string' ,
221
- required: true
223
+ required: true // nono way
222
224
}
223
225
}
224
226
}
0 commit comments