项目作者: ajv-validator

项目描述 :
Migrate JSON-Schema draft-04 to draft-07, draft-2019-09 or draft-2020-12
高级语言: TypeScript
项目地址: git://github.com/ajv-validator/json-schema-migrate.git
创建时间: 2017-03-24T23:44:33Z
项目社区:https://github.com/ajv-validator/json-schema-migrate

开源协议:MIT License

下载


json-schema-migrate

Migrate JSON-Schema from draft-04 to draft-07, draft-2019-09 or draft-2020-12

build
npm
coverage

Install

  1. npm install json-schema-migrate

Usage

  1. const migrate = require("json-schema-migrate")
  2. const schema = {
  3. id: "my-schema",
  4. minimum: 1,
  5. exclusiveMinimum: true,
  6. }
  7. migrate.draft7(schema)
  8. // or migrate.draft2019(schema)
  9. // or migrate.draft2020(schema)
  10. console.log(schema)
  11. // {
  12. // $id: 'my-schema',
  13. // exclusiveMinimum: 1
  14. // }

You can access Ajv instance that is used to migrate schema using migrate.getAjv function:

  1. console.log(migrate.getAjv().errorsText(errors))

Changes in schemas after migration

  • id is replaced with $id
  • $schema value becomes draft-07, draft-2019-09 or draft-2020-12 meta-schema
  • draft-04 boolean form of exclusiveMaximum/Minimum is replaced with the current number form
  • enum with a single allowed value is replaced with const
  • Non-standard constant is replaced with const
  • empty schema is replaced with true
  • schema {"not":{}} is replaced with false
  • draft2019 function additionally replaces:
    • definitions with $defs
    • dependencies with dependentRequired and dependentSchemas
    • "id": "#foo" with "$anchor": "foo"
    • "id": "schema#foo" with "$id": "schema", "$anchor": "foo"
  • draft2020 function additionally replaces array form of items with prefixItems (and additionalItems with items)

License

MIT