Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-schema-diff

Package Overview
Dependencies
Maintainers
4
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-diff - npm Package Compare versions

Comparing version 0.16.0 to 0.17.0

dist/json-schema-diff/diff-schemas/set-factories/create-number-set.js

9

CHANGELOG.md

@@ -0,1 +1,10 @@

## [0.17.0](https://bitbucket.org/atlassian/json-schema-diff/compare/0.16.2...0.17.0) (2021-06-28)
### Features
* add support for minimum, exclusiveMinumum, maximum and exclusiveMaximum ([796c36a](https://bitbucket.org/atlassian/json-schema-diff/commit/796c36a42ba9499cf9a6e36b1a06ab4b42f51670))
* consider integer as a subtype of number ([3f6d42b](https://bitbucket.org/atlassian/json-schema-diff/commit/3f6d42b0553dea8f4b5a5ec0969d3673de8ae0f5))
* dropping support for node 8 ([266b3ec](https://bitbucket.org/atlassian/json-schema-diff/commit/266b3ec65a338c4c05d084df96a42da84b676099))
<a name="0.16.0"></a>

@@ -2,0 +11,0 @@ # [0.16.0](https://bitbucket.org/atlassian/json-schema-diff/compare/0.15.0...0.16.0) (2020-08-14)

1

dist/json-schema-diff-factory.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonSchemaDiffFactory = void 0;
const json_schema_diff_1 = require("./json-schema-diff");

@@ -4,0 +5,0 @@ const file_reader_1 = require("./json-schema-diff/file-reader");

@@ -12,2 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonSchemaDiff = void 0;
const verror_1 = require("verror");

@@ -14,0 +15,0 @@ const diff_schemas_1 = require("./json-schema-diff/diff-schemas");

4

dist/json-schema-diff/common/logger.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.logSetDebug = (setName, set) => {
exports.logSetDebug = void 0;
const logSetDebug = (setName, set) => {
if (process.env.JSON_SCHEMA_DIFF_ENABLE_DEBUG === 'true') {

@@ -9,1 +10,2 @@ console.log(`\n${setName}`);

};
exports.logSetDebug = logSetDebug;

@@ -12,2 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.diffSchemas = void 0;
const logger_1 = require("./common/logger");

@@ -17,3 +18,3 @@ const dereference_schema_1 = require("./diff-schemas/dereference-schema");

const validate_schemas_1 = require("./diff-schemas/validate-schemas");
exports.diffSchemas = (sourceSchema, destinationSchema) => __awaiter(void 0, void 0, void 0, function* () {
const diffSchemas = (sourceSchema, destinationSchema) => __awaiter(void 0, void 0, void 0, function* () {
const [dereferencedSourceSchema, dereferencedDestinationSchema] = yield Promise.all([

@@ -42,1 +43,2 @@ dereference_schema_1.dereferenceSchema(sourceSchema), dereference_schema_1.dereferenceSchema(destinationSchema)

});
exports.diffSchemas = diffSchemas;

@@ -12,4 +12,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.dereferenceSchema = void 0;
const RefParser = require("json-schema-ref-parser");
exports.dereferenceSchema = (schema) => __awaiter(void 0, void 0, void 0, function* () {
const dereferenceSchema = (schema) => __awaiter(void 0, void 0, void 0, function* () {
const refParser = new RefParser();

@@ -20,1 +21,2 @@ return typeof schema === 'boolean'

});
exports.dereferenceSchema = dereferenceSchema;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseAsJsonSet = void 0;
const create_json_set_1 = require("./set-factories/create-json-set");

@@ -26,6 +27,10 @@ const keyword_defaults_1 = require("./set/keyword-defaults");

additionalProperties: parseSchemaOrUndefinedAsJsonSet(schema.additionalProperties),
exclusiveMaximum: parseNumericKeyword(schema.exclusiveMaximum, keyword_defaults_1.defaultMaximum),
exclusiveMinimum: parseNumericKeyword(schema.exclusiveMinimum, keyword_defaults_1.defaultMinimum),
items: parseSchemaOrUndefinedAsJsonSet(schema.items),
maximum: parseNumericKeyword(schema.maximum, keyword_defaults_1.defaultMaximum),
maxItems: parseNumericKeyword(schema.maxItems, keyword_defaults_1.defaultMaxItems),
maxLength: parseNumericKeyword(schema.maxLength, keyword_defaults_1.defaultMaxLength),
maxProperties: parseNumericKeyword(schema.maxProperties, keyword_defaults_1.defaultMaxProperties),
minimum: parseNumericKeyword(schema.minimum, keyword_defaults_1.defaultMinimum),
minItems: parseNumericKeyword(schema.minItems, keyword_defaults_1.defaultMinItems),

@@ -87,4 +92,5 @@ minLength: parseNumericKeyword(schema.minLength, keyword_defaults_1.defaultMinLength),

};
exports.parseAsJsonSet = (schema) => {
const parseAsJsonSet = (schema) => {
return parseSchemaOrUndefinedAsJsonSet(schema);
};
exports.parseAsJsonSet = parseAsJsonSet;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createArraySet = void 0;
const keyword_defaults_1 = require("../set/keyword-defaults");

@@ -19,5 +20,6 @@ const array_subset_1 = require("../set/subset/array-subset");

};
exports.createArraySet = (arraySetParsedKeywords) => {
const createArraySet = (arraySetParsedKeywords) => {
const arraySubset = createArraySubset(arraySetParsedKeywords);
return type_set_1.createTypeSetFromSubsets('array', [arraySubset]);
};
exports.createArraySet = createArraySet;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createEmptyJsonSet = exports.createAllJsonSet = exports.createJsonSetFromParsedSchemaKeywords = void 0;
const json_set_1 = require("../set/json-set");
const create_array_set_1 = require("./create-array-set");
const create_number_set_1 = require("./create-number-set");
const create_object_set_1 = require("./create-object-set");
const create_string_set_1 = require("./create-string-set");
const create_type_set_1 = require("./create-type-set");
exports.createJsonSetFromParsedSchemaKeywords = (parsedSchemaKeywords) => json_set_1.createJsonSetFromConfig({
const createJsonSetFromParsedSchemaKeywords = (parsedSchemaKeywords) => json_set_1.createJsonSetFromConfig({
array: create_array_set_1.createArraySet(parsedSchemaKeywords),
boolean: create_type_set_1.createTypeSet('boolean', parsedSchemaKeywords.type),
integer: create_type_set_1.createTypeSet('integer', parsedSchemaKeywords.type),
null: create_type_set_1.createTypeSet('null', parsedSchemaKeywords.type),
number: create_type_set_1.createTypeSet('number', parsedSchemaKeywords.type),
number: create_number_set_1.createNumberSet(parsedSchemaKeywords),
object: create_object_set_1.createObjectSet(parsedSchemaKeywords),
string: create_string_set_1.createStringSet(parsedSchemaKeywords)
});
exports.createAllJsonSet = () => json_set_1.allJsonSet;
exports.createEmptyJsonSet = () => json_set_1.emptyJsonSet;
exports.createJsonSetFromParsedSchemaKeywords = createJsonSetFromParsedSchemaKeywords;
const createAllJsonSet = () => json_set_1.allJsonSet;
exports.createAllJsonSet = createAllJsonSet;
const createEmptyJsonSet = () => json_set_1.emptyJsonSet;
exports.createEmptyJsonSet = createEmptyJsonSet;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createObjectSet = void 0;
const _ = require("lodash");

@@ -27,5 +28,6 @@ const keyword_defaults_1 = require("../set/keyword-defaults");

};
exports.createObjectSet = (objectSetParsedKeywords) => {
const createObjectSet = (objectSetParsedKeywords) => {
const objectSubset = createObjectSubset(objectSetParsedKeywords);
return type_set_1.createTypeSetFromSubsets('object', [objectSubset]);
};
exports.createObjectSet = createObjectSet;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStringSet = void 0;
const keyword_defaults_1 = require("../set/keyword-defaults");

@@ -18,5 +19,6 @@ const string_subset_1 = require("../set/subset/string-subset");

};
exports.createStringSet = (stringSetParsedKeywords) => {
const createStringSet = (stringSetParsedKeywords) => {
const stringSubset = createStringSubset(stringSetParsedKeywords);
return type_set_1.createTypeSetFromSubsets('string', [stringSubset]);
};
exports.createStringSet = createStringSet;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTypeSet = void 0;
const subset_1 = require("../set/subset/subset");

@@ -7,2 +8,3 @@ const type_set_1 = require("../set/type-set");

const createTypeSubset = (setType, types) => is_type_supported_1.isTypeSupported(types, setType) ? new subset_1.AllSubset(setType) : new subset_1.EmptySubset(setType);
exports.createTypeSet = (setType, types) => type_set_1.createTypeSetFromSubsets(setType, [createTypeSubset(setType, types)]);
const createTypeSet = (setType, types) => type_set_1.createTypeSetFromSubsets(setType, [createTypeSubset(setType, types)]);
exports.createTypeSet = createTypeSet;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTypeSupported = (parsedTypeKeyword, type) => parsedTypeKeyword.indexOf(type) >= 0;
exports.isTypeSupported = void 0;
const isTypeSupported = (parsedTypeKeyword, type) => parsedTypeKeyword.indexOf(type) >= 0;
exports.isTypeSupported = isTypeSupported;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createJsonSetFromConfig = exports.emptyJsonSet = exports.allJsonSet = void 0;
const json_set_config_1 = require("./json-set/json-set-config");

@@ -94,3 +95,3 @@ const json_set_config_to_core_representation_schema_1 = require("./json-set/json-set-config-to-core-representation-schema");

exports.emptyJsonSet = new EmptyJsonSet();
exports.createJsonSetFromConfig = (config) => {
const createJsonSetFromConfig = (config) => {
if (areAllSubsetsInConfigOfType(config, 'empty')) {

@@ -104,1 +105,2 @@ return exports.emptyJsonSet;

};
exports.createJsonSetFromConfig = createJsonSetFromConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonSetConfigToCoreRepresentationSchema = void 0;
const set_1 = require("../set");

@@ -33,3 +34,3 @@ const createEmptyCoreSchemaMetaSchema = () => ({ type: [] });

: createEmptyCoreSchemaMetaSchema();
exports.jsonSetConfigToCoreRepresentationSchema = (config) => {
const jsonSetConfigToCoreRepresentationSchema = (config) => {
const typeSetSchemas = Object

@@ -55,1 +56,2 @@ .keys(config)

};
exports.jsonSetConfigToCoreRepresentationSchema = jsonSetConfigToCoreRepresentationSchema;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.complementJsonSetConfig = exports.unionJsonSetConfigs = exports.intersectJsonSetConfigs = void 0;
const mapJsonSetConfigs = (a, b, callbackFn) => ({
array: callbackFn(a.array, b.array),
boolean: callbackFn(a.boolean, b.boolean),
integer: callbackFn(a.integer, b.integer),
null: callbackFn(a.null, b.null),

@@ -12,8 +12,9 @@ number: callbackFn(a.number, b.number),

});
exports.intersectJsonSetConfigs = (configA, configB) => mapJsonSetConfigs(configA, configB, (typeSet1, typeSet2) => typeSet1.intersect(typeSet2));
exports.unionJsonSetConfigs = (configA, configB) => mapJsonSetConfigs(configA, configB, (typeSet1, typeSet2) => typeSet1.union(typeSet2));
exports.complementJsonSetConfig = (config) => ({
const intersectJsonSetConfigs = (configA, configB) => mapJsonSetConfigs(configA, configB, (typeSet1, typeSet2) => typeSet1.intersect(typeSet2));
exports.intersectJsonSetConfigs = intersectJsonSetConfigs;
const unionJsonSetConfigs = (configA, configB) => mapJsonSetConfigs(configA, configB, (typeSet1, typeSet2) => typeSet1.union(typeSet2));
exports.unionJsonSetConfigs = unionJsonSetConfigs;
const complementJsonSetConfig = (config) => ({
array: config.array.complement(),
boolean: config.boolean.complement(),
integer: config.integer.complement(),
null: config.null.complement(),

@@ -24,1 +25,2 @@ number: config.number.complement(),

});
exports.complementJsonSetConfig = complementJsonSetConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultTypes = exports.defaultMaximum = exports.defaultMinimum = exports.defaultMinLength = exports.defaultMaxLength = exports.defaultRequired = exports.defaultMinProperties = exports.defaultMinItems = exports.defaultMaxProperties = exports.defaultMaxItems = exports.defaultProperties = void 0;
exports.defaultProperties = {};
exports.defaultMaxItems = Infinity;
exports.defaultMaxProperties = Infinity;
exports.defaultMaxItems = Number.POSITIVE_INFINITY;
exports.defaultMaxProperties = Number.POSITIVE_INFINITY;
exports.defaultMinItems = 0;
exports.defaultMinProperties = 0;
exports.defaultRequired = [];
exports.defaultMaxLength = Infinity;
exports.defaultMaxLength = Number.POSITIVE_INFINITY;
exports.defaultMinLength = 0;
exports.defaultMinimum = Number.NEGATIVE_INFINITY;
exports.defaultMaximum = Number.POSITIVE_INFINITY;
exports.defaultTypes = ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addAnyOfIfNecessary = (schemas) => schemas.length === 1 ? schemas[0] : { anyOf: schemas };
exports.addAnyOfIfNecessary = void 0;
const addAnyOfIfNecessary = (schemas) => schemas.length === 1 ? schemas[0] : { anyOf: schemas };
exports.addAnyOfIfNecessary = addAnyOfIfNecessary;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createArraySubsetFromConfig = exports.emptyArraySubset = exports.allArraySubset = void 0;
const array_subset_config_has_contradictions_1 = require("./array-subset/array-subset-config-has-contradictions");

@@ -30,3 +31,3 @@ const array_subset_config_to_json_schema_1 = require("./array-subset/array-subset-config-to-json-schema");

exports.emptyArraySubset = new subset_1.EmptySubset('array');
exports.createArraySubsetFromConfig = (config) => {
const createArraySubsetFromConfig = (config) => {
const simplifiedConfig = simplify_array_subset_config_1.simplifyArraySubsetConfig(config);

@@ -37,1 +38,2 @@ return array_subset_config_has_contradictions_1.arraySubsetConfigHasContradictions(simplifiedConfig)

};
exports.createArraySubsetFromConfig = createArraySubsetFromConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arraySubsetConfigHasContradictions = void 0;
const isEmptyItemsAndMinItemsContradiction = (config) => {

@@ -9,3 +10,3 @@ const itemsAcceptsNoValues = config.items.type === 'empty';

const isMaxItemsAndMinItemsContradiction = (config) => config.minItems > config.maxItems;
const isMinItemsContradiction = (config) => config.minItems === Infinity;
const isMinItemsContradiction = (config) => config.minItems === Number.POSITIVE_INFINITY;
const isItemsAndNotItemsContradiction = (config) => config.not.some((notConfig) => config.items.isSubsetOf(notConfig.items));

@@ -18,2 +19,3 @@ const contradictionTests = [

];
exports.arraySubsetConfigHasContradictions = (config) => contradictionTests.some((contradictionTest) => contradictionTest(config));
const arraySubsetConfigHasContradictions = (config) => contradictionTests.some((contradictionTest) => contradictionTest(config));
exports.arraySubsetConfigHasContradictions = arraySubsetConfigHasContradictions;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arraySubsetConfigToJsonSchema = void 0;
const keyword_defaults_1 = require("../../keyword-defaults");

@@ -9,2 +10,3 @@ const set_1 = require("../../set");

const getMinItemsSchema = (config) => config.minItems === keyword_defaults_1.defaultMinItems ? {} : { minItems: config.minItems };
exports.arraySubsetConfigToJsonSchema = (config) => (Object.assign(Object.assign(Object.assign(Object.assign({ type: 'array' }, getItemsSchema(config)), getMaxItemsSchema(config)), getMinItemsSchema(config)), getNotSchema(config)));
const arraySubsetConfigToJsonSchema = (config) => (Object.assign(Object.assign(Object.assign(Object.assign({ type: 'array' }, getItemsSchema(config)), getMaxItemsSchema(config)), getMinItemsSchema(config)), getNotSchema(config)));
exports.arraySubsetConfigToJsonSchema = arraySubsetConfigToJsonSchema;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.complementArraySubsetConfig = void 0;
const json_set_1 = require("../../json-set");

@@ -29,3 +30,3 @@ const keyword_defaults_1 = require("../../keyword-defaults");

const complementNot = (config) => config.not;
exports.complementArraySubsetConfig = (config) => [
const complementArraySubsetConfig = (config) => [
complementItems(config),

@@ -36,1 +37,2 @@ complementMaxItems(config),

];
exports.complementArraySubsetConfig = complementArraySubsetConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.intersectArraySubsetConfig = void 0;
const intersectMaxItems = (configA, configB) => Math.min(configA.maxItems, configB.maxItems);
const intersectMinItems = (configA, configB) => Math.max(configA.minItems, configB.minItems);
exports.intersectArraySubsetConfig = (configA, configB) => ({
const intersectArraySubsetConfig = (configA, configB) => ({
items: configA.items.intersect(configB.items),

@@ -11,1 +12,2 @@ maxItems: intersectMaxItems(configA, configB),

});
exports.intersectArraySubsetConfig = intersectArraySubsetConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.simplifyArraySubsetConfig = void 0;
const json_set_1 = require("../../json-set");

@@ -12,3 +13,3 @@ const keyword_defaults_1 = require("../../keyword-defaults");

const notItemsDisallowsEmptyArrays = (config) => config.not.length === 1 && config.not[0].items.type === 'empty';
exports.simplifyArraySubsetConfig = (config) => {
const simplifyArraySubsetConfig = (config) => {
if (maxItemsAllowsNoItems(config)) {

@@ -22,1 +23,2 @@ return Object.assign(Object.assign({}, config), { items: json_set_1.emptyJsonSet, maxItems: keyword_defaults_1.defaultMaxItems });

};
exports.simplifyArraySubsetConfig = simplifyArraySubsetConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createObjectSubsetFromConfig = exports.emptyObjectSubset = exports.allObjectSubset = void 0;
const complement_object_subset_config_1 = require("./object-subset/complement-object-subset-config");

@@ -33,3 +34,3 @@ const intersect_object_subset_config_1 = require("./object-subset/intersect-object-subset-config");

exports.emptyObjectSubset = new subset_1.EmptySubset('object');
exports.createObjectSubsetFromConfig = (config) => {
const createObjectSubsetFromConfig = (config) => {
const simplifiedConfig = simplify_object_subset_config_1.simplifyObjectSubsetConfig(config);

@@ -40,1 +41,2 @@ return object_subset_config_has_contradictions_1.objectSubsetConfigHasContradictions(simplifiedConfig)

};
exports.createObjectSubsetFromConfig = createObjectSubsetFromConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.complementObjectSubsetConfig = void 0;
const json_set_1 = require("../../json-set");

@@ -59,3 +60,3 @@ const keyword_defaults_1 = require("../../keyword-defaults");

}));
exports.complementObjectSubsetConfig = (config) => [
const complementObjectSubsetConfig = (config) => [
complementAdditionalProperties(config),

@@ -68,1 +69,2 @@ complementMaxProperties(config),

];
exports.complementObjectSubsetConfig = complementObjectSubsetConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.intersectObjectSubsetConfig = void 0;
const object_subset_config_1 = require("./object-subset-config");

@@ -18,3 +19,3 @@ const unique_1 = require("./unique");

const intersectRequired = (configA, configB) => unique_1.unique(configA.required, configB.required);
exports.intersectObjectSubsetConfig = (configA, configB) => ({
const intersectObjectSubsetConfig = (configA, configB) => ({
additionalProperties: configA.additionalProperties.intersect(configB.additionalProperties),

@@ -27,1 +28,2 @@ maxProperties: intersectMaxProperties(configA, configB),

});
exports.intersectObjectSubsetConfig = intersectObjectSubsetConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.objectSubsetConfigHasContradictions = void 0;
const object_subset_config_1 = require("./object-subset-config");

@@ -14,3 +15,3 @@ const isMinPropertiesBiggerThanDefinedProperties = (config) => {

const isMinPropertiesAndMaxPropertiesContradiction = (config) => config.minProperties > config.maxProperties;
const isMinPropertiesContradiction = (config) => config.minProperties === Infinity;
const isMinPropertiesContradiction = (config) => config.minProperties === Number.POSITIVE_INFINITY;
const isMaxPropertiesAndRequiredContradiction = (config) => config.required.length > config.maxProperties;

@@ -28,2 +29,3 @@ const isAdditionalPropertiesAndNotAdditionalPropertiesContradiction = (config) =>

];
exports.objectSubsetConfigHasContradictions = (config) => contradictionTests.some((contradictionTest) => contradictionTest(config));
const objectSubsetConfigHasContradictions = (config) => contradictionTests.some((contradictionTest) => contradictionTest(config));
exports.objectSubsetConfigHasContradictions = objectSubsetConfigHasContradictions;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.objectSubsetConfigToJsonSchema = void 0;
const keyword_defaults_1 = require("../../keyword-defaults");

@@ -20,2 +21,3 @@ const set_1 = require("../../set");

const getRequiredSchema = (config) => config.required.length === 0 ? {} : { required: config.required };
exports.objectSubsetConfigToJsonSchema = (config) => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, getAdditionalPropertiesSchema(config)), getMaxPropertiesSchema(config)), getMinPropertiesSchema(config)), getNotSchema(config)), getPropertiesSchema(config)), getRequiredSchema(config)), { type: 'object' }));
const objectSubsetConfigToJsonSchema = (config) => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, getAdditionalPropertiesSchema(config)), getMaxPropertiesSchema(config)), getMinPropertiesSchema(config)), getNotSchema(config)), getPropertiesSchema(config)), getRequiredSchema(config)), { type: 'object' }));
exports.objectSubsetConfigToJsonSchema = objectSubsetConfigToJsonSchema;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPropertyNames = (config) => Object.keys(config.properties);
exports.getPropertySet = (config, propertyName) => Object.getOwnPropertyNames(config.properties).includes(propertyName)
exports.getPropertySet = exports.getPropertyNames = void 0;
const getPropertyNames = (config) => Object.keys(config.properties);
exports.getPropertyNames = getPropertyNames;
const getPropertySet = (config, propertyName) => Object.getOwnPropertyNames(config.properties).includes(propertyName)
? config.properties[propertyName]
: config.additionalProperties;
exports.getPropertySet = getPropertySet;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.simplifyObjectSubsetConfig = void 0;
const json_set_1 = require("../../json-set");

@@ -14,3 +15,3 @@ const keyword_defaults_1 = require("../../keyword-defaults");

&& Object.keys(config.not[0].properties).length === 0;
exports.simplifyObjectSubsetConfig = (config) => {
const simplifyObjectSubsetConfig = (config) => {
if (maxPropertiesAllowsNoProperties(config)) {

@@ -24,1 +25,2 @@ return Object.assign(Object.assign({}, config), { maxProperties: keyword_defaults_1.defaultMaxProperties, additionalProperties: json_set_1.emptyJsonSet });

};
exports.simplifyObjectSubsetConfig = simplifyObjectSubsetConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unique = void 0;
const _ = require("lodash");
exports.unique = (arr1, arr2) => _.sortBy(_.uniq(arr1.concat(arr2)));
const unique = (arr1, arr2) => _.sortBy(_.uniq(arr1.concat(arr2)));
exports.unique = unique;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStringSubsetFromConfig = exports.emptyStringSubset = exports.allStringSubset = void 0;
const complement_string_subset_config_1 = require("./string-subset/complement-string-subset-config");

@@ -29,4 +30,5 @@ const intersect_string_subset_config_1 = require("./string-subset/intersect-string-subset-config");

exports.emptyStringSubset = new subset_1.EmptySubset('string');
exports.createStringSubsetFromConfig = (config) => string_subset_config_has_contradictions_1.stringSubsetConfigHasContradictions(config)
const createStringSubsetFromConfig = (config) => string_subset_config_has_contradictions_1.stringSubsetConfigHasContradictions(config)
? exports.emptyStringSubset
: new SomeStringSubset(config);
exports.createStringSubsetFromConfig = createStringSubsetFromConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.complementStringSubsetConfig = void 0;
const keyword_defaults_1 = require("../../keyword-defaults");

@@ -12,5 +13,6 @@ const complementMaxLength = (config) => ({

});
exports.complementStringSubsetConfig = (config) => [
const complementStringSubsetConfig = (config) => [
complementMaxLength(config),
complementMinLength(config)
];
exports.complementStringSubsetConfig = complementStringSubsetConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.intersectStringSubsetConfig = void 0;
const intersectMaxLength = (configA, configB) => Math.min(configA.maxLength, configB.maxLength);
const intersectMinLength = (configA, configB) => Math.max(configA.minLength, configB.minLength);
exports.intersectStringSubsetConfig = (configA, configB) => ({
const intersectStringSubsetConfig = (configA, configB) => ({
maxLength: intersectMaxLength(configA, configB),
minLength: intersectMinLength(configA, configB)
});
exports.intersectStringSubsetConfig = intersectStringSubsetConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringSubsetConfigHasContradictions = void 0;
const isMaxLengthAndMinLengthContradiction = (config) => config.minLength > config.maxLength;
const isMinLengthContradiction = (config) => config.minLength === Infinity;
const isMinLengthContradiction = (config) => config.minLength === Number.POSITIVE_INFINITY;
const contradictionTests = [

@@ -9,2 +10,3 @@ isMaxLengthAndMinLengthContradiction,

];
exports.stringSubsetConfigHasContradictions = (config) => contradictionTests.some((contradictionTest) => contradictionTest(config));
const stringSubsetConfigHasContradictions = (config) => contradictionTests.some((contradictionTest) => contradictionTest(config));
exports.stringSubsetConfigHasContradictions = stringSubsetConfigHasContradictions;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringSubsetConfigToJsonSchema = void 0;
const keyword_defaults_1 = require("../../keyword-defaults");
const getMaxLengthSchema = (config) => config.maxLength === keyword_defaults_1.defaultMaxLength ? {} : { maxLength: config.maxLength };
const getMinLengthSchema = (config) => config.minLength === keyword_defaults_1.defaultMinLength ? {} : { minLength: config.minLength };
exports.stringSubsetConfigToJsonSchema = (config) => (Object.assign(Object.assign({ type: 'string' }, getMaxLengthSchema(config)), getMinLengthSchema(config)));
const stringSubsetConfigToJsonSchema = (config) => (Object.assign(Object.assign({ type: 'string' }, getMaxLengthSchema(config)), getMinLengthSchema(config)));
exports.stringSubsetConfigToJsonSchema = stringSubsetConfigToJsonSchema;
"use strict";
// tslint:disable:max-classes-per-file
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmptySubset = exports.AllSubset = void 0;
class AllSubset {

@@ -5,0 +6,0 @@ constructor(setType) {

"use strict";
// tslint:disable:max-classes-per-file
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTypeSetFromSubsets = void 0;
const set_1 = require("./set");

@@ -113,3 +114,3 @@ class AllTypeSet {

const getNonEmptySubsets = (subsets) => subsets.filter((subset) => subset.type !== 'empty');
exports.createTypeSetFromSubsets = (setType, subsets) => {
const createTypeSetFromSubsets = (setType, subsets) => {
const notEmptySubsets = getNonEmptySubsets(subsets);

@@ -124,1 +125,2 @@ if (notEmptySubsets.length === 0) {

};
exports.createTypeSetFromSubsets = createTypeSetFromSubsets;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Ajv = require("ajv");
exports.validateSchemas = void 0;
const ajv_1 = require("ajv");
// tslint:disable-next-line:no-var-requires no-submodule-imports
const jsonSchemaDraft7Schema = require('json-schema-spec-types/lib/json-schema-draft-07-schema');
const validateJsonSchema = (schema) => {
const ajv = new Ajv();
const validate = ajv.compile(jsonSchemaDraft7Schema);
const valid = validate(schema);
const ajv = new ajv_1.default({ strict: false, meta: false });
ajv.addMetaSchema(jsonSchemaDraft7Schema);
const valid = ajv.validateSchema(schema);
if (valid) {

@@ -14,7 +15,7 @@ return { isValid: true };

return {
failureReason: ajv.errorsText(validate.errors || undefined),
failureReason: ajv.errorsText(ajv.errors || undefined),
isValid: false
};
};
exports.validateSchemas = (sourceSchema, destinationSchema) => {
const validateSchemas = (sourceSchema, destinationSchema) => {
const sourceSchemaValidationResult = validateJsonSchema(sourceSchema);

@@ -30,1 +31,2 @@ if (!sourceSchemaValidationResult.isValid) {

};
exports.validateSchemas = validateSchemas;

@@ -12,2 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.FileReader = void 0;
const verror_1 = require("verror");

@@ -14,0 +15,0 @@ class FileReader {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileSystem = void 0;
const fs = require("fs");

@@ -4,0 +5,0 @@ class FileSystem {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Reporter = void 0;
class Reporter {

@@ -4,0 +5,0 @@ constructor(wrappedLog) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WrappedLog = void 0;
class WrappedLog {

@@ -4,0 +5,0 @@ info(message) {

@@ -69,3 +69,3 @@ 'use strict';

return gulp.src('CHANGELOG.md')
.pipe(conventionalChangelog({preset: 'angular'}))
.pipe(conventionalChangelog({ preset: 'conventionalcommits'}))
.pipe(gulp.dest('./'));

@@ -99,3 +99,3 @@ };

const lintCommits = () =>
utilities.exec('./node_modules/.bin/commitlint --from=HEAD~20 --preset angular');
utilities.exec('./node_modules/.bin/commitlint --from=HEAD~20');

@@ -102,0 +102,0 @@ const lintTypescript = () =>

@@ -19,6 +19,6 @@ # Json Schema Diff Supported Keywords

| multipleOf | no |
| maximum | no |
| exclusiveMaximum | no |
| minimum | no |
| exclusiveMinimum | no |
| maximum | yes |
| exclusiveMaximum | yes |
| minimum | yes |
| exclusiveMinimum | yes |

@@ -25,0 +25,0 @@ ## Validation Keywords for Strings

@@ -8,5 +8,7 @@ import {CoreSchemaMetaSchema, JsonSchema, JsonSchemaMap, SimpleTypes} from 'json-schema-spec-types';

import {
defaultMaximum,
defaultMaxItems,
defaultMaxLength,
defaultMaxProperties,
defaultMinimum,
defaultMinItems,

@@ -51,6 +53,10 @@ defaultMinLength,

additionalProperties: parseSchemaOrUndefinedAsJsonSet(schema.additionalProperties),
exclusiveMaximum: parseNumericKeyword(schema.exclusiveMaximum, defaultMaximum),
exclusiveMinimum: parseNumericKeyword(schema.exclusiveMinimum, defaultMinimum),
items: parseSchemaOrUndefinedAsJsonSet(schema.items),
maximum: parseNumericKeyword(schema.maximum, defaultMaximum),
maxItems: parseNumericKeyword(schema.maxItems, defaultMaxItems),
maxLength: parseNumericKeyword(schema.maxLength, defaultMaxLength),
maxProperties: parseNumericKeyword(schema.maxProperties, defaultMaxProperties),
minimum: parseNumericKeyword(schema.minimum, defaultMinimum),
minItems: parseNumericKeyword(schema.minItems, defaultMinItems),

@@ -57,0 +63,0 @@ minLength: parseNumericKeyword(schema.minLength, defaultMinLength),

@@ -6,2 +6,3 @@ import {SimpleTypes} from 'json-schema-spec-types';

import {createArraySet} from './create-array-set';
import {createNumberSet} from './create-number-set';
import {createObjectSet} from './create-object-set';

@@ -13,3 +14,7 @@ import {createStringSet} from './create-string-set';

additionalProperties: Set<'json'>;
exclusiveMaximum: number;
exclusiveMinimum: number;
items: Set<'json'>;
maximum: number;
minimum: number;
maxItems: number;

@@ -30,5 +35,4 @@ maxLength: number;

boolean: createTypeSet('boolean', parsedSchemaKeywords.type),
integer: createTypeSet('integer', parsedSchemaKeywords.type),
null: createTypeSet('null', parsedSchemaKeywords.type),
number: createTypeSet('number', parsedSchemaKeywords.type),
number: createNumberSet(parsedSchemaKeywords),
object: createObjectSet(parsedSchemaKeywords),

@@ -35,0 +39,0 @@ string: createStringSet(parsedSchemaKeywords)

@@ -6,3 +6,2 @@ import {Set} from '../set';

boolean: Set<'boolean'>;
integer: Set<'integer'>;
null: Set<'null'>;

@@ -19,3 +18,2 @@ number: Set<'number'>;

boolean: callbackFn(a.boolean, b.boolean),
integer: callbackFn(a.integer, b.integer),
null: callbackFn(a.null, b.null),

@@ -36,3 +34,2 @@ number: callbackFn(a.number, b.number),

boolean: config.boolean.complement(),
integer: config.integer.complement(),
null: config.null.complement(),

@@ -39,0 +36,0 @@ number: config.number.complement(),

@@ -5,9 +5,11 @@ import {SimpleTypes} from 'json-schema-spec-types';

export const defaultProperties: ParsedPropertiesKeyword = {};
export const defaultMaxItems: number = Infinity;
export const defaultMaxProperties: number = Infinity;
export const defaultMaxItems: number = Number.POSITIVE_INFINITY;
export const defaultMaxProperties: number = Number.POSITIVE_INFINITY;
export const defaultMinItems: number = 0;
export const defaultMinProperties: number = 0;
export const defaultRequired: string[] = [];
export const defaultMaxLength: number = Infinity;
export const defaultMaxLength: number = Number.POSITIVE_INFINITY;
export const defaultMinLength: number = 0;
export const defaultMinimum: number = Number.NEGATIVE_INFINITY;
export const defaultMaximum: number = Number.POSITIVE_INFINITY;
export const defaultTypes: SimpleTypes[] = ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'];

@@ -11,3 +11,3 @@ import {ArraySubsetConfig} from './array-subset-config';

const isMinItemsContradiction = (config: ArraySubsetConfig): boolean => config.minItems === Infinity;
const isMinItemsContradiction = (config: ArraySubsetConfig): boolean => config.minItems === Number.POSITIVE_INFINITY;

@@ -17,5 +17,3 @@ const isItemsAndNotItemsContradiction = (config: ArraySubsetConfig): boolean =>

type contradictionTestFn = (config: ArraySubsetConfig) => boolean;
const contradictionTests: contradictionTestFn[] = [
const contradictionTests = [
isEmptyItemsAndMinItemsContradiction,

@@ -22,0 +20,0 @@ isMaxItemsAndMinItemsContradiction,

@@ -24,3 +24,3 @@ import {getPropertySet, ObjectSubsetConfig} from './object-subset-config';

const isMinPropertiesContradiction = (config: ObjectSubsetConfig): boolean =>
config.minProperties === Infinity;
config.minProperties === Number.POSITIVE_INFINITY;

@@ -34,5 +34,3 @@ const isMaxPropertiesAndRequiredContradiction = (config: ObjectSubsetConfig): boolean =>

type contradictionTestFn = (config: ObjectSubsetConfig) => boolean;
const contradictionTests: contradictionTestFn[] = [
const contradictionTests = [
isRequiredAndPropertiesAndAdditionalPropertiesContradiction,

@@ -39,0 +37,0 @@ isMinPropertiesAndAdditionalPropertiesContradiction,

@@ -6,3 +6,3 @@ import {StringSubsetConfig} from './string-subset-config';

const isMinLengthContradiction = (config: StringSubsetConfig): boolean => config.minLength === Infinity;
const isMinLengthContradiction = (config: StringSubsetConfig): boolean => config.minLength === Number.POSITIVE_INFINITY;

@@ -9,0 +9,0 @@ type contradictionTestFn = (config: StringSubsetConfig) => boolean;

@@ -1,2 +0,2 @@

import * as Ajv from 'ajv';
import Ajv from 'ajv';

@@ -18,6 +18,7 @@ // tslint:disable-next-line:no-var-requires no-submodule-imports

const validateJsonSchema = (schema: any): ValidationResult => {
const ajv = new Ajv();
const validate = ajv.compile(jsonSchemaDraft7Schema);
const valid = validate(schema);
const ajv = new Ajv({strict: false, meta: false});
ajv.addMetaSchema(jsonSchemaDraft7Schema);
const valid = ajv.validateSchema(schema);
if (valid) {

@@ -28,3 +29,3 @@ return {isValid: true};

return {
failureReason: ajv.errorsText(validate.errors || undefined),
failureReason: ajv.errorsText(ajv.errors || undefined),
isValid: false

@@ -31,0 +32,0 @@ };

{
"name": "json-schema-diff",
"version": "0.16.0",
"version": "0.17.0",
"description": "A language agnostic CLI tool and nodejs api to identify differences between two json schema files.",

@@ -38,7 +38,7 @@ "bin": {

"devDependencies": {
"@commitlint/cli": "^9.1.1",
"@commitlint/config-conventional": "^9.1.1",
"@types/jasmine": "^3.5.11",
"@types/json-schema": "^7.0.5",
"@types/lodash": "^4.14.158",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@types/jasmine": "^3.6.1",
"@types/json-schema": "^7.0.6",
"@types/lodash": "^4.14.165",
"@types/node": "^12",

@@ -51,4 +51,4 @@ "@types/verror": "^1.10.4",

"gulp-cli": "^2.3.0",
"gulp-conventional-changelog": "^2.0.32",
"gulp-filter": "^6.0.0",
"gulp-conventional-changelog": "^2.0.35",
"gulp-filter": "^7.0.0",
"gulp-git": "^2.10.1",

@@ -60,14 +60,14 @@ "gulp-jasmine": "^4.0.0",

"run-sequence": "^2.2.1",
"tslint": "6.1.2",
"typescript": "3.9.7"
"tslint": "6.1.3",
"typescript": "4.3.4"
},
"types": "lib/api-types.d.ts",
"dependencies": {
"ajv": "^6.12.3",
"commander": "^5.0.0",
"ajv": "^8.6.0",
"commander": "^7.2.0",
"json-schema-ref-parser": "^9.0.6",
"json-schema-spec-types": "^0.1.2",
"lodash": "^4.17.19",
"lodash": "^4.17.20",
"verror": "^1.10.0"
}
}

@@ -5,4 +5,4 @@ # Json Schema Diff

## Requirements
- nodejs 8.x or higher (tested using 8.x, 10.x, 12.x and 13.x)
- npm 3.x or higher (tested using 3.x and 6.x)
- nodejs 10.x or higher (tested using 10.x, 12.x, 14.x and 16.x)
- npm 6.x or higher (tested using 6.x and 7.x)

@@ -9,0 +9,0 @@ ## Installation

@@ -225,2 +225,26 @@ import {DiffTestCase, registerDiffTestCases} from '../support/register-diff-test-cases';

}
},
{
description: 'any of not integers or integers to numbers',
examples: [1, 1.5, 'foo'],
input: {
a: {
anyOf: [
{
not: {
type: 'integer'
},
type: 'number'
},
{
type: 'integer'
}
]
},
b: {type: 'number'}
},
output: {
added: false,
removed: false
}
}

@@ -227,0 +251,0 @@ ];

@@ -42,2 +42,26 @@ import {DiffTestCase, registerDiffTestCases} from '../support/register-diff-test-cases';

{
description: 'all types schema to true schema',
examples: ['a', 1, {}],
input: {
a: {type: ['string', 'array', 'number', 'integer', 'boolean', 'null', 'object']},
b: true
},
output: {
added: false,
removed: false
}
},
{
description: 'all types schema (not specifying integer) to true schema',
examples: ['a', 1, {}],
input: {
a: {type: ['string', 'array', 'number', 'boolean', 'null', 'object']},
b: true
},
output: {
added: false,
removed: false
}
},
{
description: 'single type schema to false',

@@ -44,0 +68,0 @@ examples: ['a', 1],

@@ -133,3 +133,3 @@ import {DiffTestCase, registerDiffTestCases} from '../support/register-diff-test-cases';

maxItems: 1,
type: ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string']
type: ['array', 'boolean', 'null', 'number', 'object', 'string']
},

@@ -233,3 +233,3 @@ removed: {

},
type: ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string']
type: ['array', 'boolean', 'null', 'number', 'object', 'string']
},

@@ -449,2 +449,56 @@ removed: {

});
describe('numbers', () => {
const testCases: DiffTestCase[] = [
{
description: 'from numbers with integer constraint to numbers with the complement of that constraint',
examples: [1, 1.5, 'foo'],
input: {
a: {
type: 'integer'
},
b: {
not: {
type: 'integer'
},
type: 'number'
}
},
output: {
added: {
not: {
type: 'integer'
},
type: 'number'
},
removed: {
type: 'integer'
}
}
},
{
description: 'from numbers with integer to double negation of integer',
examples: [1, 1.5, 'foo'],
input: {
a: {
type: 'integer'
},
b: {
not: {
not: {
type: 'integer'
}
},
type: 'number'
}
},
output: {
added: false,
removed: false
}
}
];
registerDiffTestCases(testCases);
});
});

@@ -112,3 +112,3 @@ import {DiffTestCase, registerDiffTestCases} from '../support/register-diff-test-cases';

a: {
maxLength: Infinity,
maxLength: Number.POSITIVE_INFINITY,
type: 'string'

@@ -192,3 +192,3 @@ },

a: {
maxLength: Infinity,
maxLength: Number.POSITIVE_INFINITY,
minLength: 0,

@@ -195,0 +195,0 @@ type: 'string'

@@ -15,4 +15,4 @@ import {JsonSchema} from 'json-schema-spec-types';

'Source schema is not a valid json schema: ' +
'data.type should be equal to one of the allowed values, ' +
'data.type should be array, data.type should match some schema in anyOf'
'data/type must be equal to one of the allowed values, ' +
'data/type must be array, data/type must match a schema in anyOf'
));

@@ -29,4 +29,4 @@ });

'Destination schema is not a valid json schema: ' +
'data.type should be equal to one of the allowed values, ' +
'data.type should be array, data.type should match some schema in anyOf'
'data/type must be equal to one of the allowed values, ' +
'data/type must be array, data/type must match a schema in anyOf'
));

@@ -57,3 +57,3 @@ });

'Source schema is not a valid json schema: ' +
'data.properties[\'numberProperty\'].exclusiveMinimum should be number'
'data/properties/numberProperty/exclusiveMinimum must be number'
));

@@ -60,0 +60,0 @@ });

@@ -1,2 +0,2 @@

import * as Ajv from 'ajv';
import Ajv from 'ajv';
import {JsonSchema} from 'json-schema-spec-types';

@@ -37,3 +37,3 @@ import {invokeDiff} from './invoke-diff';

const ajv = new Ajv();
const ajv = new Ajv({strict: false});
const validateA = ajv.compile(testCase.input.a);

@@ -40,0 +40,0 @@ const validateB = ajv.compile(testCase.input.b);

@@ -12,4 +12,5 @@ {

"member-access": [true, "check-constructor"],
"array-type": [true, "array-simple"]
"array-type": [true, "array-simple"],
"semicolon": [true, "always"]
}
}

Sorry, the diff of this file is not supported yet

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