Add field caching to avoid out of memory exception.

This commit is contained in:
Urs Brogle 2020-02-15 23:05:47 +01:00
parent c05db38576
commit 02c1f4d72a

View File

@ -275,12 +275,17 @@ export class SchemaModel {
} }
} }
const fieldCache: { [index: string]: FieldModel[] } = {};
function buildFields( function buildFields(
parser: OpenAPIParser, parser: OpenAPIParser,
schema: OpenAPISchema, schema: OpenAPISchema,
$ref: string, $ref: string,
options: RedocNormalizedOptions, options: RedocNormalizedOptions,
): FieldModel[] { ): FieldModel[] {
if (fieldCache[$ref]) {
return fieldCache[$ref];
}
const props = schema.properties || {}; const props = schema.properties || {};
const additionalProps = schema.additionalProperties; const additionalProps = schema.additionalProperties;
const defaults = schema.default || {}; const defaults = schema.default || {};
@ -339,6 +344,8 @@ function buildFields(
); );
} }
fieldCache[$ref] = fields;
return fields; return fields;
} }