forked from APIDevTools/json-schema-ref-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdereference-callback.spec.ts
51 lines (48 loc) · 1.29 KB
/
dereference-callback.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { describe, it } from "vitest";
import $RefParser from "../../../lib/index.js";
import pathUtils from "../../utils/path.js";
import { expect } from "vitest";
import type { Options } from "../../../lib/options";
describe("Schema with a $ref", () => {
it("should call onDereference", async () => {
const parser = new $RefParser();
const calls: any = [];
const schema = pathUtils.rel("test/specs/dereference-callback/dereference-callback.yaml");
const options = {
dereference: {
onDereference(path, value, parent, parentPropName) {
calls.push({ path, value, parent, parentPropName });
},
},
} as Options;
await parser.dereference(schema, options);
expect(calls).to.deep.equal([
{
path: "#/definitions/b",
value: { $ref: "#/definitions/a" },
parent: {
a: {
$ref: "#/definitions/a",
},
b: {
$ref: "#/definitions/a",
},
},
parentPropName: "a",
},
{
path: "#/definitions/a",
value: { $ref: "#/definitions/a" },
parent: {
c: {
type: "string",
},
d: {
$ref: "#/definitions/a",
},
},
parentPropName: "d",
},
]);
});
});