Skip to content

Commit 499a8cc

Browse files
authored
fix: bug introduced in v9.0.2 (#284)
* Fixed a bug introduced by 9.0.2 4e0123f Because of that external schema are not mapped correctly (re-crawl was not executed) and the $ref was pointing out to a wrong path: "#/paths/~1test~1add-test/post/requestBody/content/application~1json/schema/properties/test2/properties/test3/properties/test5/items/properties/test5A/properties/test6/items" instead of "$ref": "#/components/schemas/Common.Test3/properties/test5/items/properties/test5A/properties/test6/items". (deep-external test contains a main file, a shared file and expected result) * added new line at the end of yaml files; main and shared yaml files are moved into a folder; * Fixed the path for Shared.yaml file (it was lower letter instead of capital letter)
1 parent 41ffc9a commit 499a8cc

File tree

8 files changed

+359
-1
lines changed

8 files changed

+359
-1
lines changed

lib/bundle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function inventory$Ref ($refParent, $refKey, path, pathFromRoot, indirections, i
135135
});
136136

137137
// Recursively crawl the resolved value
138-
if (!existingEntry) {
138+
if (!existingEntry || external) {
139139
crawl(pointer.value, null, pointer.path, pathFromRoot, indirections + 1, inventory, $refs, options);
140140
}
141141
}

