Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/dereference.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
37 changes: 37 additions & 0 deletions test/specs/root-internal/bundled.js
Original file line number Diff line number Diff line change
@@ -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"
}
},
};
37 changes: 37 additions & 0 deletions test/specs/root-internal/dereferenced.js
Original file line number Diff line number Diff line change
@@ -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"
}
},
};
26 changes: 26 additions & 0 deletions test/specs/root-internal/parsed.js
Original file line number Diff line number Diff line change
@@ -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"
}
};
42 changes: 42 additions & 0 deletions test/specs/root-internal/root-internal.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
13 changes: 13 additions & 0 deletions test/specs/root-internal/root-internal.yaml
Original file line number Diff line number Diff line change
@@ -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"