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

Commit 799b0bd

Browse files
committed
perf(oas2): cache body generation for allOf's with ref
1 parent 7d36778 commit 799b0bd

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/openapi2-parser/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# API Elements: OpenAPI 2 Parser Changelog
22

3+
## Master
4+
5+
### Bug Fixes
6+
7+
- This release includes performance improvements to parsing documents which
8+
contain the same schema re-used via a reference (`$ref`) many times in
9+
request parameters and response bodies under an `allOf` key.
10+
311
## 0.31.0 (2020-05-12)
412

513
### Bug Fixes

packages/openapi2-parser/lib/parser.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,16 @@ class Parser {
16111611
const referencedPathValue = this.referencedPathValue();
16121612
let cacheKey;
16131613
if (referencedPathValue && referencedPathValue.$ref) {
1614+
// schema object with $ref
16141615
cacheKey = `${referencedPathValue.$ref};${contentType}`;
1616+
} else if (
1617+
referencedPathValue
1618+
&& referencedPathValue.allOf
1619+
&& Object.keys(referencedPathValue).length === 1
1620+
&& referencedPathValue.allOf.length === 1
1621+
&& referencedPathValue.allOf[0].$ref) {
1622+
// schema object with single ref in allOf (`allOf: [{$ref: path}]`)
1623+
cacheKey = `${referencedPathValue.allOf[0].$ref};${contentType}`;
16151624
}
16161625

16171626
if (this.generateMessageBody || this.generateMessageBodySchema) {

0 commit comments

Comments
 (0)