test/specs/deep-external/bundled.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"use strict";
2+
3+
module.exports =
4+
{
5+
info: {
6+
title: "Main"
7+
},
8+
paths: {
9+
"/test/add-test": {
10+
post: {
11+
requestBody: {
12+
content: {
13+
"application/json": {
14+
schema: {
15+
$ref: "#/components/schemas/Test1"
16+
}
17+
}
18+
}
19+
},
20+
responses: {
21+
204: {
22+
description: "No Content",
23+
}
24+
}
25+
}
26+
}
27+
},
28+
components: {
29+
schemas: {
30+
"Common.Test3": {
31+
properties: {
32+
test5: {
33+
items: {
34+
properties: {
35+
test5A: {
36+
properties: {
37+
test6: {
38+
items: {
39+
properties: {
40+
type: {
41+
enum: [
42+
"VALUE1",
43+
"VALUE2",
44+
"VALUE3"
45+
]
46+
},
47+
value: {
48+
format: "double",
49+
type: "number"
50+
}
51+
}
52+
}
53+
}
54+
}
55+
},
56+
test5B: {
57+
properties: {
58+
test6: {
59+
items: {
60+
$ref: "#/components/schemas/Common.Test3/properties/test5/items/properties/test5A/properties/test6/items"
61+
}
62+
}
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
},
70+
Test1: {
71+
properties: {
72+
test2: {
73+
$ref: "#/components/schemas/Test2"
74+
}
75+
}
76+
},
77+
Test2: {
78+
properties: {
79+
test3: {
80+
$ref: "#/components/schemas/Common.Test3"
81+
}
82+
}
83+
}
84+
}
85+
}
86+
};

test/specs/deep-external/deep.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
3+
const { expect } = require("chai");
4+
const $RefParser = require("../../..");
5+
const path = require("../../utils/path");
6+
const bundledSchema = require("./bundled");
7+
8+
9+
describe("Schema with deeply-nested external $refs", () => {
10+
it("should bundle successfully", async () => {
11+
let parser = new $RefParser();
12+
const schema = await parser.bundle(path.rel("specs/deep-external/definitions/Main-spec.yaml"));
13+
expect(schema).to.equal(parser.schema);
14+
expect(schema).to.deep.equal(bundledSchema);
15+
});
16+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
info:
2+
title: Main
3+
paths:
4+
/test/add-test:
5+
post:
6+
requestBody:
7+
content:
8+
application/json:
9+
schema:
10+
$ref: "#/components/schemas/Test1"
11+
responses:
12+
'204':
13+
description: No Content
14+
15+
components:
16+
schemas:
17+
Test1:
18+
properties:
19+
test2:
20+
$ref: "#/components/schemas/Test2"
21+
Test2:
22+
properties:
23+
test3:
24+
$ref: '#/components/schemas/Common.Test3'
25+
Common.Test3:
26+
$ref: '../definitions/Shared.yaml#/components/schemas/Test4'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
info:
2+
title: Shared
3+
4+
components:
5+
schemas:
6+
7+
Test4:
8+
properties:
9+
test5:
10+
items:
11+
$ref: '#/components/schemas/Test5'
12+
13+
Test5:
14+
properties:
15+
test5A:
16+
$ref: '#/components/schemas/Test5A'
17+
test5B:
18+
$ref: '#/components/schemas/Test5B'
19+
20+
Test5A:
21+
properties:
22+
test6:
23+
items:
24+
$ref: '#/components/schemas/Test6'
25+
26+
Test5B:
27+
properties:
28+
test6:
29+
items:
30+
$ref: '#/components/schemas/Test6'
31+
32+
Test6:
33+
properties:
34+
type:
35+
$ref: '#/components/schemas/Test7Type'
36+
value:
37+
format: double
38+
type: number
39+
40+
Test7Type:
41+
enum:
42+
- VALUE1
43+
- VALUE2
44+
- VALUE3
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
info:
2+
title: Main
3+
paths:
4+
/test/add-test:
5+
post:
6+
requestBody:
7+
content:
8+
application/json:
9+
schema:
10+
$ref: "#/components/schemas/Test1"
11+
responses:
12+
'204':
13+
description: No Content
14+
15+
components:
16+
schemas:
17+
Test1:
18+
properties:
19+
test2:
20+
$ref: "#/components/schemas/Test2"
21+
22+
Test2:
23+
properties:
24+
test3:
25+
$ref: '#/components/schemas/Common.Test3'
26+
27+
Common.Test3:
28+
$ref: '#/components/schemas/Test4'
29+
30+
Test4:
31+
properties:
32+
test5:
33+
items:
34+
$ref: '#/components/schemas/Test5'
35+
36+
Test5:
37+
properties:
38+
test5A:
39+
$ref: '#/components/schemas/Test5A'
40+
test5B:
41+
$ref: '#/components/schemas/Test5B'
42+
43+
Test5A:
44+
properties:
45+
test6:
46+
items:
47+
$ref: '#/components/schemas/Test6'
48+
49+
Test5B:
50+
properties:
51+
test6:
52+
items:
53+
$ref: '#/components/schemas/Test6'
54+
55+
Test6:
56+
properties:
57+
type:
58+
$ref: '#/components/schemas/Test7Type'
59+
value:
60+
format: double
61+
type: number
62+
63+
Test7Type:
64+
enum:
65+
- VALUE1
66+
- VALUE2
67+
- VALUE3

test/specs/deep-internal/bundled.js

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
"use strict";
2+
3+
module.exports =
4+
{
5+
info: {
6+
title: "Main"
7+
},
8+
paths: {
9+
"/test/add-test": {
10+
post: {
11+
requestBody: {
12+
content: {
13+
"application/json": {
14+
schema: {
15+
$ref: "#/components/schemas/Test1"
16+
}
17+
}
18+
}
19+
},
20+
responses: {
21+
204: {
22+
description: "No Content",
23+
}
24+
}
25+
}
26+
}
27+
},
28+
components: {
29+
schemas: {
30+
"Common.Test3": {
31+
$ref: "#/components/schemas/Test4"
32+
},
33+
Test1: {
34+
properties: {
35+
test2: {
36+
$ref: "#/components/schemas/Test2"
37+
}
38+
}
39+
},
40+
Test2: {
41+
properties: {
42+
test3: {
43+
$ref: "#/components/schemas/Test4"
44+
}
45+
}
46+
},
47+
Test4: {
48+
properties: {
49+
test5: {
50+
items: {
51+
$ref: "#/components/schemas/Test5"
52+
}
53+
}
54+
}
55+
},
56+
Test5: {
57+
properties: {
58+
test5A: {
59+
$ref: "#/components/schemas/Test5A"
60+
},
61+
test5B: {
62+
$ref: "#/components/schemas/Test5B"
63+
}
64+
}
65+
},
66+
Test5A: {
67+
properties: {
68+
test6: {
69+
items: {
70+
$ref: "#/components/schemas/Test6"
71+
}
72+
}
73+
}
74+
},
75+
Test5B: {
76+
properties: {
77+
test6: {
78+
items: {
79+
$ref: "#/components/schemas/Test6"
80+
}
81+
}
82+
}
83+
},
84+
Test6: {
85+
properties: {
86+
type: {
87+
$ref: "#/components/schemas/Test7Type"
88+
},
89+
value: {
90+
format: "double",
91+
type: "number"
92+
}
93+
}
94+
},
95+
Test7Type: {
96+
enum: [
97+
"VALUE1",
98+
"VALUE2",
99+
"VALUE3"
100+
]
101+
}
102+
}
103+
}
104+
};

test/specs/deep-internal/deep.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
3+
const { expect } = require("chai");
4+
const $RefParser = require("../../..");
5+
const path = require("../../utils/path");
6+
const bundledSchema = require("./bundled");
7+
8+
describe("Schema with deeply-nested internal $refs", () => {
9+
it("should bundle successfully", async () => {
10+
let parser = new $RefParser();
11+
const schema = await parser.bundle(path.rel("specs/deep-internal/Full-spec.yaml"));
12+
expect(schema).to.equal(parser.schema);
13+
expect(schema).to.deep.equal(bundledSchema);
14+
});
15+
});

0 commit comments

Comments
 (0)