From 23a425caefd5c1b8f54103744df388b5e41a1949 Mon Sep 17 00:00:00 2001 From: Konstantinos Feretos Date: Fri, 24 Nov 2023 16:29:50 +0200 Subject: [PATCH] fix(router): route Swagger doc missing non-global security headers (#818) * fix(router): route swagger doc missing non-global security headers * fix(router): invalid authMiddleware condition handling --- modules/router/src/hermes/swaggerMetadata.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/router/src/hermes/swaggerMetadata.ts b/modules/router/src/hermes/swaggerMetadata.ts index 2a454e0c3..4d27f3c0f 100644 --- a/modules/router/src/hermes/swaggerMetadata.ts +++ b/modules/router/src/hermes/swaggerMetadata.ts @@ -6,7 +6,7 @@ export const getSwaggerMetadata: () => SwaggerRouterMetadata = () => ({ urlPrefix: '', securitySchemes: { clientId: { - name: 'clientid', + name: 'clientId', type: 'apiKey', in: 'header', description: 'A security client id, retrievable through [POST] /security/client', @@ -37,6 +37,9 @@ export const getSwaggerMetadata: () => SwaggerRouterMetadata = () => ({ setExtraRouteHeaders(route: ConduitRoute, swaggerRouteDoc: Indexable): void { // https://swagger.io/docs/specification/authentication/#multiple if (route.input.middlewares?.includes('authMiddleware')) { + if (swaggerRouteDoc.security.length === 0) { + swaggerRouteDoc.security.push({}); + } // Logical AND swaggerRouteDoc.security = swaggerRouteDoc.security.map( (originalSecEntry: { [field: string]: string }) => ({ @@ -44,8 +47,10 @@ export const getSwaggerMetadata: () => SwaggerRouterMetadata = () => ({ userToken: [], }), ); - } - if (route.input.middlewares?.includes('authMiddleware?')) { + } else if (route.input.middlewares?.includes('authMiddleware?')) { + if (swaggerRouteDoc.security.length === 0) { + swaggerRouteDoc.security.push({}); + } // Logical OR swaggerRouteDoc.security.forEach( (originalSecEntry: { [field: string]: string }) => {