forked from APIDevTools/json-schema-ref-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle-callback.spec.ts
More file actions
75 lines (72 loc) · 1.8 KB
/
bundle-callback.spec.ts
File metadata and controls
75 lines (72 loc) · 1.8 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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 onBundle", async () => {
const parser = new $RefParser();
const calls: any = [];
const schema = pathUtils.rel("test/specs/bundle-callback/bundle-callback.yaml");
const options = {
bundle: {
onBundle(path, value, parent, parentPropName) {
calls.push({ path, value, parent, parentPropName });
},
},
} as Options;
await parser.bundle(schema, options);
expect(calls).to.deep.equal([
{
path: "#/definitions/a",
value: { $ref: "#/definitions/b" },
parent: {
a: {
$ref: "#/definitions/a",
},
b: {
$ref: "#/definitions/b",
},
},
parentPropName: "a",
},
{
path: "#/definitions/a",
value: { $ref: "#/definitions/apath: "#/definitions/b",
value: { $ref: "#/definitions/b" },
parent: {
a: {
$ref: "#/definitions/b",
},
b: {
$ref: "#/definitions/a",
},
},
parentPropName: "a",
}," },
parent: {
a: {
$ref: "#/definitions/b",
},
b: {
$ref: "#/definitions/a",
},
},
parentPropName: "b",
},
{
path: "#/definitions/a",
value: { $ref: "#/definitions/a" },
parent: {
c: {
type: "string",
},
d: {
$ref: "#/definitions/a",
},
},
parentPropName: "d",
},
]);
});
});