oas-toolkit 0.15.4 → 0.15.6
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/filter-annotation.js +12 -4
- package/filter-annotation.test.js +22 -0
- package/merger.js +1 -1
- package/merger.test.js +9 -0
- package/package.json +1 -1
package/filter-annotation.js
CHANGED
|
@@ -12,19 +12,27 @@ function run(oas, opts = {}) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
if (opts.keep?.length > 0) {
|
|
15
|
+
let containsAny = false;
|
|
15
16
|
for (const keep of opts.keep) {
|
|
16
|
-
if (path[verb][keep]
|
|
17
|
-
|
|
17
|
+
if (path[verb][keep] !== undefined) {
|
|
18
|
+
containsAny = true;
|
|
18
19
|
}
|
|
19
20
|
}
|
|
21
|
+
if (!containsAny) {
|
|
22
|
+
delete path[verb];
|
|
23
|
+
}
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
if (opts.remove?.length > 0) {
|
|
27
|
+
let containsAny = false;
|
|
23
28
|
for (const remove of opts.remove) {
|
|
24
|
-
if (path[verb][remove]) {
|
|
25
|
-
|
|
29
|
+
if (path[verb][remove] !== undefined) {
|
|
30
|
+
containsAny = true;
|
|
26
31
|
}
|
|
27
32
|
}
|
|
33
|
+
if (containsAny) {
|
|
34
|
+
delete path[verb];
|
|
35
|
+
}
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
38
|
|
|
@@ -13,6 +13,7 @@ const oas = {
|
|
|
13
13
|
description: "Hello world endpoint",
|
|
14
14
|
},
|
|
15
15
|
post: {
|
|
16
|
+
"x-other": true,
|
|
16
17
|
description: "Create a hello world",
|
|
17
18
|
},
|
|
18
19
|
},
|
|
@@ -32,16 +33,37 @@ describe("#run", () => {
|
|
|
32
33
|
});
|
|
33
34
|
});
|
|
34
35
|
|
|
36
|
+
it("with multiple keep", () => {
|
|
37
|
+
expect(c.run(oas, { keep: ["x-internal", "x-other"] }).paths).toEqual({
|
|
38
|
+
"/foo/hello": {
|
|
39
|
+
get: {
|
|
40
|
+
"x-internal": true,
|
|
41
|
+
description: "Hello world endpoint",
|
|
42
|
+
},
|
|
43
|
+
post: {
|
|
44
|
+
"x-other": true,
|
|
45
|
+
description: "Create a hello world",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
35
51
|
it("with remove", () => {
|
|
36
52
|
expect(c.run(oas, { remove: ["x-internal"] }).paths).toEqual({
|
|
37
53
|
"/foo/hello": {
|
|
38
54
|
post: {
|
|
55
|
+
"x-other": true,
|
|
39
56
|
description: "Create a hello world",
|
|
40
57
|
},
|
|
41
58
|
},
|
|
42
59
|
});
|
|
43
60
|
});
|
|
44
61
|
|
|
62
|
+
it("with multiple remove", () => {
|
|
63
|
+
expect(c.run(oas, { remove: ["x-internal", "x-other"] }).paths).toEqual({
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
45
67
|
it("removes empty paths", () => {
|
|
46
68
|
expect(c.run(oas, { keep: ["x-missing"] }).paths).toEqual({});
|
|
47
69
|
});
|
package/merger.js
CHANGED
|
@@ -107,7 +107,7 @@ function ensureNoPathColissions(objects) {
|
|
|
107
107
|
// Normalise the path
|
|
108
108
|
const normalisedPath = path.replace(/\{\w+\}/g, "{VAR}");
|
|
109
109
|
for (let verb in object.paths[path]) {
|
|
110
|
-
const k = `${verb.toUpperCase()} ${normalisedPath}`;
|
|
110
|
+
const k = `${verb.toUpperCase()} ${normalisedPath} @ ${object.servers ? object.servers.map(s => s.url).join(",") : "No Server"}`;
|
|
111
111
|
actionList[k] = actionList[k] || [];
|
|
112
112
|
actionList[k].push(object.info.title);
|
|
113
113
|
}
|
package/merger.test.js
CHANGED
|
@@ -363,6 +363,15 @@ describe("path collisions", () => {
|
|
|
363
363
|
).toBe(undefined);
|
|
364
364
|
});
|
|
365
365
|
|
|
366
|
+
it.only("does not throw with overlapping paths and different servers", () => {
|
|
367
|
+
expect(
|
|
368
|
+
ensureNoPathColissions([
|
|
369
|
+
{ info: { title: "One" }, servers: [{ url: "https://example.com/v1" }], paths: { "/foo": { get: {} } } },
|
|
370
|
+
{ info: { title: "Two" }, servers: [{ url: "https://example.com/v2" }], paths: { "/foo": { get: {} } } },
|
|
371
|
+
])
|
|
372
|
+
).toBe(undefined);
|
|
373
|
+
});
|
|
374
|
+
|
|
366
375
|
it("throws when a path has multiple implementations for a verb (static)", () => {
|
|
367
376
|
expect(() => {
|
|
368
377
|
ensureNoPathColissions([
|