-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve root level references (#329)
Co-authored-by: JonLuca De Caro <[email protected]>
- Loading branch information
Showing
6 changed files
with
113 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default { | ||
$ref: "#/definitions/user", | ||
definitions: { | ||
user: { | ||
properties: { | ||
userId: { | ||
type: "integer", | ||
}, | ||
}, | ||
required: ["userId"], | ||
type: "object", | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export default { | ||
definitions: { | ||
user: { | ||
type: "object", | ||
properties: { | ||
userId: { | ||
type: "integer", | ||
}, | ||
}, | ||
required: ["userId"], | ||
}, | ||
}, | ||
type: "object", | ||
properties: { | ||
userId: { | ||
type: "integer", | ||
}, | ||
}, | ||
required: ["userId"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { describe, it } from "vitest"; | ||
import $RefParser from "../../../lib/index.js"; | ||
import helper from "../../utils/helper.js"; | ||
import path from "../../utils/path.js"; | ||
import parsedSchema from "./parsed.js"; | ||
import dereferencedSchema from "./dereferenced.js"; | ||
import bundledSchema from "./bundled.js"; | ||
|
||
import { expect } from "vitest"; | ||
|
||
describe("Schema with $ref at root level", () => { | ||
it("should parse successfully", async () => { | ||
const parser = new $RefParser(); | ||
const schema = await parser.parse(path.rel("test/specs/internal-root-ref/internal-root-ref.yaml")); | ||
expect(schema).to.equal(parser.schema); | ||
expect(schema).to.deep.equal(parsedSchema); | ||
expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/internal-root-ref/internal-root-ref.yaml")]); | ||
}); | ||
|
||
it( | ||
"should resolve successfully", | ||
helper.testResolve( | ||
path.rel("test/specs/internal-root-ref/internal-root-ref.yaml"), | ||
path.abs("test/specs/internal-root-ref/internal-root-ref.yaml"), | ||
parsedSchema, | ||
), | ||
); | ||
|
||
it("should dereference successfully", async () => { | ||
const parser = new $RefParser(); | ||
const schema = await parser.dereference(path.rel("test/specs/internal-root-ref/internal-root-ref.yaml")); | ||
expect(schema).to.equal(parser.schema); | ||
expect(schema).to.deep.equal(dereferencedSchema); | ||
// Reference equality | ||
// @ts-expect-error TS(2532): Object is possibly 'undefined'. | ||
expect(schema.properties.userId).to.equal(schema.definitions.user.properties.userId); | ||
expect(parser.$refs.circular).to.equal(false); | ||
}); | ||
|
||
it("should bundle successfully", async () => { | ||
const parser = new $RefParser(); | ||
const schema = await parser.bundle(path.rel("test/specs/internal-root-ref/internal-root-ref.yaml")); | ||
expect(schema).to.equal(parser.schema); | ||
expect(schema).to.deep.equal(bundledSchema); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
$ref: "#/definitions/user" | ||
definitions: | ||
user: | ||
type: object | ||
properties: | ||
userId: | ||
type: integer | ||
required: | ||
- userId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default { | ||
$ref: "#/definitions/user", | ||
definitions: { | ||
user: { | ||
properties: { | ||
userId: { | ||
type: "integer", | ||
}, | ||
}, | ||
required: ["userId"], | ||
type: "object", | ||
}, | ||
}, | ||
}; |