Skip to content

Releases: ajv-validator/ajv

5.0.3-beta.0

01 Mar 10:08
Compare
Choose a tag to compare
5.0.3-beta.0 Pre-release
Pre-release

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

12 Feb 19:30
Compare
Choose a tag to compare
5.0.2-beta.0 Pre-release
Pre-release

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

04 Feb 23:04
Compare
Choose a tag to compare
5.0.1-beta.3 Pre-release
Pre-release

Improve error handling (#380, #394)
Improve webpack support (#403)

5.0.1-beta.2

23 Jan 21:22
Compare
Choose a tag to compare
5.0.1-beta.2 Pre-release
Pre-release

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

21 Jan 00:19
Compare
Choose a tag to compare
5.0.1-beta.1 Pre-release
Pre-release

Same as 4.11.0
Also see 5.0.1-beta.0

4.11.0

21 Jan 00:15
Compare
Choose a tag to compare

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

31 Dec 00:56
Compare
Choose a tag to compare
5.0.1-beta.0 Pre-release
Pre-release

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 alias constant 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:

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:

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');

4.10.0

11 Dec 13:04
Compare
Choose a tag to compare

Method getKeyword to return keyword definition.
Method removeKeyword to remove custom or pre-defined keyword. See API.
Fix for webpack warnings for optional dependencies (#117, #325).

5.0.0-beta.1

30 Nov 21:09
Compare
Choose a tag to compare
5.0.0-beta.1 Pre-release
Pre-release

Ajv.MissingRefError class is used to throw missing $ref exception
Typings are updated - typescript 2.0 is required now

Also see 5.0.0-beta.0

4.9.0

14 Nov 21:06
Compare
Choose a tag to compare

Support undefined, RegExp and Date instances in uniqueItems keyword (#342).