Socket
Socket
Sign inDemoInstall

json-schema-migrate

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-migrate - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

spec/fixtures/expected-schema-from-draft-04-to-2020.json

2

.eslintrc.js

@@ -16,3 +16,3 @@ const jsConfig = require("@ajv-validator/config/.eslintrc_js")

...tsConfig.rules,
complexity: ["error", 35],
complexity: ["error", 15],
"@typescript-eslint/no-explicit-any": "off",

@@ -19,0 +19,0 @@ "@typescript-eslint/no-unnecessary-condition": "warn",

import Ajv, { AnySchemaObject } from "ajv/dist/2019";
export declare const draft7: (schema: AnySchemaObject) => void;
export declare const draft2019: (schema: AnySchemaObject) => void;
export declare const draft2020: (schema: AnySchemaObject) => void;
export declare function getAjv(): Ajv;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAjv = exports.draft2019 = exports.draft7 = void 0;
exports.getAjv = exports.draft2020 = exports.draft2019 = exports.draft7 = void 0;
const _2019_1 = require("ajv/dist/2019");
exports.draft7 = getMigrate("draft7");
exports.draft2019 = getMigrate("draft2019");
exports.draft2020 = getMigrate("draft2020");
function getMigrateSchema(version) {

@@ -37,3 +38,4 @@ return {

modifying: true,
metaSchema: { enum: ["draft7", "draft2019"] },
metaSchema: { enum: ["draft7", "draft2019", "draft2020"] },
// eslint-disable-next-line complexity
validate(version, dataSchema, _parentSchema, dataCxt) {

@@ -60,3 +62,3 @@ if (typeof dataSchema != "object")

}
if (version === "draft2019" && id.includes("#")) {
if ((version === "draft2019" || version === "draft2020") && id.includes("#")) {
const [$id, $anchor, ...rest] = id.split("#");

@@ -127,2 +129,18 @@ if (rest.length > 0) {

}
case "items":
if (version === "draft2020" && Array.isArray(dsCopy.items)) {
dataSchema.prefixItems = dsCopy.items;
if (dsCopy.additionalItems !== undefined) {
dataSchema.items = dsCopy.additionalItems;
}
}
else {
dataSchema.items = dsCopy.items;
}
break;
case "additionalItems":
if (version !== "draft2020") {
dataSchema.additionalItems = dsCopy.additionalItems;
}
break;
default:

@@ -129,0 +147,0 @@ dataSchema[key] = dsCopy[key];

{
"name": "json-schema-migrate",
"version": "1.1.0",
"version": "2.0.0",
"description": "Migrate JSON-Schema to draft-06",

@@ -31,3 +31,3 @@ "main": "dist/index.js",

"dependencies": {
"ajv": "^7.0.0-beta.9"
"ajv": "^8.0.0"
},

@@ -34,0 +34,0 @@ "devDependencies": {

# json-schema-migrate
Migrate JSON-Schema from draft-04 to draft-07 or draft-2019-09
Migrate JSON-Schema from draft-04 to draft-07, draft-2019-09 or draft-2020-12

@@ -26,2 +26,3 @@ [![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)

// or migrate.draft2019(schema)
// or migrate.draft2020(schema)

@@ -44,3 +45,3 @@ console.log(schema)

- `id` is replaced with `$id`
- `$schema` value becomes draft-07 or draft-2019-09 meta-schema
- `$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

@@ -56,2 +57,3 @@ - `enum` with a single allowed value is replaced with `const`

- `"id": "schema#foo"` with `"$id": "schema", "$anchor": "foo"`
- `draft2020` function additionally replaces array form of `items` with `prefixItems` (and `additionalItems` with `items`)

@@ -58,0 +60,0 @@ ## License

@@ -29,3 +29,14 @@ {

"alwaysInvalid": false,
"alsoAlwaysInvalid": false
"alsoAlwaysInvalid": false,
"array": {
"items": {"type": "number"}
},
"tuple": {
"items": [{"type": "number"}, {"type": "string"}],
"additionalItems": false
},
"tupleExtras": {
"items": [{"type": "number"}, {"type": "string"}],
"additionalItems": {"type": "boolean"}
}
},

@@ -32,0 +43,0 @@ "dependencies": {

@@ -30,3 +30,14 @@ {

"alwaysInvalid": false,
"alsoAlwaysInvalid": false
"alsoAlwaysInvalid": false,
"array": {
"items": {"type": "number"}
},
"tuple": {
"items": [{"type": "number"}, {"type": "string"}],
"additionalItems": false
},
"tupleExtras": {
"items": [{"type": "number"}, {"type": "string"}],
"additionalItems": {"type": "boolean"}
}
},

@@ -33,0 +44,0 @@ "dependentRequired": {

@@ -33,3 +33,14 @@ {

"alwaysInvalid": {"not": {}},
"alsoAlwaysInvalid": {"not": {"not": {"not": {}}}}
"alsoAlwaysInvalid": {"not": {"not": {"not": {}}}},
"array": {
"items": {"type": "number"}
},
"tuple": {
"items": [{"type": "number"}, {"type": "string"}],
"additionalItems": false
},
"tupleExtras": {
"items": [{"type": "number"}, {"type": "string"}],
"additionalItems": {"type": "boolean"}
}
},

@@ -36,0 +47,0 @@ "dependencies": {

import assert = require("assert")
import {draft7, draft2019, getAjv} from ".."
import {draft7, draft2019, draft2020, getAjv} from ".."
import schemaDraft4 = require("./fixtures/schema-draft-04.json")
import expectedSchemaDraft7 = require("./fixtures/expected-schema-from-draft-04-to-07.json")
import expectedSchemaDraft2019 = require("./fixtures/expected-schema-from-draft-04-to-2019.json")
import expectedSchemaDraft2020 = require("./fixtures/expected-schema-from-draft-04-to-2020.json")
import Ajv, {AnySchemaObject} from "ajv/dist/core"

@@ -28,2 +29,8 @@

it("should migrate from draft-04 schema to draft-2020-12 schema", () => {
const schema = clone(schemaDraft4)
draft2020(schema)
assert.deepStrictEqual(schema, expectedSchemaDraft2020)
})
describe("invalid schemas", () => {

@@ -30,0 +37,0 @@ it("should throw if id is not a string", () => {

import Ajv, {SchemaObject, AnySchemaObject, AnySchema} from "ajv/dist/2019"
import type {DataValidationCxt, ValidateFunction} from "ajv/dist/types"
type SchemaVersion = "draft7" | "draft2019"
type SchemaVersion = "draft7" | "draft2019" | "draft2020"
export const draft7 = getMigrate("draft7")
export const draft2019 = getMigrate("draft2019")
export const draft2020 = getMigrate("draft2020")

@@ -44,3 +45,4 @@ function getMigrateSchema(version: SchemaVersion): SchemaObject {

modifying: true,
metaSchema: {enum: ["draft7", "draft2019"]},
metaSchema: {enum: ["draft7", "draft2019", "draft2020"]},
// eslint-disable-next-line complexity
validate(

@@ -70,3 +72,3 @@ version: SchemaVersion,

}
if (version === "draft2019" && id.includes("#")) {
if ((version === "draft2019" || version === "draft2020") && id.includes("#")) {
const [$id, $anchor, ...rest] = id.split("#")

@@ -132,2 +134,17 @@ if (rest.length > 0) {

}
case "items":
if (version === "draft2020" && Array.isArray(dsCopy.items)) {
dataSchema.prefixItems = dsCopy.items
if (dsCopy.additionalItems !== undefined) {
dataSchema.items = dsCopy.additionalItems
}
} else {
dataSchema.items = dsCopy.items
}
break
case "additionalItems":
if (version !== "draft2020") {
dataSchema.additionalItems = dsCopy.additionalItems
}
break
default:

@@ -134,0 +151,0 @@ dataSchema[key] = dsCopy[key]

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc