oas-toolkit 0.7.2 → 0.7.3
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/components.js +10 -2
- package/components.test.js +26 -0
- package/package.json +1 -1
package/components.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const traverse = require("traverse");
|
|
2
|
-
const
|
|
2
|
+
const isEqual = require("lodash.isequal");
|
|
3
3
|
const difference = require("lodash.difference");
|
|
4
4
|
|
|
5
5
|
function removeUnusedComponents(oas) {
|
|
@@ -7,7 +7,15 @@ function removeUnusedComponents(oas) {
|
|
|
7
7
|
const defined = getDefinedComponents(oas);
|
|
8
8
|
const unused = getUnusedComponents(defined, used);
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const result = removeSpecifiedComponents(oas, unused);
|
|
11
|
+
|
|
12
|
+
// If nothing was removed, we've removed all unused components
|
|
13
|
+
// including those referenced by other components that were unused
|
|
14
|
+
if (isEqual(oas, result)) {
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return removeUnusedComponents(result);
|
|
11
19
|
}
|
|
12
20
|
|
|
13
21
|
function removeSpecifiedComponents(oas, unused) {
|
package/components.test.js
CHANGED
|
@@ -227,6 +227,32 @@ describe("#components", () => {
|
|
|
227
227
|
});
|
|
228
228
|
});
|
|
229
229
|
|
|
230
|
+
it("Removes schemas that are only referenced by removed schemas", () => {
|
|
231
|
+
expect(
|
|
232
|
+
c.removeUnusedComponents({
|
|
233
|
+
info: { title: "One" },
|
|
234
|
+
components: {
|
|
235
|
+
schemas: {
|
|
236
|
+
SubSchema: {
|
|
237
|
+
type: "string",
|
|
238
|
+
},
|
|
239
|
+
MySchema: {
|
|
240
|
+
type: "object",
|
|
241
|
+
properties: {
|
|
242
|
+
subSchema: {
|
|
243
|
+
$ref: "#/components/schemas/SubSchema",
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
})
|
|
250
|
+
).toEqual({
|
|
251
|
+
info: { title: "One" },
|
|
252
|
+
components: {},
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
230
256
|
it("removes unused security schemes", () => {
|
|
231
257
|
const securityOas = {
|
|
232
258
|
info: { title: "One" },
|