Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 600ca9e

Browse files
committed
perf(oas2): cache body asset for $ref's with same content type
With some larger API Description documents the parse time goes down from ~80 seconds to ~14 seconds.
1 parent b14bdee commit 600ca9e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/fury-adapter-swagger/lib/parser.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,16 @@ class Parser {
15301530

15311531
pushAssets(schema, payload, contentType, pushBody) {
15321532
let jsonSchema;
1533+
1534+
if (this.bodyCache === undefined) {
1535+
this.bodyCache = {};
1536+
}
1537+
15331538
const referencedPathValue = this.referencedPathValue();
1539+
let cacheKey;
1540+
if (referencedPathValue && referencedPathValue.$ref) {
1541+
cacheKey = `${referencedPathValue.$ref};${contentType}`;
1542+
}
15341543

15351544
try {
15361545
const root = { definitions: this.definitions };
@@ -1542,7 +1551,15 @@ class Parser {
15421551
}
15431552

15441553
if (pushBody) {
1545-
bodyFromSchema(jsonSchema, payload, this, contentType);
1554+
if (cacheKey && this.bodyCache[cacheKey]) {
1555+
const asset = this.bodyCache[cacheKey];
1556+
payload.push(asset.clone());
1557+
} else {
1558+
const asset = bodyFromSchema(jsonSchema, payload, this, contentType);
1559+
if (cacheKey) {
1560+
this.bodyCache[cacheKey] = asset;
1561+
}
1562+
}
15461563
}
15471564

15481565
this.pushSchemaAsset(schema, jsonSchema, payload, this.path);

0 commit comments

Comments
 (0)