From 02c1f4d72a4cc939942663c2de6759345fefdfe9 Mon Sep 17 00:00:00 2001 From: Urs Brogle Date: Sat, 15 Feb 2020 23:05:47 +0100 Subject: [PATCH] Add field caching to avoid out of memory exception. --- src/services/models/Schema.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts index 7fb5a8e9..8f2d6004 100644 --- a/src/services/models/Schema.ts +++ b/src/services/models/Schema.ts @@ -275,12 +275,17 @@ export class SchemaModel { } } +const fieldCache: { [index: string]: FieldModel[] } = {}; + function buildFields( parser: OpenAPIParser, schema: OpenAPISchema, $ref: string, options: RedocNormalizedOptions, ): FieldModel[] { + if (fieldCache[$ref]) { + return fieldCache[$ref]; + } const props = schema.properties || {}; const additionalProps = schema.additionalProperties; const defaults = schema.default || {}; @@ -339,6 +344,8 @@ function buildFields( ); } + fieldCache[$ref] = fields; + return fields; }