1
1
# Express JSON Validator Middleware
2
2
3
3
> [ Express] ( https://github.com/expressjs/express/ ) middleware for validating
4
- requests against JSON schemas.
4
+ requests against JSON schemas with Ajv .
5
5
6
6
[ ![ npm version] ( https://img.shields.io/npm/v/express-json-validator-middleware.svg )] ( https://www.npmjs.com/package/express-json-validator-middleware )
7
7
[ ![ npm monthly downloads] ( https://img.shields.io/npm/dm/express-json-validator-middleware.svg )] ( https://www.npmjs.com/package/express-json-validator-middleware )
@@ -11,12 +11,11 @@ requests against JSON schemas.
11
11
12
12
## Why validate with JSON schemas?
13
13
14
- - ** Simple** - JSON schemas are a simple and expressive way to describe a data structure.
15
- - ** Standard** - JSON schemas are not specific to JavaScript. In fact, they are used just about everywhere.
16
- - ** Fail-Fast** - Catch errors early in your logic, evading confusing errors later.
17
- - ** Separate Validation** - Keep your routes clean. Validation logic doesn't need to be defined in your route handlers.
18
- - ** Error Messaging** - Ajv provides you with rich error objects that can easily be transformed into human-readable format.
19
- - ** Documentation** - Creating a JSON Schema is another way of documenting your application.
14
+ - ** Expressive** — JSON schemas are an expressive way to describe data structures.
15
+ - ** Standard** — JSON schemas are portable. There are validator implementations in many languages.
16
+ - ** Separate validation** — Avoid the need to handle request validation in your route handlers.
17
+ - ** Error messaging** — Ajv provides rich and descriptive error objects.
18
+ - ** Documentation** — Schemas can help document your application.
20
19
21
20
## Requirements
22
21
@@ -28,6 +27,8 @@ requests against JSON schemas.
28
27
npm install express-json-validator-middleware
29
28
```
30
29
30
+ If you're upgrading from v2 to v3, make sure you read the [ migration notes] ( #upgrading-from-v2-to-v3 ) .
31
+
31
32
## Getting started
32
33
33
34
``` javascript
@@ -277,21 +278,31 @@ validator.ajv;
277
278
Ajv must be configured * before* you call ` Validator.validate() ` to add middleware
278
279
(e.g. if you need to define [ custom keywords] ( https://ajv.js.org/custom.html ) .
279
280
280
- ## Ajv versions
281
+ ## Upgrading from v2 to v3
282
+
283
+ v2.x releases of this library use [ Ajv v6] ( https://www.npmjs.com/package/ajv/v/6.6.2 ) .
284
+ v3.x of this library uses [ Ajv v8] ( https://www.npmjs.com/package/ajv/v/8.11.0 ) .
285
+
286
+ Notable changes between Ajv v6 and v8:
281
287
282
- The major version ` 1.x ` of this module uses ` ajv@5 ` , read their changelog and
283
- migration guide [ here] ( https://github.com/ajv-validator/ajv/releases/tag/5.0.0 ) .
288
+ - All formats have been moved to [ ajv-formats] ( https://www.npmjs.com/package/ajv-formats ) .
289
+ If you're using formats in your schemas, you must install this package to continue
290
+ using them.
291
+ - The structure of validation errors has changed.
292
+ - Support has been dropped for JSON Schema draft-04.
284
293
285
- Major version ` 2.x ` uses ` ajv@6 ` in order to support draft-07 of JSON Schema.
286
- You have to manually configure Ajv to support ** draft-06** schemas
287
- (see https://github.com/ajv-validator/ajv/tree/v6#using-version-6 ).
294
+ For full details, read the Ajv migration guide: [ Changes from Ajv v6.12.6 to v8.0.0] ( https://ajv.js.org/v6-to-v8-migration.html ) .
295
+
296
+ If you have any Ajv plugins as dependencies, update them to their newest versions.
297
+ Older versions of Ajv plugins are less likely to be compatible with Ajv v8.
288
298
289
299
## Tests
290
300
291
301
Tests are written using [ node-tap] ( https://www.npmjs.com/package/tap ) .
292
302
293
303
```
294
304
npm install
305
+
295
306
npm test
296
307
```
297
308
0 commit comments