oas-toolkit 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/commands/check-conflicts.js +1 -0
- package/merger.js +26 -13
- package/merger.test.js +73 -68
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ module.exports = async function ({ argv }) {
|
|
|
19
19
|
merger.ensureNoPathColissions(oas, argv);
|
|
20
20
|
merger.ensureNoTagColissions(oas, argv);
|
|
21
21
|
merger.ensureNoSecurityColissions(oas, argv);
|
|
22
|
+
merger.ensureNoComplexObjectCollisions(oas, argv);
|
|
22
23
|
} catch (e) {
|
|
23
24
|
console.error(`ERROR: ${e.message}`);
|
|
24
25
|
process.exit(1);
|
package/merger.js
CHANGED
|
@@ -36,19 +36,6 @@ function merge(objects, options) {
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
// Validate that $ref is the only thing at a specific level
|
|
40
|
-
combinedSpec = traverse(combinedSpec).map(function () {
|
|
41
|
-
if (["oneOf", "allOf", "anyOf", "$ref"].includes(this.key)) {
|
|
42
|
-
if (Object.keys(this.parent.node).length > 1) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
`Cannot have ${
|
|
45
|
-
this.key
|
|
46
|
-
} and other properties at the same level: ${this.path.join(".")}`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
39
|
return combinedSpec;
|
|
53
40
|
}
|
|
54
41
|
|
|
@@ -208,9 +195,35 @@ function ensureNoSecurityColissions(objects) {
|
|
|
208
195
|
}
|
|
209
196
|
}
|
|
210
197
|
|
|
198
|
+
function ensureNoComplexObjectCollisions(objects) {
|
|
199
|
+
const allPaths = {};
|
|
200
|
+
for (let object of objects) {
|
|
201
|
+
traverse(object).forEach(function () {
|
|
202
|
+
if (
|
|
203
|
+
["oneOf", "allOf", "anyOf", "$ref", "properties"].includes(this.key)
|
|
204
|
+
) {
|
|
205
|
+
const k = this.path.slice(0, -1).join(".");
|
|
206
|
+
allPaths[k] = allPaths[k] || [];
|
|
207
|
+
allPaths[k].push({ key: this.key, file: object.info.title });
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
for (let path in allPaths) {
|
|
213
|
+
if (allPaths[path].length > 1) {
|
|
214
|
+
throw new Error(
|
|
215
|
+
`Conflicting complex object detected: ${path} (${allPaths[path]
|
|
216
|
+
.map((f) => `${f.file}[${f.key}]`)
|
|
217
|
+
.join(", ")})`
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
211
223
|
module.exports = Object.assign(merge, {
|
|
212
224
|
ensureNoComponentColissions,
|
|
213
225
|
ensureNoPathColissions,
|
|
214
226
|
ensureNoTagColissions,
|
|
215
227
|
ensureNoSecurityColissions,
|
|
228
|
+
ensureNoComplexObjectCollisions,
|
|
216
229
|
});
|
package/merger.test.js
CHANGED
|
@@ -3,6 +3,7 @@ const {
|
|
|
3
3
|
ensureNoPathColissions,
|
|
4
4
|
ensureNoTagColissions,
|
|
5
5
|
ensureNoSecurityColissions,
|
|
6
|
+
ensureNoComplexObjectCollisions,
|
|
6
7
|
} = require("./merger");
|
|
7
8
|
const merger = require("./merger");
|
|
8
9
|
|
|
@@ -152,6 +153,78 @@ describe("#ensureNoComponentColissions", () => {
|
|
|
152
153
|
});
|
|
153
154
|
});
|
|
154
155
|
|
|
156
|
+
describe("#ensureNoComplexObjectCollisions", () => {
|
|
157
|
+
it("throws when $ref is detected alongside other values", () => {
|
|
158
|
+
expect(() => {
|
|
159
|
+
ensureNoComplexObjectCollisions([
|
|
160
|
+
{
|
|
161
|
+
info: { title: "One" },
|
|
162
|
+
components: {
|
|
163
|
+
schemas: {
|
|
164
|
+
DemoError: {
|
|
165
|
+
type: "object",
|
|
166
|
+
properties: {
|
|
167
|
+
code: {
|
|
168
|
+
type: "string",
|
|
169
|
+
example: "ERROR_ABC",
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
info: { title: "Two" },
|
|
178
|
+
components: {
|
|
179
|
+
schemas: {
|
|
180
|
+
DemoError: {
|
|
181
|
+
$ref: "#/components/schemas/AnotherError",
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
}).toThrow(
|
|
188
|
+
"Conflicting complex object detected: components.schemas.DemoError (One[properties], Two[$ref])"
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("throws when $ref is detected alongside other values", () => {
|
|
193
|
+
expect(() => {
|
|
194
|
+
ensureNoComplexObjectCollisions([
|
|
195
|
+
{
|
|
196
|
+
info: { title: "One" },
|
|
197
|
+
components: {
|
|
198
|
+
schemas: {
|
|
199
|
+
DemoError: {
|
|
200
|
+
type: "object",
|
|
201
|
+
properties: {
|
|
202
|
+
code: {
|
|
203
|
+
type: "string",
|
|
204
|
+
example: "ERROR_ABC",
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
info: { title: "Two" },
|
|
213
|
+
components: {
|
|
214
|
+
schemas: {
|
|
215
|
+
DemoError: {
|
|
216
|
+
oneOf: ["#/components/schemas/AnotherError"],
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
]);
|
|
222
|
+
}).toThrow(
|
|
223
|
+
"Conflicting complex object detected: components.schemas.DemoError (One[properties], Two[oneOf])"
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
155
228
|
describe("path collisions", () => {
|
|
156
229
|
it("does not throw with overlapping paths and different verbs", () => {
|
|
157
230
|
expect(
|
|
@@ -453,71 +526,3 @@ describe("returns unique items for:", () => {
|
|
|
453
526
|
});
|
|
454
527
|
});
|
|
455
528
|
});
|
|
456
|
-
|
|
457
|
-
describe("validates the final output", () => {
|
|
458
|
-
it("throws when $ref is detected alongside other values", () => {
|
|
459
|
-
expect(() => {
|
|
460
|
-
merger([
|
|
461
|
-
{
|
|
462
|
-
components: {
|
|
463
|
-
schemas: {
|
|
464
|
-
DemoError: {
|
|
465
|
-
type: "object",
|
|
466
|
-
properties: {
|
|
467
|
-
code: {
|
|
468
|
-
type: "string",
|
|
469
|
-
example: "ERROR_ABC",
|
|
470
|
-
},
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
},
|
|
474
|
-
},
|
|
475
|
-
},
|
|
476
|
-
{
|
|
477
|
-
components: {
|
|
478
|
-
schemas: {
|
|
479
|
-
DemoError: {
|
|
480
|
-
$ref: "#/components/schemas/AnotherError",
|
|
481
|
-
},
|
|
482
|
-
},
|
|
483
|
-
},
|
|
484
|
-
},
|
|
485
|
-
]);
|
|
486
|
-
}).toThrow(
|
|
487
|
-
"Cannot have $ref and other properties at the same level: components.schemas.DemoError.$ref"
|
|
488
|
-
);
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
it("throws when $ref is detected alongside other values", () => {
|
|
492
|
-
expect(() => {
|
|
493
|
-
merger([
|
|
494
|
-
{
|
|
495
|
-
components: {
|
|
496
|
-
schemas: {
|
|
497
|
-
DemoError: {
|
|
498
|
-
type: "object",
|
|
499
|
-
properties: {
|
|
500
|
-
code: {
|
|
501
|
-
type: "string",
|
|
502
|
-
example: "ERROR_ABC",
|
|
503
|
-
},
|
|
504
|
-
},
|
|
505
|
-
},
|
|
506
|
-
},
|
|
507
|
-
},
|
|
508
|
-
},
|
|
509
|
-
{
|
|
510
|
-
components: {
|
|
511
|
-
schemas: {
|
|
512
|
-
DemoError: {
|
|
513
|
-
oneOf: ["#/components/schemas/AnotherError"],
|
|
514
|
-
},
|
|
515
|
-
},
|
|
516
|
-
},
|
|
517
|
-
},
|
|
518
|
-
]);
|
|
519
|
-
}).toThrow(
|
|
520
|
-
"Cannot have oneOf and other properties at the same level: components.schemas.DemoError.oneOf"
|
|
521
|
-
);
|
|
522
|
-
});
|
|
523
|
-
});
|