oas-toolkit 0.15.0 → 0.15.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/filter-annotation.js +10 -0
- package/filter-annotation.test.js +22 -0
- package/package.json +1 -1
package/filter-annotation.js
CHANGED
|
@@ -7,6 +7,10 @@ function run(oas, opts = {}) {
|
|
|
7
7
|
for (const p of Object.keys(oas.paths)) {
|
|
8
8
|
const path = oas.paths[p];
|
|
9
9
|
for (const verb in path) {
|
|
10
|
+
if (verb == "parameters") {
|
|
11
|
+
continue; // Skip parameters
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
if (opts.keep?.length > 0) {
|
|
11
15
|
for (const keep of opts.keep) {
|
|
12
16
|
if (path[verb][keep] === undefined) {
|
|
@@ -28,6 +32,12 @@ function run(oas, opts = {}) {
|
|
|
28
32
|
if (Object.keys(path).length === 0) {
|
|
29
33
|
delete oas.paths[p];
|
|
30
34
|
}
|
|
35
|
+
|
|
36
|
+
// Also remove if only parameters remain
|
|
37
|
+
if (Object.keys(path).length === 1 && path['parameters']) {
|
|
38
|
+
delete oas.paths[p];
|
|
39
|
+
}
|
|
40
|
+
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
return oas;
|
|
@@ -45,4 +45,26 @@ describe("#run", () => {
|
|
|
45
45
|
it("removes empty paths", () => {
|
|
46
46
|
expect(c.run(oas, { keep: ["x-missing"] }).paths).toEqual({});
|
|
47
47
|
});
|
|
48
|
+
|
|
49
|
+
it("removes empty paths with just parameters", () => {
|
|
50
|
+
const oas = {
|
|
51
|
+
servers: [
|
|
52
|
+
{
|
|
53
|
+
url: "https://api.example.com/v1",
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
paths: {
|
|
57
|
+
"/foo/hello": {
|
|
58
|
+
parameters: [
|
|
59
|
+
- { "$ref": '#/components/parameters/Other' }
|
|
60
|
+
],
|
|
61
|
+
get: {
|
|
62
|
+
"x-internal": true,
|
|
63
|
+
description: "Hello world endpoint",
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
expect(c.run(oas, { keep: ["x-missing"] }).paths).toEqual({});
|
|
69
|
+
});
|
|
48
70
|
});
|