json-schema-migrate
Advanced tools
Comparing version 0.2.0 to 1.0.0-beta.0
{ | ||
"name": "json-schema-migrate", | ||
"version": "0.2.0", | ||
"version": "1.0.0-beta.0", | ||
"description": "Migrate JSON-Schema to draft-06", | ||
"main": "lib/index.js", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"eslint": "eslint lib spec", | ||
"test-spec": "mocha spec/*.spec.js -R spec", | ||
"test-debug": "mocha spec/*.spec.js --debug-brk -R spec", | ||
"test": "nyc npm run test-spec" | ||
"build": "rm -rf dist && tsc", | ||
"eslint": "eslint src spec", | ||
"prettier:write": "prettier --write \"./**/*.{md,json,yaml,js,ts}\"", | ||
"prettier:check": "prettier --list-different \"./**/*.{md,json,yaml,js,ts}\"", | ||
"test-spec": "jest \"spec/*.ts\"", | ||
"test-cov": "jest \"spec/*.ts\" --coverage", | ||
"test": "npm run build && npm run eslint && npm run test-cov" | ||
}, | ||
@@ -28,21 +31,29 @@ "repository": { | ||
"dependencies": { | ||
"ajv": "^5.0.0" | ||
"ajv": "^7.0.0-beta.9" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^2.12.0", | ||
"eslint": "^3.18.0", | ||
"mocha": "^3.2.0", | ||
"nyc": "^10.1.2", | ||
"pre-commit": "^1.2.2" | ||
"@ajv-validator/config": "^0.3.0", | ||
"@types/jest": "^26.0.16", | ||
"@types/node": "^14.11.10", | ||
"@typescript-eslint/eslint-plugin": "^4.4.1", | ||
"@typescript-eslint/parser": "^4.4.1", | ||
"eslint": "^7.2.0", | ||
"eslint-config-prettier": "^6.13.0", | ||
"glob": "^7.1.3", | ||
"husky": "^4.3.0", | ||
"jest": "^26.5.3", | ||
"lint-staged": "^10.5.2", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.4.4", | ||
"typescript": "^4.1.2" | ||
}, | ||
"nyc": { | ||
"exclude": [ | ||
"**/spec/**", | ||
"node_modules" | ||
], | ||
"reporter": [ | ||
"lcov", | ||
"text-summary" | ||
] | ||
"prettier": "@ajv-validator/config/prettierrc.json", | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged && npm test" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{md,json,yaml,js,ts}": "prettier --write" | ||
} | ||
} |
# json-schema-migrate | ||
Migrate JSON-Schema to draft-06 | ||
Migrate JSON-Schema from draft-04 to draft-07 and draft-2019-09 | ||
[![Build Status](https://travis-ci.org/epoberezkin/json-schema-migrate.svg?branch=master)](https://travis-ci.org/epoberezkin/json-schema-migrate) | ||
[![npm version](https://badge.fury.io/js/json-schema-migrate.svg)](http://badge.fury.io/js/json-schema-migrate) | ||
[![Coverage Status](https://coveralls.io/repos/github/epoberezkin/json-schema-migrate/badge.svg?branch=master)](https://coveralls.io/github/epoberezkin/json-schema-migrate?branch=master) | ||
[![build](https://github.com/ajv-validator/json-schema-migrate/workflows/build/badge.svg)](https://github.com/ajv-validator/json-schema-migrate/actions?query=workflow%3Abuild) | ||
[![npm](https://img.shields.io/npm/v/json-schema-migrate)](https://www.npmjs.com/package/json-schema-migrate) | ||
[![Coverage Status](https://coveralls.io/repos/github/ajv-validator/json-schema-migrate/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/json-schema-migrate?branch=master) | ||
## Install | ||
## Purpose | ||
``` | ||
npm install json-schema-migrate@beta | ||
``` | ||
This package allows to migrate JSON-schemas to draft-06 specification. | ||
or to install v0.2 (to migrate to draft-06) | ||
It supports: | ||
- draft-04 schemas | ||
- draft-04 hyper-schemas | ||
- [Ajv](https://github.com/epoberezkin/ajv) v5 schemas (special extended mode in Ajv 4.x.x, deprecated from version 5.0.0). | ||
## Install | ||
``` | ||
@@ -26,15 +21,15 @@ npm install json-schema-migrate | ||
## Usage | ||
```javascript | ||
var migrate = require('json-schema-migrate'); | ||
var schema = { | ||
id: 'my-schema', | ||
const migrate = require("json-schema-migrate") | ||
const schema = { | ||
id: "my-schema", | ||
minimum: 1, | ||
exclusiveMinimum: true | ||
}; | ||
migrate.draft6(schema /*, options */); | ||
exclusiveMinimum: true, | ||
} | ||
const {valid, errors} = migrate.draft7(schema) | ||
// or migrate.draft2019(schema) | ||
console.log(schema); | ||
console.log(schema) | ||
// { | ||
@@ -46,22 +41,25 @@ // $id: 'my-schema', | ||
You can access Ajv instance that was used to migrate schema using `migrate.getAjv` function: | ||
```javascript | ||
console.log(migrate.getAjv().errorsText(errors)) | ||
``` | ||
## Changes in schemas after migration | ||
- `id` is replaced with `$id` | ||
- `$schema` value becomes draft-06 meta-schema (or draft-06 hyper-schema) | ||
- `$schema` value becomes draft-07 or draft-2019-09 meta-schema | ||
- boolean form of `exclusiveMaximum/Minimum` is replaced with numeric form | ||
- `enum` with a single allowed value is replaced with `const` | ||
- Ajv v5 `constant` 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"` | ||
## Options | ||
- _v5_ - use v5 by default (if `$schema` keyword is absent) | ||
- _validateSchema_ - pass `false` to skip schema validation | ||
## License | ||
[MIT](https://github.com/epoberezkin/json-schema-migrate/blob/master/LICENSE) |
{ | ||
"id": "my-schema", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"definitions": { | ||
"str": { | ||
"id": "#str", | ||
"type": "string" | ||
}, | ||
"num": { | ||
"id": "another-schema#num", | ||
"type": "string" | ||
} | ||
}, | ||
"properties": { | ||
@@ -17,7 +27,19 @@ "exclusiveLimits": { | ||
}, | ||
"singleValue": { "enum": ["foo"] }, | ||
"multipleValues": { "enum": ["foo", "bar"] }, | ||
"singleValue": {"enum": ["foo"]}, | ||
"singleValueConstant": {"constant": "foo"}, | ||
"multipleValues": {"enum": ["foo", "bar"]}, | ||
"alwaysValid": {}, | ||
"alwaysInvalid": {"not": {}} | ||
"alsoAlwaysValid": {"not": {"not": {}}}, | ||
"alwaysInvalid": {"not": {}}, | ||
"alsoAlwaysInvalid": {"not": {"not": {"not": {}}}} | ||
}, | ||
"dependencies": { | ||
"foo": ["bar"], | ||
"bar": { | ||
"required": ["baz"], | ||
"properties": { | ||
"baz": {"type": "string"} | ||
} | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
27797
18
0
14
539
64
1
+ Addedajv@7.2.4(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addeduri-js@4.4.1(transitive)
- Removedajv@5.5.2(transitive)
- Removedco@4.6.0(transitive)
- Removedfast-deep-equal@1.1.0(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedjson-schema-traverse@0.3.1(transitive)
Updatedajv@^7.0.0-beta.9