File tree Expand file tree Collapse file tree 3 files changed +23
-18
lines changed
packages/react-openapi/src Expand file tree Collapse file tree 3 files changed +23
-18
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @gitbook/react-openapi ' : patch
3
+ ---
4
+
5
+ Better securities sample and headers
Original file line number Diff line number Diff line change @@ -136,34 +136,28 @@ function getSecurityHeaders(securities: OpenAPIOperationData['securities']): {
136
136
switch ( security [ 1 ] . type ) {
137
137
case 'http' : {
138
138
let scheme = security [ 1 ] . scheme ;
139
- if ( scheme === 'bearer' ) {
139
+ let format = security [ 1 ] . bearerFormat ?? 'YOUR_SECRET_TOKEN' ;
140
+
141
+ if ( scheme ?. includes ( 'bearer' ) ) {
140
142
scheme = 'Bearer' ;
143
+ } else if ( scheme ?. includes ( 'basic' ) ) {
144
+ scheme = 'Basic' ;
145
+ format = 'username:password' ;
146
+ } else if ( scheme ?. includes ( 'token' ) ) {
147
+ scheme = 'Token' ;
141
148
}
142
149
143
150
return {
144
- Authorization : scheme + ' ' + ( security [ 1 ] . bearerFormat ?? '<token>' ) ,
151
+ Authorization : scheme + ' ' + format ,
145
152
} ;
146
153
}
147
154
case 'apiKey' : {
148
155
if ( security [ 1 ] . in !== 'header' ) return { } ;
149
156
150
157
const name = security [ 1 ] . name ?? 'Authorization' ;
151
- let scheme = security [ 0 ] ;
152
-
153
- switch ( scheme ) {
154
- case 'bearerAuth' :
155
- scheme = 'Bearer' ;
156
- break ;
157
- case 'token' :
158
- scheme = 'Token' ;
159
- break ;
160
- case 'basic' :
161
- scheme = 'Basic' ;
162
- break ;
163
- }
164
158
165
159
return {
166
- [ name ] : scheme + ' ' + '<apiKey> ',
160
+ [ name ] : 'YOUR_API_KEY ',
167
161
} ;
168
162
}
169
163
default : {
Original file line number Diff line number Diff line change @@ -53,10 +53,16 @@ export function OpenAPISecurities(props: {
53
53
function getLabelForType ( security : OpenAPIV3_1 . SecuritySchemeObject ) {
54
54
switch ( security . type ) {
55
55
case 'apiKey' :
56
- return < OpenAPISchemaName propertyName = "apiKey" type = "string" required /> ;
56
+ return (
57
+ < OpenAPISchemaName
58
+ propertyName = { security . name ?? 'apiKey' }
59
+ type = "string"
60
+ required
61
+ />
62
+ ) ;
57
63
case 'http' :
58
64
if ( security . scheme === 'basic' ) {
59
- return 'Basic Auth' ;
65
+ return < OpenAPISchemaName propertyName = "Authorization" type = "string" required /> ;
60
66
}
61
67
62
68
if ( security . scheme == 'bearer' ) {
You can’t perform that action at this time.
0 commit comments