Skip to content

Commit ca3a88e

Browse files
authored
fix(openapi): hide auth header when set in securityScheme (#769)
1 parent 19a7513 commit ca3a88e

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

examples/options.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ const openapiOption = {
5252
type: 'apiKey',
5353
name: 'apiKey',
5454
in: 'header'
55+
},
56+
bearerAuth: {
57+
type: 'http',
58+
scheme: 'bearer'
5559
}
5660
}
5761
},
5862
security: [{
59-
apiKey: []
63+
apiKey: [],
64+
bearerAuth: []
6065
}],
6166
externalDocs: {
6267
description: 'Find more info here',

lib/spec/openapi/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,10 @@ function prepareOpenapiMethod (schema, ref, openapiObject, url) {
373373
]
374374
.reduce((acc, securitySchemeGroup) => {
375375
Object.keys(securitySchemeGroup).forEach((securitySchemeLabel) => {
376-
const { name, in: category } = openapiObject.components.securitySchemes[securitySchemeLabel]
376+
const scheme = openapiObject.components.securitySchemes[securitySchemeLabel]
377+
const isBearer = scheme.type === 'http' && scheme.scheme === 'bearer'
378+
const category = isBearer ? 'header' : scheme.in
379+
const name = isBearer ? 'authorization' : scheme.name
377380
if (!acc[category]) {
378381
acc[category] = []
379382
}

test/spec/openapi/route.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ test('security headers ignored when declared in security and securityScheme', as
647647
type: 'string',
648648
description: 'api token'
649649
},
650+
bearerAuth: {
651+
type: 'string',
652+
description: 'authorization bearer'
653+
},
650654
id: {
651655
type: 'string',
652656
description: 'common field'

0 commit comments

Comments
 (0)