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

json-schema-diff

Package Overview
Dependencies
Maintainers
3
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.3.0 to 0.4.0

10

CHANGELOG.md

@@ -0,1 +1,11 @@

<a name="0.4.0"></a>
# [0.4.0](https://bitbucket.org/atlassian/json-schema-diff/compare/0.3.0...0.4.0) (2018-05-03)
### Features
* add support for anyOf keyword ([1753af1](https://bitbucket.org/atlassian/json-schema-diff/commits/1753af1))
<a name="0.3.0"></a>

@@ -2,0 +12,0 @@ # [0.3.0](https://bitbucket.org/atlassian/json-schema-diff/compare/0.2.0...0.3.0) (2018-05-02)

3

dist/json-schema-diff/differ/diff-schemas/json-schema-set.js

@@ -19,2 +19,5 @@ "use strict";

}
union(other) {
return new JsonSchemaSet(this.arraySet.union(other.arraySet), this.booleanSet.union(other.booleanSet), this.integerSet.union(other.integerSet), this.numberSet.union(other.numberSet), this.nullSet.union(other.nullSet), this.objectSet.union(other.objectSet), this.stringSet.union(other.stringSet));
}
toRepresentations() {

@@ -21,0 +24,0 @@ return this.arraySet.toRepresentations()

@@ -21,2 +21,13 @@ "use strict";

}
union(otherSet) {
return otherSet.unionWithAll(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllArraySet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllArraySet(mergedSchemaOrigins);
}
complement() {

@@ -51,2 +62,13 @@ return new EmptyArraySet(this.schemaOrigins);

}
union(otherSet) {
return otherSet.unionWithEmpty(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllArraySet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyArraySet(mergedSchemaOrigins);
}
complement() {

@@ -53,0 +75,0 @@ return new AllArraySet(this.schemaOrigins);

@@ -21,2 +21,13 @@ "use strict";

}
union(otherSet) {
return otherSet.unionWithAll(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllBooleanSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllBooleanSet(mergedSchemaOrigins);
}
complement() {

@@ -51,2 +62,13 @@ return new EmptyBooleanSet(this.schemaOrigins);

}
union(otherSet) {
return otherSet.unionWithEmpty(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllBooleanSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyBooleanSet(mergedSchemaOrigins);
}
complement() {

@@ -53,0 +75,0 @@ return new AllBooleanSet(this.schemaOrigins);

@@ -21,2 +21,13 @@ "use strict";

}
union(otherSet) {
return otherSet.unionWithAll(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllIntegerSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllIntegerSet(mergedSchemaOrigins);
}
complement() {

@@ -51,2 +62,13 @@ return new EmptyIntegerSet(this.schemaOrigins);

}
union(otherSet) {
return otherSet.unionWithEmpty(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllIntegerSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyIntegerSet(mergedSchemaOrigins);
}
complement() {

@@ -53,0 +75,0 @@ return new AllIntegerSet(this.schemaOrigins);

@@ -21,2 +21,13 @@ "use strict";

}
union(otherSet) {
return otherSet.unionWithAll(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllNullSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllNullSet(mergedSchemaOrigins);
}
complement() {

@@ -51,2 +62,13 @@ return new EmptyNullSet(this.schemaOrigins);

}
union(otherSet) {
return otherSet.unionWithEmpty(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllNullSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyNullSet(mergedSchemaOrigins);
}
complement() {

@@ -53,0 +75,0 @@ return new AllNullSet(this.schemaOrigins);

@@ -21,2 +21,13 @@ "use strict";

}
union(otherSet) {
return otherSet.unionWithAll(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllNumberSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllNumberSet(mergedSchemaOrigins);
}
complement() {

@@ -51,2 +62,13 @@ return new EmptyNumberSet(this.schemaOrigins);

}
union(otherSet) {
return otherSet.unionWithEmpty(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllNumberSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyNumberSet(mergedSchemaOrigins);
}
complement() {

@@ -53,0 +75,0 @@ return new AllNumberSet(this.schemaOrigins);

@@ -21,2 +21,13 @@ "use strict";

}
union(otherSet) {
return otherSet.unionWithAll(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllObjectSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllObjectSet(mergedSchemaOrigins);
}
complement() {

@@ -51,2 +62,13 @@ return new EmptyObjectSet(this.schemaOrigins);

}
union(otherSet) {
return otherSet.unionWithEmpty(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllObjectSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyObjectSet(mergedSchemaOrigins);
}
complement() {

@@ -53,0 +75,0 @@ return new AllObjectSet(this.schemaOrigins);

@@ -21,2 +21,13 @@ "use strict";

}
union(otherSet) {
return otherSet.unionWithAll(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllStringSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllStringSet(mergedSchemaOrigins);
}
complement() {

@@ -51,2 +62,13 @@ return new EmptyStringSet(this.schemaOrigins);

}
union(otherSet) {
return otherSet.unionWithEmpty(this);
}
unionWithAll(otherAllSet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllStringSet(mergedSchemaOrigins);
}
unionWithEmpty(otherEmptySet) {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyStringSet(mergedSchemaOrigins);
}
complement() {

@@ -53,0 +75,0 @@ return new AllStringSet(this.schemaOrigins);

@@ -51,2 +51,11 @@ "use strict";

};
const parseAnyOf = (anyOfSchemas, origin, location, initialJsonSchemaSet) => {
let jsonSchemaSetResult = parseWithLocation(anyOfSchemas[0], origin, `${location}.anyOf[0]`);
for (let i = 1; i < anyOfSchemas.length; i += 1) {
const currentJsonSchemaSet = parseWithLocation(anyOfSchemas[i], origin, `${location}.anyOf[${i}]`);
jsonSchemaSetResult = jsonSchemaSetResult.union(currentJsonSchemaSet);
}
jsonSchemaSetResult = jsonSchemaSetResult.intersect(initialJsonSchemaSet);
return jsonSchemaSetResult;
};
const parseNot = (notSchema, origin, location, initialJsonSchemaSet) => {

@@ -62,2 +71,5 @@ const parsedNotJsonSchemaSet = parseWithLocation(notSchema, origin, `${location}.not`);

}
if (schema.anyOf) {
jsonSchemaSet = parseAnyOf(schema.anyOf, origin, location, jsonSchemaSet);
}
if (schema.not) {

@@ -64,0 +76,0 @@ jsonSchemaSet = parseNot(schema.not, origin, location, jsonSchemaSet);

@@ -44,2 +44,14 @@ import {ArraySet} from './json-schema-set/array-set';

public union(other: JsonSchemaSet): JsonSchemaSet {
return new JsonSchemaSet(
this.arraySet.union(other.arraySet),
this.booleanSet.union(other.booleanSet),
this.integerSet.union(other.integerSet),
this.numberSet.union(other.numberSet),
this.nullSet.union(other.nullSet),
this.objectSet.union(other.objectSet),
this.stringSet.union(other.stringSet)
);
}
public toRepresentations(): Representation[] {

@@ -46,0 +58,0 @@ return this.arraySet.toRepresentations()

@@ -6,3 +6,4 @@ // tslint:disable:max-classes-per-file

export interface ArraySet extends Set<'array'> {}
export interface ArraySet extends Set<'array'> {
}

@@ -12,3 +13,4 @@ export class AllArraySet implements ArraySet {

public constructor(public readonly schemaOrigins: SchemaOrigin[]) {}
public constructor(public readonly schemaOrigins: SchemaOrigin[]) {
}

@@ -29,2 +31,16 @@ public intersect(otherSet: ArraySet): ArraySet {

public union(otherSet: ArraySet): ArraySet {
return otherSet.unionWithAll(this);
}
public unionWithAll(otherAllSet: ArraySet): ArraySet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllArraySet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: ArraySet): ArraySet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllArraySet(mergedSchemaOrigins);
}
public complement(): ArraySet {

@@ -47,3 +63,4 @@ return new EmptyArraySet(this.schemaOrigins);

public constructor(public readonly schemaOrigins: SchemaOrigin[]) {}
public constructor(public readonly schemaOrigins: SchemaOrigin[]) {
}

@@ -64,2 +81,16 @@ public intersect(otherSet: ArraySet): ArraySet {

public union(otherSet: ArraySet): ArraySet {
return otherSet.unionWithEmpty(this);
}
public unionWithAll(otherAllSet: ArraySet): ArraySet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllArraySet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: ArraySet): ArraySet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyArraySet(mergedSchemaOrigins);
}
public complement(): ArraySet {

@@ -66,0 +97,0 @@ return new AllArraySet(this.schemaOrigins);

@@ -27,2 +27,15 @@ // tslint:disable:max-classes-per-file

public union(otherSet: BooleanSet): BooleanSet {
return otherSet.unionWithAll(this);
}
public unionWithAll(otherAllSet: BooleanSet): BooleanSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllBooleanSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: BooleanSet): BooleanSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllBooleanSet(mergedSchemaOrigins);
}
public complement(): BooleanSet {

@@ -60,3 +73,16 @@ return new EmptyBooleanSet(this.schemaOrigins);

}
public union(otherSet: BooleanSet): BooleanSet {
return otherSet.unionWithEmpty(this);
}
public unionWithAll(otherAllSet: BooleanSet): BooleanSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllBooleanSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: BooleanSet): BooleanSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyBooleanSet(mergedSchemaOrigins);
}
public complement(): BooleanSet {

@@ -63,0 +89,0 @@ return new AllBooleanSet(this.schemaOrigins);

@@ -27,2 +27,15 @@ // tslint:disable:max-classes-per-file

public union(otherSet: IntegerSet): IntegerSet {
return otherSet.unionWithAll(this);
}
public unionWithAll(otherAllSet: IntegerSet): IntegerSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllIntegerSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: IntegerSet): IntegerSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllIntegerSet(mergedSchemaOrigins);
}
public complement(): IntegerSet {

@@ -61,2 +74,16 @@ return new EmptyIntegerSet(this.schemaOrigins);

public union(otherSet: IntegerSet): IntegerSet {
return otherSet.unionWithEmpty(this);
}
public unionWithAll(otherAllSet: IntegerSet): IntegerSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllIntegerSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: IntegerSet): IntegerSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyIntegerSet(mergedSchemaOrigins);
}
public complement(): IntegerSet {

@@ -63,0 +90,0 @@ return new AllIntegerSet(this.schemaOrigins);

@@ -27,2 +27,16 @@ // tslint:disable:max-classes-per-file

public union(otherSet: NullSet): NullSet {
return otherSet.unionWithAll(this);
}
public unionWithAll(otherAllSet: NullSet): NullSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllNullSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: NullSet): NullSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllNullSet(mergedSchemaOrigins);
}
public complement(): NullSet {

@@ -61,2 +75,16 @@ return new EmptyNullSet(this.schemaOrigins);

public union(otherSet: NullSet): NullSet {
return otherSet.unionWithEmpty(this);
}
public unionWithAll(otherAllSet: NullSet): NullSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllNullSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: NullSet): NullSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyNullSet(mergedSchemaOrigins);
}
public complement(): NullSet {

@@ -63,0 +91,0 @@ return new AllNullSet(this.schemaOrigins);

@@ -26,3 +26,16 @@ // tslint:disable:max-classes-per-file

}
public union(otherSet: NumberSet): NumberSet {
return otherSet.unionWithAll(this);
}
public unionWithAll(otherAllSet: NumberSet): NumberSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllNumberSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: NumberSet): NumberSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllNumberSet(mergedSchemaOrigins);
}
public complement(): NumberSet {

@@ -61,2 +74,16 @@ return new EmptyNumberSet(this.schemaOrigins);

public union(otherSet: NumberSet): NumberSet {
return otherSet.unionWithEmpty(this);
}
public unionWithAll(otherAllSet: NumberSet): NumberSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllNumberSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: NumberSet): NumberSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyNumberSet(mergedSchemaOrigins);
}
public complement(): NumberSet {

@@ -63,0 +90,0 @@ return new AllNumberSet(this.schemaOrigins);

@@ -26,3 +26,15 @@ // tslint:disable:max-classes-per-file

}
public union(otherSet: ObjectSet): ObjectSet {
return otherSet.unionWithAll(this);
}
public unionWithAll(otherAllSet: ObjectSet): ObjectSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllObjectSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: ObjectSet): ObjectSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllObjectSet(mergedSchemaOrigins);
}
public complement(): ObjectSet {

@@ -60,3 +72,16 @@ return new EmptyObjectSet(this.schemaOrigins);

}
public union(otherSet: ObjectSet): ObjectSet {
return otherSet.unionWithEmpty(this);
}
public unionWithAll(otherAllSet: ObjectSet): ObjectSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllObjectSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: ObjectSet): ObjectSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyObjectSet(mergedSchemaOrigins);
}
public complement(): ObjectSet {

@@ -63,0 +88,0 @@ return new AllObjectSet(this.schemaOrigins);

@@ -29,4 +29,7 @@ export type RepresentationType = 'type';

intersectWithEmpty(otherEmptySet: Set<T>): Set<T>;
union(otherSet: Set<T>): Set<T>;
unionWithAll(otherAllSet: Set<T>): Set<T>;
unionWithEmpty(otherEmptySet: Set<T>): Set<T>;
complement(): Set<T>;
toRepresentations(): Representation[];
}

@@ -27,2 +27,15 @@ // tslint:disable:max-classes-per-file

public union(otherSet: StringSet): StringSet {
return otherSet.unionWithAll(this);
}
public unionWithAll(otherAllSet: StringSet): StringSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllStringSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: StringSet): StringSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new AllStringSet(mergedSchemaOrigins);
}
public complement(): StringSet {

@@ -61,2 +74,16 @@ return new EmptyStringSet(this.schemaOrigins);

public union(otherSet: StringSet): StringSet {
return otherSet.unionWithEmpty(this);
}
public unionWithAll(otherAllSet: StringSet): StringSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherAllSet.schemaOrigins);
return new AllStringSet(mergedSchemaOrigins);
}
public unionWithEmpty(otherEmptySet: StringSet): StringSet {
const mergedSchemaOrigins = this.schemaOrigins.concat(otherEmptySet.schemaOrigins);
return new EmptyStringSet(mergedSchemaOrigins);
}
public complement(): StringSet {

@@ -63,0 +90,0 @@ return new AllStringSet(this.schemaOrigins);

@@ -82,2 +82,18 @@ import {CoreSchemaMetaSchema, SimpleTypes} from './json-schema';

const parseAnyOf = (anyOfSchemas: CoreSchemaMetaSchema[],
origin: SchemaOriginType,
location: string,
initialJsonSchemaSet: JsonSchemaSet): JsonSchemaSet => {
let jsonSchemaSetResult = parseWithLocation(anyOfSchemas[0], origin, `${location}.anyOf[0]`);
for (let i = 1; i < anyOfSchemas.length; i += 1) {
const currentJsonSchemaSet = parseWithLocation(anyOfSchemas[i], origin, `${location}.anyOf[${i}]`);
jsonSchemaSetResult = jsonSchemaSetResult.union(currentJsonSchemaSet);
}
jsonSchemaSetResult = jsonSchemaSetResult.intersect(initialJsonSchemaSet);
return jsonSchemaSetResult;
};
const parseNot = (notSchema: CoreSchemaMetaSchema,

@@ -100,2 +116,5 @@ origin: SchemaOriginType,

}
if (schema.anyOf) {
jsonSchemaSet = parseAnyOf(schema.anyOf, origin, location, jsonSchemaSet);
}
if (schema.not) {

@@ -102,0 +121,0 @@ jsonSchemaSet = parseNot(schema.not, origin, location, jsonSchemaSet);

2

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

@@ -5,0 +5,0 @@ "bin": {

@@ -6,3 +6,3 @@ import {Differ, DiffResult} from '../../../lib/json-schema-diff/differ';

import {
diffResultDifferenceValueBuilder
diffResultDifferenceValueBuilder
} from '../support/builders/diff-result-difference-value-builder';

@@ -27,6 +27,4 @@ import {customMatchers, CustomMatchers} from '../support/custom-matchers/diff-custom-matcher';

const invokeDiffAndExpectToFail = async (
sourceSchema: JsonSchema,
destinationSchema: JsonSchema
): Promise<Error> => {
const invokeDiffAndExpectToFail = async (sourceSchema: JsonSchema,
destinationSchema: JsonSchema): Promise<Error> => {
return expectToFail(new Differ().diff(sourceSchema, destinationSchema));

@@ -444,6 +442,6 @@ };

const sourceSchema: JsonSchema = {
not: { type: 'string'}
not: {type: 'string'}
};
const destinationSchema: JsonSchema = {
not: { type: 'number'}
not: {type: 'number'}
};

@@ -484,2 +482,138 @@

});
describe('anyOf', () => {
it('should find an add and a remove difference inside an anyOf', async () => {
const sourceSchema: JsonSchema = {
anyOf: [
{type: 'string'},
{type: 'number'}
]
};
const destinationSchema: JsonSchema = {
anyOf: [
{type: 'string'},
{type: 'boolean'}
]
};
const diffResult = await invokeDiff(sourceSchema, destinationSchema);
const baseDifferenceBuilder = diffResultDifferenceBuilder
.withSourceValues([
diffResultDifferenceValueBuilder
.withValue(undefined)
.withLocation('.type'),
diffResultDifferenceValueBuilder
.withValue('string')
.withLocation('.anyOf[0].type'),
diffResultDifferenceValueBuilder
.withValue('number')
.withLocation('.anyOf[1].type')
])
.withDestinationValues([
diffResultDifferenceValueBuilder
.withValue(undefined)
.withLocation('.type'),
diffResultDifferenceValueBuilder
.withValue('string')
.withLocation('.anyOf[0].type'),
diffResultDifferenceValueBuilder
.withValue('boolean')
.withLocation('.anyOf[1].type')]);
const addDifference = baseDifferenceBuilder
.withTypeAddType()
.withValue('boolean')
.build();
const removeDifference = baseDifferenceBuilder
.withTypeRemoveType()
.withValue('number')
.build();
expect(diffResult).toContainDifferences([addDifference, removeDifference]);
});
});
describe('keyword combination', () => {
it('should find an add and remove differences for a schema with all the keywords', async () => {
const sourceSchema: JsonSchema = {
allOf: [
{type: 'object'},
{type: ['object', 'array']}
],
anyOf: [
{type: 'object'},
{not: {type: 'array'}}
]
};
const destinationSchema: JsonSchema = {
allOf: [
{type: 'string'},
{type: ['string', 'array']}
],
anyOf: [
{type: 'string'},
{not: {type: 'array'}}
]
};
const diffResult = await invokeDiff(sourceSchema, destinationSchema);
const baseDifference = diffResultDifferenceBuilder
.withSourceValues([
diffResultDifferenceValueBuilder
.withLocation('.allOf[0].type')
.withValue('object'),
diffResultDifferenceValueBuilder
.withLocation('.allOf[1].type')
.withValue(['object', 'array']),
diffResultDifferenceValueBuilder
.withLocation('.anyOf[0].type')
.withValue('object'),
diffResultDifferenceValueBuilder
.withLocation('.anyOf[1].type')
.withValue(undefined),
diffResultDifferenceValueBuilder
.withLocation('.anyOf[1].not.type')
.withValue('array'),
diffResultDifferenceValueBuilder
.withLocation('.type')
.withValue(undefined)
])
.withDestinationValues([
diffResultDifferenceValueBuilder
.withLocation('.allOf[0].type')
.withValue('string'),
diffResultDifferenceValueBuilder
.withLocation('.allOf[1].type')
.withValue(['string', 'array']),
diffResultDifferenceValueBuilder
.withLocation('.anyOf[0].type')
.withValue('string'),
diffResultDifferenceValueBuilder
.withLocation('.anyOf[1].type')
.withValue(undefined),
diffResultDifferenceValueBuilder
.withLocation('.anyOf[1].not.type')
.withValue('array'),
diffResultDifferenceValueBuilder
.withLocation('.type')
.withValue(undefined)
]);
const addedDifference = baseDifference
.withTypeAddType()
.withValue('string')
.build();
const removedDifference = baseDifference
.withTypeRemoveType()
.withValue('object')
.build();
expect(diffResult).toContainDifferences([addedDifference, removedDifference]);
});
});
});
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