Skip to content

Commit

Permalink
perf(resolver): utilize cache for OpenAPI 3.1 normalization (#3009)
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n authored Jun 16, 2023
1 parent c7ccc36 commit 67bb618
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
68 changes: 34 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@
},
"dependencies": {
"@babel/runtime-corejs3": "^7.20.13",
"@swagger-api/apidom-core": ">=0.70.0 <1.0.0",
"@swagger-api/apidom-json-pointer": ">=0.70.0 <1.0.0",
"@swagger-api/apidom-ns-openapi-3-1": ">=0.70.0 <1.0.0",
"@swagger-api/apidom-reference": ">=0.70.0 <1.0.0",
"@swagger-api/apidom-core": ">=0.70.1 <1.0.0",
"@swagger-api/apidom-json-pointer": ">=0.70.1 <1.0.0",
"@swagger-api/apidom-ns-openapi-3-1": ">=0.70.2 <1.0.0",
"@swagger-api/apidom-reference": ">=0.70.2 <1.0.0",
"cookie": "~0.5.0",
"cross-fetch": "^3.1.5",
"deepmerge": "~4.3.0",
Expand Down
7 changes: 6 additions & 1 deletion src/resolver/strategies/openapi-3-1-apidom/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ const normalize = (element) => {
*/
export const pojoAdapter = (normalizeFn) => (spec) => {
if (spec?.$$normalized) return spec;
if (pojoAdapter.cache.has(spec)) return spec;

const openApiElement = OpenApi3_1Element.refract(spec);
const normalized = normalizeFn(openApiElement);
const value = toValue(normalized);

return toValue(normalized);
pojoAdapter.cache.set(spec, value);

return value;
};
pojoAdapter.cache = new WeakMap();

export default normalize;
/* eslint-enable camelcase */

0 comments on commit 67bb618

Please sign in to comment.