diff --git a/src/services/AppStore.ts b/src/services/AppStore.ts index 8ecc3a6df7..217b4cf1be 100644 --- a/src/services/AppStore.ts +++ b/src/services/AppStore.ts @@ -101,6 +101,9 @@ export class AppStore { dispose() { this.scroll.dispose(); this.menu.dispose(); + if (this.search) { + this.search.dispose(); + } if (this.disposer != null) { this.disposer(); } diff --git a/src/services/SearchStore.ts b/src/services/SearchStore.ts index 669d8d05bb..ab80b71c8a 100644 --- a/src/services/SearchStore.ts +++ b/src/services/SearchStore.ts @@ -38,6 +38,10 @@ export class SearchStore { this.searchWorker.add(title, body, meta); } + dispose() { + (this.searchWorker as any).terminate(); + } + search(q: string) { return this.searchWorker.search(q); } diff --git a/src/services/models/MediaContent.ts b/src/services/models/MediaContent.ts index 32fd770e84..c709f42a84 100644 --- a/src/services/models/MediaContent.ts +++ b/src/services/models/MediaContent.ts @@ -21,7 +21,7 @@ export class MediaContentModel { * @param isRequestType needed to know if skipe RO/RW fields in objects */ constructor( - public parser: OpenAPIParser, + parser: OpenAPIParser, info: Dict, public isRequestType: boolean, options: RedocNormalizedOptions, diff --git a/src/services/models/Operation.ts b/src/services/models/Operation.ts index 7e846f2806..1aa3a65d79 100644 --- a/src/services/models/Operation.ts +++ b/src/services/models/Operation.ts @@ -76,7 +76,6 @@ export class OperationModel implements IMenuItem { path: string; servers: OpenAPIServer[]; security: SecurityRequirementModel[]; - codeSamples: Array; extensions: Dict; constructor( @@ -104,23 +103,6 @@ export class OperationModel implements IMenuItem { this.deprecated = !!operationSpec.deprecated; this.operationId = operationSpec.operationId; this.path = operationSpec.pathName; - this.codeSamples = operationSpec['x-code-samples'] || []; - - const requestBodyContent = this.requestBody && this.requestBody.content; - if (requestBodyContent && requestBodyContent.hasSample) { - const insertInx = Math.min(this.codeSamples.length, options.payloadSampleIdx); - - this.codeSamples = [ - ...this.codeSamples.slice(0, insertInx), - { - lang: 'payload', - label: 'Payload', - source: '', - requestBodyContent, - }, - ...this.codeSamples.slice(insertInx), - ]; - } const pathInfo = parser.byRef( JsonPointer.compile(['paths', operationSpec.pathName]), @@ -174,6 +156,30 @@ export class OperationModel implements IMenuItem { ); } + @memoize + get codeSamples() { + let samples: Array = + this.operationSpec['x-code-samples'] || []; + + const requestBodyContent = this.requestBody && this.requestBody.content; + if (requestBodyContent && requestBodyContent.hasSample) { + const insertInx = Math.min(samples.length, this.options.payloadSampleIdx); + + samples = [ + ...samples.slice(0, insertInx), + { + lang: 'payload', + label: 'Payload', + source: '', + requestBodyContent, + }, + ...samples.slice(insertInx), + ]; + } + + return samples; + } + @memoize get parameters() { const _parameters = mergeParams(