Releases: ajv-validator/ajv
5.0.4-beta.1
More comprehencive uri-reference
format in {format: "full"}
mode.
5.0.4-beta.0
Rename format uri-ref
to uri-reference
Cross-platform scripts
Update draft-6 meta-schema
5.0.3-beta.0
Support $id from draft-06.
Option schemaId
determining whether $id
, id
or both are used. See Options
Format "regex"
is changed to prohibit \Z
anchor.
Format "uri"
is changed to only allow absolute URIs, relative URIs are supported with "uri-ref"
.
Run draft-06 tests from JSON-Schema-Test-Suite in addition to draft-04 tests.
5.0.2-beta.0
Support custom formats for numbers (#291)
Option ownProperties supports all keywords (#197). See Options.
Improve support of custom keywords with $data option.
Also see 5.0.1-beta.0 about the migration from 4.x.x
5.0.1-beta.3
5.0.1-beta.2
Option serialize
to replace json-stable-stringify with another function to serialise schemas.
Support deprecated patternGroups
without draft-06 meta-schema.
Log warning instead of throwing exception when option meta: false
is used without validateSchema: false
.
5.0.1-beta.1
Same as 4.11.0
Also see 5.0.1-beta.0
4.11.0
Custom keywords enhancements:
- allow hyphens in keyword names.
- option
modifying: true
in keyword definition to support keywords that change data (#392). - option
valid: true/false
in keyword definition to pre-define validation result - it allows to simplify generated code in cases when keywords are used only for side-effects (#393).
5.0.1-beta.0
If you are migrating from 4.x.x also see 5.0.0-beta.1 and Migration section below
Changes
Keyword changes
Support for all keywords included in draft 6 (it is not published yet and can change).
-
const (previously available as
constant
). To simplify migration you can define an aliasconstant
as a custom macro keyword:ajv.addKeyword('constant', { macro: x => ({ const: x }) });
-
contains. It is re-implemented as a standard keyword, if none of the items is valid, errors for all items will be reported now.
-
NEW propertyNames keyword added (previously it was a part of ajv-keywords package). It allows to validate all property names rather than values.
-
exclusiveMaximum/Minimum in draft 6 must be numbers, Ajv supports boolean form too for backwards compatibility.
Moved/deprecated:
- switch, patternRequired and formatMinimum/Maximum moved to ajv-keywords (^2.0.0-beta).
- patternGroups is deprecated, it can be still used with option
patternRequired
.
Draft 6 support
- Support for boolean schemas: wherever a schema is required,
true
/false
can be used in order to always pass/fail validation. - Meta-schema - by default Ajv adds backwards compatible draft 6 meta-schema. Its URI used in Ajv is
http://json-schema.org/draft-06/schema#
(it can change when draft 6 is published).
If your $schema keyword points to draft 4 or v5 meta-schema you need to add it manually:
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
// or
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-v5.json'));
Options
v5
is no longer used, for $data reference support use option$data
beautify: true
is no longer supported.processCode: function() {}
can be used to beautify/transpile generated code. See Options
Asynchronous validation
- Auto-detection of async mode and
transpile
option support require ajv-async package. - Default async mode is
"co*"
(co-wrapped generator functions). - If you need to transpile code without ajv-async package, you can pass transpilation function in
processCode
option. See Options. - In case of validation success, returned Promise resolves with validated data to simplify chaining (previously it resolved with
true
).
Related packages
Compatible versions are:
- ajv-keywords:
^2.0.0-beta
- ajv-merge-patch:
^3.0.0-beta
- ajv-i18n:
^2.0.0-beta
Migration from 4.x.x
If you use draft-04 schemas
var ajv = new Ajv({
meta: false, // optional, to prevent adding draft-06 meta-schema
extendRefs: true, // optional, current default is to 'fail', spec behaviour is to 'ignore'
unknownFormats: 'ignore', // optional, current default is true (fail)
// ...
});
var metaSchema = require('ajv/lib/refs/json-schema-draft-04.json');
ajv.addMetaSchema(metaSchema);
ajv._opts.defaultMeta = metaSchema.id;
// optional, using unversioned URI is out of spec, see https://github.com/json-schema-org/json-schema-spec/issues/216
ajv._refs['http://json-schema.org/schema'] = 'http://json-schema.org/draft-04/schema';
// Optionally you can also disable keywords defined in draft-06
ajv.removeKeyword('propertyNames');
ajv.removeKeyword('contains');
ajv.removeKeyword('const');
If you use schemas requiring v5 mode of Ajv
var ajv = new Ajv({
$data: true,
patternGroups: true,
meta: false, // optional, to prevent adding draft-06 meta-schema
extendRefs: true, // optional, current default is to 'fail', spec behaviour is to 'ignore'
unknownFormats: 'ignore', // optional, current default is true (fail)
// ...
});
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
ajv._refs['http://json-schema.org/schema'] = 'http://json-schema.org/draft-04/schema'; // optional, using unversioned URI is out of spec
var metaSchema = require('ajv/lib/refs/json-schema-v5.json');
ajv.addMetaSchema(metaSchema);
ajv._opts.defaultMeta = metaSchema.id;
// optional - to avoid changing the schemas
ajv.addKeyword('constant', { macro: x => ({ const: x }) }); // this keyword is renamed to const in draft-06
// you need to use version "^2.0.0-beta" of ajv-keywords
require('ajv-keywords')(ajv, ['switch', 'patternRequired', 'formatMinimum', 'formatMaximum']);
// Optionally you can also disable propertyNames keyword defined in draft-06
ajv.removeKeyword('propertyNames');