oas-toolkit 0.7.5 → 0.7.7

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 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,17 @@ function getUnusedComponents(all, referenced, oas) {
129
140
  return unused;
130
141
  }
131
142
 
143
+ let recursiveCache = {};
144
+
145
+ function resetReferenceCache() {
146
+ recursiveCache = {};
147
+ }
148
+
132
149
  function getRecursiveReferencesToComponent(oas, component, originalComponents) {
150
+ if (recursiveCache[component]) {
151
+ return recursiveCache[component];
152
+ }
153
+
133
154
  if (!originalComponents) {
134
155
  originalComponents = [];
135
156
  }
@@ -144,6 +165,7 @@ function getRecursiveReferencesToComponent(oas, component, originalComponents) {
144
165
  }
145
166
  refs.sort();
146
167
 
168
+ recursiveCache[component] = refs;
147
169
  return refs;
148
170
  }
149
171
 
@@ -153,4 +175,5 @@ module.exports = {
153
175
  getUnusedComponents,
154
176
  removeSpecifiedComponents,
155
177
  removeUnusedComponents,
178
+ resetReferenceCache,
156
179
  };
package/merger.test.js CHANGED
@@ -491,7 +491,7 @@ describe("returns unique items for:", () => {
491
491
  });
492
492
  });
493
493
 
494
- fit("handles keys that don't exist in both specs", () => {
494
+ it("handles keys that don't exist in both specs", () => {
495
495
  expect(
496
496
  merger([
497
497
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas-toolkit",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {