oas-toolkit 0.6.1 → 0.6.2
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/merger.js +29 -2
- package/merger.test.js +84 -1
- package/package.json +1 -1
package/merger.js
CHANGED
|
@@ -204,15 +204,42 @@ function ensureNoComplexObjectCollisions(objects) {
|
|
|
204
204
|
) {
|
|
205
205
|
const k = this.path.slice(0, -1).join(".");
|
|
206
206
|
allPaths[k] = allPaths[k] || [];
|
|
207
|
-
allPaths[k].push({
|
|
207
|
+
allPaths[k].push({
|
|
208
|
+
key: this.key,
|
|
209
|
+
file: object.info.title,
|
|
210
|
+
value: this.node,
|
|
211
|
+
});
|
|
208
212
|
}
|
|
209
213
|
});
|
|
210
214
|
}
|
|
211
215
|
|
|
212
216
|
for (let path in allPaths) {
|
|
213
217
|
if (allPaths[path].length > 1) {
|
|
218
|
+
const v = allPaths[path];
|
|
219
|
+
|
|
220
|
+
// If all entries for this path use the same special key
|
|
221
|
+
if (
|
|
222
|
+
uniqWith(
|
|
223
|
+
v.map((f) => f.key),
|
|
224
|
+
isEqual
|
|
225
|
+
).length == 1
|
|
226
|
+
) {
|
|
227
|
+
// Check if all the values are the same
|
|
228
|
+
const values = v.map((f) => {
|
|
229
|
+
// If it's a oneOf, order doesn't matter so sort for comparison
|
|
230
|
+
if (f.key == "oneOf") {
|
|
231
|
+
f.value.sort();
|
|
232
|
+
}
|
|
233
|
+
return f.value;
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
if (isEqual(...values)) {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
214
241
|
throw new Error(
|
|
215
|
-
`Conflicting complex object detected: ${path} (${
|
|
242
|
+
`Conflicting complex object detected: ${path} (${v
|
|
216
243
|
.map((f) => `${f.file}[${f.key}]`)
|
|
217
244
|
.join(", ")})`
|
|
218
245
|
);
|
package/merger.test.js
CHANGED
|
@@ -189,7 +189,90 @@ describe("#ensureNoComplexObjectCollisions", () => {
|
|
|
189
189
|
);
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
-
it("
|
|
192
|
+
it("does not throw when refs point to the same component", () => {
|
|
193
|
+
expect(() => {
|
|
194
|
+
ensureNoComplexObjectCollisions([
|
|
195
|
+
{
|
|
196
|
+
info: { title: "One" },
|
|
197
|
+
components: {
|
|
198
|
+
schemas: {
|
|
199
|
+
DemoError: {
|
|
200
|
+
$ref: "#/components/schemas/AnotherError",
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
info: { title: "Two" },
|
|
207
|
+
components: {
|
|
208
|
+
schemas: {
|
|
209
|
+
DemoError: {
|
|
210
|
+
$ref: "#/components/schemas/AnotherError",
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
]);
|
|
216
|
+
}).not.toThrow();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("does not throw when oneOf point to the same component (order independent)", () => {
|
|
220
|
+
expect(() => {
|
|
221
|
+
ensureNoComplexObjectCollisions([
|
|
222
|
+
{
|
|
223
|
+
info: { title: "One" },
|
|
224
|
+
components: {
|
|
225
|
+
schemas: {
|
|
226
|
+
DemoError: {
|
|
227
|
+
oneOf: ["#/components/schemas/One", "#/components/schemas/Two"],
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
info: { title: "Two" },
|
|
234
|
+
components: {
|
|
235
|
+
schemas: {
|
|
236
|
+
DemoError: {
|
|
237
|
+
oneOf: ["#/components/schemas/Two", "#/components/schemas/One"],
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
]);
|
|
243
|
+
}).not.toThrow();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("throws when allOf values are provided in different orders", () => {
|
|
247
|
+
expect(() => {
|
|
248
|
+
ensureNoComplexObjectCollisions([
|
|
249
|
+
{
|
|
250
|
+
info: { title: "One" },
|
|
251
|
+
components: {
|
|
252
|
+
schemas: {
|
|
253
|
+
DemoError: {
|
|
254
|
+
allOf: ["#/components/schemas/One", "#/components/schemas/Two"],
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
info: { title: "Two" },
|
|
261
|
+
components: {
|
|
262
|
+
schemas: {
|
|
263
|
+
DemoError: {
|
|
264
|
+
allOf: ["#/components/schemas/Two", "#/components/schemas/One"],
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
]);
|
|
270
|
+
}).toThrow(
|
|
271
|
+
"Conflicting complex object detected: components.schemas.DemoError (One[allOf], Two[allOf])"
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("throws when oneOf is detected alongside other values", () => {
|
|
193
276
|
expect(() => {
|
|
194
277
|
ensureNoComplexObjectCollisions([
|
|
195
278
|
{
|