oas-toolkit 0.7.5 → 0.7.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/components.js +17 -0
- package/merger.test.js +1 -1
- package/package.json +1 -1
package/components.js
CHANGED
|
@@ -2,6 +2,7 @@ const traverse = require("traverse");
|
|
|
2
2
|
const isEqual = require("lodash.isequal");
|
|
3
3
|
const difference = require("lodash.difference");
|
|
4
4
|
const intersection = require("lodash.intersection");
|
|
5
|
+
const uniqWith = require("lodash.uniqwith");
|
|
5
6
|
|
|
6
7
|
function removeUnusedComponents(oas) {
|
|
7
8
|
const used = getReferencedComponents(oas);
|
|
@@ -114,6 +115,16 @@ function getUnusedComponents(all, referenced, oas) {
|
|
|
114
115
|
// If there's a circular dependency and nothing else, it can be removed
|
|
115
116
|
for (let ref of references) {
|
|
116
117
|
referencesTo[ref] = getRecursiveReferencesToComponent(oas, ref);
|
|
118
|
+
// Add all the references for each reference to build a complete list
|
|
119
|
+
referencesTo[ref] = referencesTo[ref].concat(
|
|
120
|
+
referencesTo[ref].flatMap((r) => {
|
|
121
|
+
if (!referencesTo[r]) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
return referencesTo[r];
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
referencesTo[ref] = uniqWith(referencesTo[ref], isEqual);
|
|
117
128
|
}
|
|
118
129
|
|
|
119
130
|
let shouldRemove = true;
|
|
@@ -129,7 +140,12 @@ function getUnusedComponents(all, referenced, oas) {
|
|
|
129
140
|
return unused;
|
|
130
141
|
}
|
|
131
142
|
|
|
143
|
+
const recursiveCache = {};
|
|
132
144
|
function getRecursiveReferencesToComponent(oas, component, originalComponents) {
|
|
145
|
+
if (recursiveCache[component]) {
|
|
146
|
+
return recursiveCache[component];
|
|
147
|
+
}
|
|
148
|
+
|
|
133
149
|
if (!originalComponents) {
|
|
134
150
|
originalComponents = [];
|
|
135
151
|
}
|
|
@@ -144,6 +160,7 @@ function getRecursiveReferencesToComponent(oas, component, originalComponents) {
|
|
|
144
160
|
}
|
|
145
161
|
refs.sort();
|
|
146
162
|
|
|
163
|
+
recursiveCache[component] = refs;
|
|
147
164
|
return refs;
|
|
148
165
|
}
|
|
149
166
|
|
package/merger.test.js
CHANGED