11# Express JSON Validator Middleware
22
33> [ Express] ( https://github.com/expressjs/express/ ) middleware for validating
4- requests against JSON schemas.
4+ requests against JSON schemas with Ajv .
55
66[ ![ npm version] ( https://img.shields.io/npm/v/express-json-validator-middleware.svg )] ( https://www.npmjs.com/package/express-json-validator-middleware )
77[ ![ 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.
1111
1212## Why validate with JSON schemas?
1313
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.
2019
2120## Requirements
2221
@@ -28,6 +27,8 @@ requests against JSON schemas.
2827npm install express-json-validator-middleware
2928```
3029
30+ If you're upgrading from v2 to v3, make sure you read the [ migration notes] ( #upgrading-from-v2-to-v3 ) .
31+
3132## Getting started
3233
3334``` javascript
@@ -277,21 +278,31 @@ validator.ajv;
277278Ajv must be configured * before* you call ` Validator.validate() ` to add middleware
278279(e.g. if you need to define [ custom keywords] ( https://ajv.js.org/custom.html ) .
279280
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:
281287
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.
284293
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.
288298
289299## Tests
290300
291301Tests are written using [ node-tap] ( https://www.npmjs.com/package/tap ) .
292302
293303```
294304npm install
305+
295306npm test
296307```
297308
0 commit comments