diff --git a/lib/dereference.js b/lib/dereference.js index 0a4c919a..4d0b6ce7 100644 --- a/lib/dereference.js +++ b/lib/dereference.js @@ -129,7 +129,6 @@ function dereference$Ref ($ref, path, pathFromRoot, parents, processedObjects, d return cache; } - let pointer = $refs._resolve($refPath, path, options); if (pointer === null) { diff --git a/test/specs/root-internal/bundled.js b/test/specs/root-internal/bundled.js new file mode 100644 index 00000000..c39f781f --- /dev/null +++ b/test/specs/root-internal/bundled.js @@ -0,0 +1,37 @@ +"use strict"; + +module.exports = +{ + definitions: { + name: { + title: "name", + required: [ + "first", + "last" + ], + type: "object", + properties: { + last: { + type: "string" + }, + first: { + type: "string" + } + }, + } + }, + title: "name", + required: [ + "first", + "last" + ], + type: "object", + properties: { + last: { + type: "string" + }, + first: { + type: "string" + } + }, +}; diff --git a/test/specs/root-internal/dereferenced.js b/test/specs/root-internal/dereferenced.js new file mode 100644 index 00000000..c39f781f --- /dev/null +++ b/test/specs/root-internal/dereferenced.js @@ -0,0 +1,37 @@ +"use strict"; + +module.exports = +{ + definitions: { + name: { + title: "name", + required: [ + "first", + "last" + ], + type: "object", + properties: { + last: { + type: "string" + }, + first: { + type: "string" + } + }, + } + }, + title: "name", + required: [ + "first", + "last" + ], + type: "object", + properties: { + last: { + type: "string" + }, + first: { + type: "string" + } + }, +}; diff --git a/test/specs/root-internal/parsed.js b/test/specs/root-internal/parsed.js new file mode 100644 index 00000000..71e197a7 --- /dev/null +++ b/test/specs/root-internal/parsed.js @@ -0,0 +1,26 @@ +"use strict"; + +module.exports = +{ + schema: { + definitions: { + name: { + title: "name", + required: [ + "first", + "last" + ], + type: "object", + properties: { + last: { + $ref: "#/definitions/name/properties/first" + }, + first: { + type: "string" + } + }, + } + }, + $ref: "#/definitions/name" + } +}; diff --git a/test/specs/root-internal/root-internal.spec.js b/test/specs/root-internal/root-internal.spec.js new file mode 100644 index 00000000..a3ce9888 --- /dev/null +++ b/test/specs/root-internal/root-internal.spec.js @@ -0,0 +1,42 @@ +"use strict"; + +const { expect } = require("chai"); +const $RefParser = require("../../.."); +const helper = require("../../utils/helper"); +const path = require("../../utils/path"); +const parsedSchema = require("./parsed"); +const dereferencedSchema = require("./dereferenced"); +const bundledSchema = require("./bundled"); + +describe("Schema with a top-level internal (root) $ref", () => { + it("should parse successfully", async () => { + let parser = new $RefParser(); + const schema = await parser.parse(path.rel("specs/root-internal/root-internal.yaml")); + expect(schema).to.equal(parser.schema); + expect(schema).to.deep.equal(parsedSchema.schema); + expect(parser.$refs.paths()).to.deep.equal([path.abs("specs/root-internal/root-internal.yaml")]); + }); + + it("should resolve successfully", helper.testResolve( + path.rel("specs/root-internal/root-internal.yaml"), + path.abs("specs/root-internal/root-internal.yaml"), parsedSchema.schema + )); + + it("should dereference successfully", async () => { + let parser = new $RefParser(); + const schema = await parser.dereference(path.rel("specs/root-internal/root-internal.yaml")); + expect(schema).to.equal(parser.schema); + expect(schema).to.deep.equal(dereferencedSchema); + // Reference equality + expect(schema.properties.first).to.equal(schema.properties.last); + // The "circular" flag should NOT be set + expect(parser.$refs.circular).to.equal(false); + }); + + it("should bundle successfully", async () => { + let parser = new $RefParser(); + const schema = await parser.bundle(path.rel("specs/root-internal/root-internal.yaml")); + expect(schema).to.equal(parser.schema); + expect(schema).to.deep.equal(bundledSchema); + }); +}); diff --git a/test/specs/root-internal/root-internal.yaml b/test/specs/root-internal/root-internal.yaml new file mode 100644 index 00000000..b654e9e2 --- /dev/null +++ b/test/specs/root-internal/root-internal.yaml @@ -0,0 +1,13 @@ +definitions: + name: + title: name + type: object + required: + - first + - last + properties: + first: + type: string + last: + $ref: "#/definitions/name/properties/first" +$ref: "#/definitions/name" \ No newline at end of file