Skip to content

Commit

Permalink
fix(router): route Swagger doc missing non-global security headers (#818
Browse files Browse the repository at this point in the history
)

* fix(router): route swagger doc missing non-global security headers

* fix(router): invalid authMiddleware condition handling
  • Loading branch information
kon14 authored Nov 24, 2023
1 parent 2e0a4ae commit 23a425c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/router/src/hermes/swaggerMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -37,15 +37,20 @@ 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 }) => ({
...originalSecEntry,
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 }) => {
Expand Down

0 comments on commit 23a425c

Please sign in to comment.