diff --git a/tests/specs/circular-extended/circular-extended-ancestor.yaml b/tests/specs/circular-extended/circular-extended-ancestor.yaml index 85af25f0..1e6b0609 100644 --- a/tests/specs/circular-extended/circular-extended-ancestor.yaml +++ b/tests/specs/circular-extended/circular-extended-ancestor.yaml @@ -1,32 +1,6 @@ definitions: person: - title: person - properties: - name: - type: string - spouse: - $ref: "#/definitions/person" - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "person". - pet: - $ref: '#/definitions/pet' - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "pet". + $ref: definitions/person-with-spouse.yaml pet: - title: pet - type: object - properties: - name: - type: string - age: - type: number - species: - type: string - enum: - - cat - - dog - - bird - - fish + $ref: definitions/pet.yaml diff --git a/tests/specs/circular-extended/circular-extended-indirect-ancestor.yaml b/tests/specs/circular-extended/circular-extended-indirect-ancestor.yaml index 71d39390..ab476d6b 100644 --- a/tests/specs/circular-extended/circular-extended-indirect-ancestor.yaml +++ b/tests/specs/circular-extended/circular-extended-indirect-ancestor.yaml @@ -1,46 +1,9 @@ definitions: parent: - title: parent - properties: - name: - type: string - child: - $ref: '#/definitions/child' - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "child". + $ref: definitions/parent-with-child.yaml child: - title: child - properties: - name: - type: string - pet: - $ref: '#/definitions/pet' - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "pet". - children: - description: children - type: array - items: - $ref: '#/definitions/child' - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "child". + $ref: definitions/child-with-children.yaml pet: - title: pet - type: object - properties: - name: - type: string - age: - type: number - species: - type: string - enum: - - cat - - dog - - bird - - fish + $ref: definitions/pet.yaml diff --git a/tests/specs/circular-extended/circular-extended-indirect.yaml b/tests/specs/circular-extended/circular-extended-indirect.yaml index bd50ef0f..51bfda63 100644 --- a/tests/specs/circular-extended/circular-extended-indirect.yaml +++ b/tests/specs/circular-extended/circular-extended-indirect.yaml @@ -1,47 +1,9 @@ definitions: parent: - title: parent - properties: - name: - type: string - children: - type: array - items: - $ref: "#/definitions/child" - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "child". + $ref: definitions/parent-with-children.yaml child: - title: child - properties: - name: - type: string - pet: - $ref: '#/definitions/pet' - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "pet". - parents: - type: array - items: - $ref: "#/definitions/parent" - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "parent". + $ref: definitions/child-with-parents.yaml pet: - title: pet - type: object - properties: - name: - type: string - age: - type: number - species: - type: string - enum: - - cat - - dog - - bird - - fish + $ref: definitions/pet.yaml diff --git a/tests/specs/circular-extended/circular-extended-self.yaml b/tests/specs/circular-extended/circular-extended-self.yaml index 5dcc82b7..a00b8893 100644 --- a/tests/specs/circular-extended/circular-extended-self.yaml +++ b/tests/specs/circular-extended/circular-extended-self.yaml @@ -1,8 +1,3 @@ definitions: thing: - title: thing - $ref: "#/definitions/thing" - description: > - This JSON Reference has additional properties (other than $ref). - Normally, this creates a new type that extends the referenced type, - but since this reference points to ITSELF, it doesn't do that. + $ref: "definitions/thing.yaml" diff --git a/tests/specs/circular-extended/circular-extended.bundled.js b/tests/specs/circular-extended/circular-extended.bundled.js new file mode 100644 index 00000000..019599d2 --- /dev/null +++ b/tests/specs/circular-extended/circular-extended.bundled.js @@ -0,0 +1,139 @@ +helper.bundled.circularExtended = +{ + "self": { + "definitions": { + "thing": { + "title": "thing", + "$ref": "#/definitions/thing", + "description": "This JSON Reference has additional properties (other than $ref). Normally, this creates a new type that extends the referenced type, but since this reference points to ITSELF, it doesn't do that.\n", + } + } + }, + + pet: { + "title": "pet", + "type": "object", + "properties": { + "age": { + type: "number" + }, + "name": { + type: "string" + }, + "species": { + "type": "string", + "enum": [ + "cat", + "dog", + "bird", + "fish" + ], + }, + }, + }, + + ancestor: { + "definitions": { + "person": { + "title": "person", + "properties": { + "spouse": { + "$ref": "#/definitions/person", + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"person\".\n", + }, + "pet": { + $ref: "#/definitions/pet", + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n" + }, + "name": { + "type": "string" + } + } + }, + "pet": null + } + }, + + indirect: { + "definitions": { + "parent": { + "title": "parent", + "properties": { + "name": { + "type": "string" + }, + "children": { + "items": { + "$ref": "#/definitions/child", + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", + }, + "type": "array" + } + } + }, + "child": { + "title": "child", + "properties": { + "parents": { + "items": { + "$ref": "#/definitions/parent", + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"parent\".\n", + }, + "type": "array" + }, + "pet": { + "$ref": "#/definitions/pet", + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", + }, + "name": { + "type": "string" + } + } + }, + "pet": null + } + }, + + indirectAncestor: { + "definitions": { + "pet": null, + "parent": { + "title": "parent", + "properties": { + "name": { + "type": "string" + }, + "child": { + "$ref": "#/definitions/child", + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", + } + }, + }, + "child": { + "title": "child", + "properties": { + "pet": { + "$ref": "#/definitions/pet", + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", + }, + "name": { + "type": "string" + }, + "children": { + "items": { + "$ref": "#/definitions/child", + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", + }, + "type": "array", + "description": "children" + } + }, + } + } + } +}; + +helper.bundled.circularExtended.ancestor.definitions.pet = + helper.bundled.circularExtended.indirect.definitions.pet = + helper.bundled.circularExtended.indirectAncestor.definitions.pet = + helper.bundled.circularExtended.pet; diff --git a/tests/specs/circular-extended/circular-extended.dereferenced.js b/tests/specs/circular-extended/circular-extended.dereferenced.js index c1314840..47c648ef 100644 --- a/tests/specs/circular-extended/circular-extended.dereferenced.js +++ b/tests/specs/circular-extended/circular-extended.dereferenced.js @@ -10,6 +10,28 @@ helper.dereferenced.circularExtended = } }, + pet: { + "title": "pet", + "type": "object", + "properties": { + "age": { + type: "number" + }, + "name": { + type: "string" + }, + "species": { + "type": "string", + "enum": [ + "cat", + "dog", + "bird", + "fish" + ], + }, + }, + }, + ancestor: { fullyDereferenced: { "definitions": { @@ -25,78 +47,23 @@ helper.dereferenced.circularExtended = "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", "title": "pet", "type": "object", - "properties": null + "properties": null, }, "name": { "type": "string" } } }, - "pet": { - "type": "object", - "properties": { - "age": { - "type": "number" - }, - "name": { - "type": "string" - }, - "species": { - "enum": [ - "cat", - "dog", - "bird", - "fish" - ], - "type": "string" - } - }, - "title": "pet" - }, + "pet": null } }, ignoreCircular$Refs: { "definitions": { "person": { - "title": "person", - "properties": { - "spouse": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"person\".\n", - "$ref": "#/definitions/person" - }, - "pet": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", - "title": "pet", - "type": "object", - "properties": null - }, - "name": { - "type": "string" - } - } - }, - "pet": { - "type": "object", - "properties": { - "age": { - "type": "number" - }, - "name": { - "type": "string" - }, - "species": { - "enum": [ - "cat", - "dog", - "bird", - "fish" - ], - "type": "string" - } - }, - "title": "pet" + "$ref": "definitions/person-with-spouse.yaml" }, + "pet": null } } }, @@ -135,96 +102,26 @@ helper.dereferenced.circularExtended = "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", "title": "pet", "type": "object", - "properties": null + "properties": null, }, "name": { "type": "string" } } }, - "pet": { - "type": "object", - "properties": { - "age": { - "type": "number" - }, - "name": { - "type": "string" - }, - "species": { - "enum": [ - "cat", - "dog", - "bird", - "fish" - ], - "type": "string" - } - }, - "title": "pet" - }, + "pet": null } }, ignoreCircular$Refs: { "definitions": { "parent": { - "title": "parent", - "properties": { - "name": { - "type": "string" - }, - "children": { - "items": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", - $ref: "#/definitions/child" - }, - "type": "array" - } - } + "$ref": "definitions/parent-with-children.yaml" }, "child": { - "title": "child", - "properties": { - "parents": { - "items": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"parent\".\n", - $ref: "#/definitions/parent" - }, - "type": "array" - }, - "pet": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", - "title": "pet", - "type": "object", - "properties": null - }, - "name": { - "type": "string" - } - } - }, - "pet": { - "type": "object", - "properties": { - "age": { - "type": "number" - }, - "name": { - "type": "string" - }, - "species": { - "enum": [ - "cat", - "dog", - "bird", - "fish" - ], - "type": "string" - } - }, - "title": "pet" + "$ref": "definitions/child-with-parents.yaml" }, + "pet": null } } }, @@ -232,27 +129,7 @@ helper.dereferenced.circularExtended = indirectAncestor: { fullyDereferenced: { "definitions": { - "pet": { - "title": "pet", - "type": "object", - "properties": { - "age": { - "type": "number" - }, - "name": { - "type": "string" - }, - "species": { - "enum": [ - "cat", - "dog", - "bird", - "fish" - ], - "type": "string" - } - }, - }, + "pet": null, "parent": { "title": "parent", "properties": { @@ -273,7 +150,7 @@ helper.dereferenced.circularExtended = "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", "title": "pet", "type": "object", - properties: null + properties: null, }, "name": { "type": "string" @@ -294,74 +171,32 @@ helper.dereferenced.circularExtended = ignoreCircular$Refs: { "definitions": { - "pet": { - "title": "pet", - "type": "object", - "properties": { - "age": { - "type": "number" - }, - "name": { - "type": "string" - }, - "species": { - "enum": [ - "cat", - "dog", - "bird", - "fish" - ], - "type": "string" - } - }, - }, + "pet": null, "parent": { - "title": "parent", - "properties": { - "name": { - "type": "string" - }, - "child": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", - $ref: "#/definitions/child" - } - }, + $ref: "definitions/parent-with-child.yaml" }, "child": { - "title": "child", - "properties": { - "pet": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", - "title": "pet", - "type": "object", - properties: null - }, - "name": { - "type": "string" - }, - "children": { - "items": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", - $ref: "#/definitions/child" - }, - "type": "array", - "description": "children" - } - }, + $ref: "definitions/child-with-children.yaml" } } } } }; - -helper.dereferenced.circularExtended.ancestor.fullyDereferenced.definitions.person.properties.spouse.properties = - helper.dereferenced.circularExtended.ancestor.fullyDereferenced.definitions.person.properties; +helper.dereferenced.circularExtended.ancestor.fullyDereferenced.definitions.pet = + helper.dereferenced.circularExtended.ancestor.ignoreCircular$Refs.definitions.pet = + helper.dereferenced.circularExtended.indirect.fullyDereferenced.definitions.pet = + helper.dereferenced.circularExtended.indirect.ignoreCircular$Refs.definitions.pet = + helper.dereferenced.circularExtended.indirectAncestor.fullyDereferenced.definitions.pet = + helper.dereferenced.circularExtended.indirectAncestor.ignoreCircular$Refs.definitions.pet = + helper.dereferenced.circularExtended.pet; helper.dereferenced.circularExtended.ancestor.fullyDereferenced.definitions.person.properties.pet.properties = + helper.dereferenced.circularExtended.indirect.fullyDereferenced.definitions.child.properties.pet.properties = + helper.dereferenced.circularExtended.indirectAncestor.fullyDereferenced.definitions.child.properties.pet.properties = helper.dereferenced.circularExtended.ancestor.fullyDereferenced.definitions.pet.properties; -helper.dereferenced.circularExtended.ancestor.ignoreCircular$Refs.definitions.person.properties.pet.properties = - helper.dereferenced.circularExtended.ancestor.ignoreCircular$Refs.definitions.pet.properties; +helper.dereferenced.circularExtended.ancestor.fullyDereferenced.definitions.person.properties.spouse.properties = + helper.dereferenced.circularExtended.ancestor.fullyDereferenced.definitions.person.properties; helper.dereferenced.circularExtended.indirect.fullyDereferenced.definitions.parent.properties.children.items.properties = helper.dereferenced.circularExtended.indirect.fullyDereferenced.definitions.child.properties; @@ -369,20 +204,8 @@ helper.dereferenced.circularExtended.indirect.fullyDereferenced.definitions.pare helper.dereferenced.circularExtended.indirect.fullyDereferenced.definitions.child.properties.parents.items.properties = helper.dereferenced.circularExtended.indirect.fullyDereferenced.definitions.parent.properties; -helper.dereferenced.circularExtended.indirect.fullyDereferenced.definitions.child.properties.pet.properties = - helper.dereferenced.circularExtended.indirect.fullyDereferenced.definitions.pet.properties; - -helper.dereferenced.circularExtended.indirect.ignoreCircular$Refs.definitions.child.properties.pet.properties = - helper.dereferenced.circularExtended.indirect.ignoreCircular$Refs.definitions.pet.properties; - helper.dereferenced.circularExtended.indirectAncestor.fullyDereferenced.definitions.parent.properties.child.properties = helper.dereferenced.circularExtended.indirectAncestor.fullyDereferenced.definitions.child.properties; helper.dereferenced.circularExtended.indirectAncestor.fullyDereferenced.definitions.child.properties.children.items.properties = helper.dereferenced.circularExtended.indirectAncestor.fullyDereferenced.definitions.child.properties; - -helper.dereferenced.circularExtended.indirectAncestor.fullyDereferenced.definitions.child.properties.pet.properties = - helper.dereferenced.circularExtended.indirectAncestor.fullyDereferenced.definitions.pet.properties; - -helper.dereferenced.circularExtended.indirectAncestor.ignoreCircular$Refs.definitions.child.properties.pet.properties = - helper.dereferenced.circularExtended.indirectAncestor.ignoreCircular$Refs.definitions.pet.properties; diff --git a/tests/specs/circular-extended/circular-extended.parsed.js b/tests/specs/circular-extended/circular-extended.parsed.js index bcd32c97..43233526 100644 --- a/tests/specs/circular-extended/circular-extended.parsed.js +++ b/tests/specs/circular-extended/circular-extended.parsed.js @@ -3,32 +3,60 @@ helper.parsed.circularExtended = "self": { "definitions": { "thing": { - "title": "thing", - "$ref": "#/definitions/thing", - "description": "This JSON Reference has additional properties (other than $ref). Normally, this creates a new type that extends the referenced type, but since this reference points to ITSELF, it doesn't do that.\n", + "$ref": "definitions/thing.yaml" } } }, + "thing": { + "title": "thing", + "$ref": "thing.yaml", + "description": "This JSON Reference has additional properties (other than $ref). Normally, this creates a new type that extends the referenced type, but since this reference points to ITSELF, it doesn't do that.\n", + }, + ancestor: { "definitions": { "person": { - "title": "person", - "properties": { - "spouse": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"person\".\n", - "$ref": "#/definitions/person" - }, - "pet": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", - "$ref": "#/definitions/pet" - }, - "name": { - "type": "string" - } - } + "$ref": "definitions/person-with-spouse.yaml" + }, + "pet": { + "$ref": "definitions/pet.yaml" + } + } + }, + + "personWithSpouse": { + "title": "person", + "properties": { + "spouse": { + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"person\".\n", + "$ref": "person-with-spouse.yaml" }, "pet": { + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", + "$ref": "pet.yaml" + }, + "name": { + "type": "string" + } + } + }, + + "animals": { + "definitions": { + "fish": { + "title": "fish", + "$ref": "#/definitions/animal" + }, + "cat": { + "title": "cat", + "$ref": "#/definitions/animal" + }, + "bird": { + "title": "bird", + "$ref": "#/definitions/animal" + }, + "animal": { "type": "object", "properties": { "age": { @@ -36,137 +64,136 @@ helper.parsed.circularExtended = }, "name": { "type": "string" - }, - "species": { - "enum": [ - "cat", - "dog", - "bird", - "fish" - ], - "type": "string" } }, - "title": "pet" + "title": "animal" }, + "dog": { + "title": "dog", + "$ref": "#/definitions/animal" + } } }, + "pet": { + "title": "pet", + "type": { + "$ref": "animals.yaml#/definitions/cat/type" + }, + "properties": { + "age": { + "$ref": "animals.yaml#/definitions/bird/properties/age" + }, + "name": { + "$ref": "animals.yaml#/definitions/dog/properties/name" + }, + "species": { + "type": "string", + "enum": [ + "cat", + "dog", + "bird", + "fish" + ], + }, + }, + }, + indirect: { "definitions": { "parent": { - "title": "parent", - "properties": { - "name": { - "type": "string" - }, - "children": { - "items": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", - "$ref": "#/definitions/child" - }, - "type": "array" - } - } + "$ref": "definitions/parent-with-children.yaml" }, "child": { - "title": "child", - "properties": { - "parents": { - "items": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"parent\".\n", - "$ref": "#/definitions/parent" - }, - "type": "array" - }, - "pet": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", - "$ref": "#/definitions/pet" - }, - "name": { - "type": "string" - } - } + $ref: "definitions/child-with-parents.yaml" }, "pet": { - "type": "object", - "properties": { - "age": { - "type": "number" - }, - "name": { - "type": "string" - }, - "species": { - "enum": [ - "cat", - "dog", - "bird", - "fish" - ], - "type": "string" - } + $ref: "definitions/pet.yaml" + } + } + }, + + "parentWithChildren": { + "title": "parent", + "properties": { + "name": { + "type": "string" + }, + "children": { + "items": { + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", + "$ref": "child-with-parents.yaml" }, - "title": "pet" + "type": "array" + } + } + }, + + "childWithParents": { + "title": "child", + "properties": { + "parents": { + "items": { + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"parent\".\n", + "$ref": "parent-with-children.yaml" + }, + "type": "array" + }, + "pet": { + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", + "$ref": "pet.yaml" }, + "name": { + "type": "string" + } } }, indirectAncestor: { "definitions": { "pet": { - "type": "object", - "properties": { - "age": { - "type": "number" - }, - "name": { - "type": "string" - }, - "species": { - "enum": [ - "cat", - "dog", - "bird", - "fish" - ], - "type": "string" - } - }, - "title": "pet" + "$ref": "definitions/pet.yaml" }, "parent": { - "properties": { - "name": { - "type": "string" - }, - "child": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", - "$ref": "#/definitions/child" - } - }, - "title": "parent" + "$ref": "definitions/parent-with-child.yaml" }, "child": { - "properties": { - "pet": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", - "$ref": "#/definitions/pet" - }, - "name": { - "type": "string" - }, - "children": { - "items": { - "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", - "$ref": "#/definitions/child" - }, - "type": "array", - "description": "children" - } - }, - "title": "child" + "$ref": "definitions/child-with-children.yaml" } } + }, + + "parentWithChild": { + "title": "parent", + "properties": { + "name": { + "type": "string" + }, + "child": { + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", + "$ref": "child-with-children.yaml" + } + }, + }, + + "childWithChildren": { + "title": "child", + "properties": { + "pet": { + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"pet\".\n", + "$ref": "pet.yaml" + }, + "name": { + "type": "string" + }, + "children": { + "items": { + "description": "This JSON Reference has additional properties (other than $ref). This creates a new type that extends \"child\".\n", + "$ref": "child-with-children.yaml" + }, + "type": "array", + "description": "children" + } + }, } }; diff --git a/tests/specs/circular-extended/circular-extended.spec.js b/tests/specs/circular-extended/circular-extended.spec.js index 2e6db6bb..2205e699 100644 --- a/tests/specs/circular-extended/circular-extended.spec.js +++ b/tests/specs/circular-extended/circular-extended.spec.js @@ -19,7 +19,8 @@ describe('Schema with circular $refs that extend each other', function() { it('should resolve successfully', helper.testResolve( path.rel('specs/circular-extended/circular-extended-self.yaml'), - path.abs('specs/circular-extended/circular-extended-self.yaml'), helper.parsed.circularExtended.self + path.abs('specs/circular-extended/circular-extended-self.yaml'), helper.parsed.circularExtended.self, + path.abs('specs/circular-extended/definitions/thing.yaml'), helper.parsed.circularExtended.thing )); it('should dereference successfully', function() { @@ -70,7 +71,7 @@ describe('Schema with circular $refs that extend each other', function() { .bundle(path.rel('specs/circular-extended/circular-extended-self.yaml')) .then(function(schema) { expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(helper.parsed.circularExtended.self); + expect(schema).to.deep.equal(helper.bundled.circularExtended.self); // The "circular" flag should NOT be set // (it only gets set by `dereference`) @@ -97,7 +98,10 @@ describe('Schema with circular $refs that extend each other', function() { it('should resolve successfully', helper.testResolve( path.rel('specs/circular-extended/circular-extended-ancestor.yaml'), - path.abs('specs/circular-extended/circular-extended-ancestor.yaml'), helper.parsed.circularExtended.ancestor + path.abs('specs/circular-extended/circular-extended-ancestor.yaml'), helper.parsed.circularExtended.ancestor, + path.abs('specs/circular-extended/definitions/person-with-spouse.yaml'), helper.parsed.circularExtended.personWithSpouse, + path.abs('specs/circular-extended/definitions/pet.yaml'), helper.parsed.circularExtended.pet, + path.abs('specs/circular-extended/definitions/animals.yaml'), helper.parsed.circularExtended.animals )); it('should dereference successfully', function() { @@ -129,9 +133,6 @@ describe('Schema with circular $refs that extend each other', function() { // The "circular" flag should be set expect(parser.$refs.circular).to.equal(true); - - // Reference equality - expect(schema.definitions.person.properties.pet.properties).to.equal(schema.definitions.pet.properties); }); }); @@ -144,7 +145,7 @@ describe('Schema with circular $refs that extend each other', function() { // A ReferenceError should have been thrown expect(err).to.be.an.instanceOf(ReferenceError); expect(err.message).to.contain('Circular $ref pointer found at '); - expect(err.message).to.contain('specs/circular-extended/circular-extended-ancestor.yaml#/definitions/person/properties/spouse'); + expect(err.message).to.contain('specs/circular-extended/definitions/person-with-spouse.yaml#/properties/spouse'); // $Refs.circular should be true expect(parser.$refs.circular).to.equal(true); @@ -157,7 +158,7 @@ describe('Schema with circular $refs that extend each other', function() { .bundle(path.rel('specs/circular-extended/circular-extended-ancestor.yaml')) .then(function(schema) { expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(helper.parsed.circularExtended.ancestor); + expect(schema).to.deep.equal(helper.bundled.circularExtended.ancestor); // The "circular" flag should NOT be set // (it only gets set by `dereference`) @@ -184,7 +185,11 @@ describe('Schema with circular $refs that extend each other', function() { it('should resolve successfully', helper.testResolve( path.rel('specs/circular-extended/circular-extended-indirect.yaml'), - path.abs('specs/circular-extended/circular-extended-indirect.yaml'), helper.parsed.circularExtended.indirect + path.abs('specs/circular-extended/circular-extended-indirect.yaml'), helper.parsed.circularExtended.indirect, + path.abs('specs/circular-extended/definitions/parent-with-children.yaml'), helper.parsed.circularExtended.parentWithChildren, + path.abs('specs/circular-extended/definitions/child-with-parents.yaml'), helper.parsed.circularExtended.childWithParents, + path.abs('specs/circular-extended/definitions/pet.yaml'), helper.parsed.circularExtended.pet, + path.abs('specs/circular-extended/definitions/animals.yaml'), helper.parsed.circularExtended.animals )); it('should dereference successfully', function() { @@ -218,9 +223,6 @@ describe('Schema with circular $refs that extend each other', function() { // The "circular" flag should be set expect(parser.$refs.circular).to.equal(true); - - // Reference equality - expect(schema.definitions.child.properties.pet.properties).to.equal(schema.definitions.pet.properties); }); }); @@ -233,7 +235,7 @@ describe('Schema with circular $refs that extend each other', function() { // A ReferenceError should have been thrown expect(err).to.be.an.instanceOf(ReferenceError); expect(err.message).to.contain('Circular $ref pointer found at '); - expect(err.message).to.contain('specs/circular-extended/circular-extended-indirect.yaml#/definitions/child/properties/parents/items'); + expect(err.message).to.contain('specs/circular-extended/definitions/child-with-parents.yaml#/properties/parents/items'); // $Refs.circular should be true expect(parser.$refs.circular).to.equal(true); @@ -246,7 +248,7 @@ describe('Schema with circular $refs that extend each other', function() { .bundle(path.rel('specs/circular-extended/circular-extended-indirect.yaml')) .then(function(schema) { expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(helper.parsed.circularExtended.indirect); + expect(schema).to.deep.equal(helper.bundled.circularExtended.indirect); // The "circular" flag should NOT be set // (it only gets set by `dereference`) @@ -273,7 +275,11 @@ describe('Schema with circular $refs that extend each other', function() { it('should resolve successfully', helper.testResolve( path.rel('specs/circular-extended/circular-extended-indirect-ancestor.yaml'), - path.abs('specs/circular-extended/circular-extended-indirect-ancestor.yaml'), helper.parsed.circularExtended.indirectAncestor + path.abs('specs/circular-extended/circular-extended-indirect-ancestor.yaml'), helper.parsed.circularExtended.indirectAncestor, + path.abs('specs/circular-extended/definitions/parent-with-child.yaml'), helper.parsed.circularExtended.parentWithChild, + path.abs('specs/circular-extended/definitions/child-with-children.yaml'), helper.parsed.circularExtended.childWithChildren, + path.abs('specs/circular-extended/definitions/pet.yaml'), helper.parsed.circularExtended.pet, + path.abs('specs/circular-extended/definitions/animals.yaml'), helper.parsed.circularExtended.animals )); it('should dereference successfully', function() { @@ -307,9 +313,6 @@ describe('Schema with circular $refs that extend each other', function() { // The "circular" flag should be set expect(parser.$refs.circular).to.equal(true); - - // Reference equality - expect(schema.definitions.pet.properties).to.equal(schema.definitions.child.properties.pet.properties); }); }); @@ -322,7 +325,7 @@ describe('Schema with circular $refs that extend each other', function() { // A ReferenceError should have been thrown expect(err).to.be.an.instanceOf(ReferenceError); expect(err.message).to.contain('Circular $ref pointer found at '); - expect(err.message).to.contain('specs/circular-extended/circular-extended-indirect-ancestor.yaml#/definitions/child/properties'); + expect(err.message).to.contain('specs/circular-extended/definitions/child-with-children.yaml#/properties'); // $Refs.circular should be true expect(parser.$refs.circular).to.equal(true); @@ -335,7 +338,7 @@ describe('Schema with circular $refs that extend each other', function() { .bundle(path.rel('specs/circular-extended/circular-extended-indirect-ancestor.yaml')) .then(function(schema) { expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(helper.parsed.circularExtended.indirectAncestor); + expect(schema).to.deep.equal(helper.bundled.circularExtended.indirectAncestor); // The "circular" flag should NOT be set // (it only gets set by `dereference`) diff --git a/tests/specs/circular-extended/definitions/animals.yaml b/tests/specs/circular-extended/definitions/animals.yaml new file mode 100644 index 00000000..d7f858ae --- /dev/null +++ b/tests/specs/circular-extended/definitions/animals.yaml @@ -0,0 +1,25 @@ +definitions: + animal: + title: animal + type: object + properties: + name: + type: string + age: + type: number + + cat: + title: cat + $ref: "#/definitions/animal" + + dog: + title: dog + $ref: "#/definitions/animal" + + bird: + title: bird + $ref: "#/definitions/animal" + + fish: + title: fish + $ref: "#/definitions/animal" diff --git a/tests/specs/circular-extended/definitions/child-with-children.yaml b/tests/specs/circular-extended/definitions/child-with-children.yaml new file mode 100644 index 00000000..c1814846 --- /dev/null +++ b/tests/specs/circular-extended/definitions/child-with-children.yaml @@ -0,0 +1,17 @@ +title: child +properties: + name: + type: string + pet: + $ref: pet.yaml + description: > + This JSON Reference has additional properties (other than $ref). + This creates a new type that extends "pet". + children: + description: children + type: array + items: + $ref: child-with-children.yaml + description: > + This JSON Reference has additional properties (other than $ref). + This creates a new type that extends "child". diff --git a/tests/specs/circular-extended/definitions/child-with-parents.yaml b/tests/specs/circular-extended/definitions/child-with-parents.yaml new file mode 100644 index 00000000..3c6ac6b3 --- /dev/null +++ b/tests/specs/circular-extended/definitions/child-with-parents.yaml @@ -0,0 +1,16 @@ +title: child +properties: + name: + type: string + pet: + $ref: pet.yaml + description: > + This JSON Reference has additional properties (other than $ref). + This creates a new type that extends "pet". + parents: + type: array + items: + $ref: parent-with-children.yaml + description: > + This JSON Reference has additional properties (other than $ref). + This creates a new type that extends "parent". diff --git a/tests/specs/circular-extended/definitions/parent-with-child.yaml b/tests/specs/circular-extended/definitions/parent-with-child.yaml new file mode 100644 index 00000000..ef69fc42 --- /dev/null +++ b/tests/specs/circular-extended/definitions/parent-with-child.yaml @@ -0,0 +1,9 @@ +title: parent +properties: + name: + type: string + child: + $ref: child-with-children.yaml + description: > + This JSON Reference has additional properties (other than $ref). + This creates a new type that extends "child". diff --git a/tests/specs/circular-extended/definitions/parent-with-children.yaml b/tests/specs/circular-extended/definitions/parent-with-children.yaml new file mode 100644 index 00000000..b71a5366 --- /dev/null +++ b/tests/specs/circular-extended/definitions/parent-with-children.yaml @@ -0,0 +1,11 @@ +title: parent +properties: + name: + type: string + children: + type: array + items: + $ref: child-with-parents.yaml + description: > + This JSON Reference has additional properties (other than $ref). + This creates a new type that extends "child". diff --git a/tests/specs/circular-extended/definitions/person-with-spouse.yaml b/tests/specs/circular-extended/definitions/person-with-spouse.yaml new file mode 100644 index 00000000..f1a0842b --- /dev/null +++ b/tests/specs/circular-extended/definitions/person-with-spouse.yaml @@ -0,0 +1,14 @@ +title: person +properties: + name: + type: string + spouse: + $ref: person-with-spouse.yaml + description: > + This JSON Reference has additional properties (other than $ref). + This creates a new type that extends "person". + pet: + $ref: pet.yaml + description: > + This JSON Reference has additional properties (other than $ref). + This creates a new type that extends "pet". diff --git a/tests/specs/circular-extended/definitions/pet.yaml b/tests/specs/circular-extended/definitions/pet.yaml new file mode 100644 index 00000000..16565ecf --- /dev/null +++ b/tests/specs/circular-extended/definitions/pet.yaml @@ -0,0 +1,15 @@ +title: pet +type: + $ref: "animals.yaml#/definitions/cat/type" # <-- deep linking into an extended object +properties: + name: + $ref: "animals.yaml#/definitions/dog/properties/name" # <-- deep linking into an extended object + age: + $ref: "animals.yaml#/definitions/bird/properties/age" # <-- deep linking into an extended object + species: + type: string + enum: + - cat + - dog + - bird + - fish diff --git a/tests/specs/circular-extended/definitions/thing.yaml b/tests/specs/circular-extended/definitions/thing.yaml new file mode 100644 index 00000000..f0d96b6b --- /dev/null +++ b/tests/specs/circular-extended/definitions/thing.yaml @@ -0,0 +1,6 @@ +title: thing +$ref: thing.yaml +description: > + This JSON Reference has additional properties (other than $ref). + Normally, this creates a new type that extends the referenced type, + but since this reference points to ITSELF, it doesn't do that.