Skip to content

AJV JSON Schemas Draft 06 Support Update #178

Open
@sundeepnarang

Description

@sundeepnarang

AJV@5 or above cannot add XMLSchema.jsonschema

Requires migration as per AJV (https://github.com/epoberezkin/ajv/releases/tag/5.0.0)

## Migrate your schemas

It is a recommended approach.

Required changes

  • replace id with $id
  • update $schema
  • replace boolean form of exclusiveMaximum/Minimum with numeric form
  • replace Ajv v5 constant with const

Optional changes

  • replace enum with a single allowed value with const
  • replace empty schemas with true
  • replace schemas {"not":{}} with false
  • You can use "migrate" command of ajv-cli to make these changes to your schemas.

You can use "migrate" command of ajv-cli to make these changes to your schemas.

Either we can update docs to keep using Draft04 of JSON schema with following info :

If you need to continue using 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');

Or we can update jsonschemas using "migrate" command of ajv-cli ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions