From c107ca393095a1a45c6a55afc513b02ce70b119e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Thu, 21 Oct 2021 16:05:35 +0200 Subject: [PATCH] fix(): fallback to the original behavior when no aliases --- lib/swagger-explorer.ts | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/lib/swagger-explorer.ts b/lib/swagger-explorer.ts index b91ec5031..3706e5c4a 100644 --- a/lib/swagger-explorer.ts +++ b/lib/swagger-explorer.ts @@ -183,16 +183,33 @@ export class SwaggerExplorer { }, {}) ); - return methodMetadata.root.map((endpointMetadata: DenormalizedDoc) => { - endpointMetadata = { - ...methodMetadata, - root: endpointMetadata as any - }; - const mergedMethodMetadata = this.mergeMetadata( - globalMetadata, - omitBy(endpointMetadata, isEmpty) - ); - return this.migrateOperationSchema( + if (Array.isArray(methodMetadata.root)) { + return methodMetadata.root.map((endpointMetadata: DenormalizedDoc) => { + endpointMetadata = { + ...methodMetadata, + root: endpointMetadata as any + }; + const mergedMethodMetadata = this.mergeMetadata( + globalMetadata, + omitBy(endpointMetadata, isEmpty) + ); + return this.migrateOperationSchema( + { + responses: {}, + ...omit(globalMetadata, 'chunks'), + ...mergedMethodMetadata + }, + prototype, + targetCallback + ); + }); + } + const mergedMethodMetadata = this.mergeMetadata( + globalMetadata, + omitBy(methodMetadata, isEmpty) + ); + return [ + this.migrateOperationSchema( { responses: {}, ...omit(globalMetadata, 'chunks'), @@ -200,8 +217,8 @@ export class SwaggerExplorer { }, prototype, targetCallback - ); - }); + ) + ]; }); return flatten(denormalizedPaths).filter((path) => path.root?.path);