json-schema-migrate
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -99,34 +99,57 @@ 'use strict'; | ||
} | ||
if (dataSchema.id) dataSchema.$id = use('id'); | ||
var $s = dataSchema.$schema; | ||
if ($s) { | ||
dataSchema.$schema = $s == metaSchema4.id || $s == metaSchemaV5.id | ||
? 'http://json-schema.org/draft-06/schema#' | ||
: $s == hyperSchema.id | ||
? 'http://json-schema.org/draft-06/hyper-schema#' | ||
: $s; | ||
var dsCopy = copy(dataSchema); | ||
var key; | ||
for (key in dataSchema) delete dataSchema[key]; | ||
for (var i=0; i<keys.length; i++) { | ||
key = keys[i]; | ||
switch (key) { | ||
case 'id': | ||
dataSchema.$id = dsCopy.id; | ||
break; | ||
case '$schema': | ||
var $s = dsCopy.$schema; | ||
dataSchema.$schema = $s == metaSchema4.id || $s == metaSchemaV5.id | ||
? 'http://json-schema.org/draft-06/schema#' | ||
: $s == hyperSchema.id | ||
? 'http://json-schema.org/draft-06/hyper-schema#' | ||
: $s; | ||
break; | ||
case 'constant': | ||
dataSchema.const = dsCopy.constant; | ||
break; | ||
case 'enum': | ||
if (Array.isArray(dsCopy.enum) | ||
&& dsCopy.enum.length == 1 | ||
&& dsCopy.constant === undefined) { | ||
dataSchema.const = dsCopy.enum[0]; | ||
} else { | ||
dataSchema.enum = dsCopy.enum; | ||
} | ||
break; | ||
case 'exclusiveMaximum': | ||
migrateExclusive('maximum'); | ||
break; | ||
case 'exclusiveMinimum': | ||
migrateExclusive('minimum'); | ||
break; | ||
case 'maximum': | ||
if (dsCopy.exclusiveMaximum !== true) | ||
dataSchema.maximum = dsCopy.maximum; | ||
break; | ||
case 'minimum': | ||
if (dsCopy.exclusiveMinimum !== true) | ||
dataSchema.minimum = dsCopy.minimum; | ||
break; | ||
default: | ||
dataSchema[key] = dsCopy[key]; | ||
} | ||
} | ||
migrateExclusiveM('aximum'); | ||
migrateExclusiveM('inimum'); | ||
if (dataSchema.constant !== undefined) | ||
dataSchema.const = use('constant'); | ||
else if (Array.isArray(dataSchema.enum) && dataSchema.enum.length == 1) | ||
dataSchema.const = use('enum')[0]; | ||
function migrateExclusiveM(limit) { | ||
var key = 'exclusiveM' + limit; | ||
if (dataSchema[key] === true) | ||
dataSchema[key] = use('m' + limit); | ||
else if (dataSchema[key] === false) | ||
delete dataSchema[key]; | ||
else if (dataSchema[key] !== undefined) | ||
function migrateExclusive(limit) { | ||
if (dsCopy[key] === true) | ||
dataSchema[key] = dsCopy[limit]; | ||
else if (dsCopy[key] !== false && dsCopy[key] !== undefined) | ||
console.warn(key + ' is not boolean'); | ||
} | ||
function use(keyword) { | ||
var value = dataSchema[keyword]; | ||
delete dataSchema[keyword]; | ||
return value; | ||
} | ||
} | ||
@@ -133,0 +156,0 @@ }); |
{ | ||
"name": "json-schema-migrate", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Migrate JSON-Schema to draft-06", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
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
21049
568
0