@@ -13,7 +13,8 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
13
13
if ( ! securitySchemes || ! Object . keys ( securitySchemes ) . length ) return "" ;
14
14
15
15
const createAuthenticationTable = ( securityScheme : any ) => {
16
- const { bearerFormat, flows, name, scheme, type } = securityScheme ;
16
+ const { bearerFormat, flows, name, scheme, type, openIdConnectUrl } =
17
+ securityScheme ;
17
18
18
19
const createSecuritySchemeTypeRow = ( ) =>
19
20
create ( "tr" , {
@@ -30,7 +31,7 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
30
31
31
32
return create ( "tr" , {
32
33
children : [
33
- create ( "th" , { children : `${ flowType } OAuth Flow :` } ) ,
34
+ create ( "th" , { children : `OAuth Flow ( ${ flowType } ) :` } ) ,
34
35
create ( "td" , {
35
36
children : [
36
37
guard ( tokenUrl , ( ) =>
@@ -91,12 +92,14 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
91
92
create ( "td" , { children : scheme } ) ,
92
93
] ,
93
94
} ) ,
94
- create ( "tr" , {
95
- children : [
96
- create ( "th" , { children : "Bearer format:" } ) ,
97
- create ( "td" , { children : bearerFormat } ) ,
98
- ] ,
99
- } ) ,
95
+ guard ( bearerFormat , ( ) =>
96
+ create ( "tr" , {
97
+ children : [
98
+ create ( "th" , { children : "Bearer format:" } ) ,
99
+ create ( "td" , { children : bearerFormat } ) ,
100
+ ] ,
101
+ } )
102
+ ) ,
100
103
] ,
101
104
} ) ,
102
105
} ) ,
@@ -115,23 +118,51 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
115
118
} ) ,
116
119
] ,
117
120
} ) ;
121
+ case "openIdConnect" :
122
+ return create ( "div" , {
123
+ children : [
124
+ create ( "table" , {
125
+ children : create ( "tbody" , {
126
+ children : [
127
+ createSecuritySchemeTypeRow ( ) ,
128
+ guard ( openIdConnectUrl , ( ) =>
129
+ create ( "tr" , {
130
+ children : [
131
+ create ( "th" , { children : "OpenID Connect URL:" } ) ,
132
+ create ( "td" , { children : openIdConnectUrl } ) ,
133
+ ] ,
134
+ } )
135
+ ) ,
136
+ ] ,
137
+ } ) ,
138
+ } ) ,
139
+ ] ,
140
+ } ) ;
118
141
default :
119
142
return "" ;
120
143
}
121
144
} ;
122
145
123
- const formatTabLabel = ( str : string ) => {
124
- const formattedLabel = str
146
+ const formatTabLabel = ( key : string , type : string , scheme : string ) => {
147
+ const formattedLabel = key
125
148
. replace ( / ( _ | - ) / g, " " )
126
149
. trim ( )
127
150
. replace ( / \w \S * / g, ( str ) => str . charAt ( 0 ) . toUpperCase ( ) + str . substr ( 1 ) )
128
151
. replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, "$1 $2" )
129
152
. replace ( / ( [ A - Z ] ) ( [ A - Z ] [ a - z ] ) / g, "$1 $2" ) ;
153
+ const isOAuth = type === "oauth2" ;
154
+ const isApiKey = type === "apiKey" ;
155
+ const isHttpBasic = type === "http" && scheme === "basic" ;
156
+ const isHttpBearer = type === "http" && scheme === "bearer" ;
157
+ const isOpenId = type === "openIdConnect" ;
130
158
131
- const isOAuth = formattedLabel . toLowerCase ( ) . includes ( "oauth2" ) ;
132
- const isApiKey = formattedLabel . toLowerCase ( ) . includes ( "api" ) ;
159
+ if ( isOAuth ) return `OAuth 2.0: ${ key } ` ;
160
+ if ( isApiKey ) return `API Key: ${ key } ` ;
161
+ if ( isHttpBasic ) return "HTTP: Basic Auth" ;
162
+ if ( isHttpBearer ) return "HTTP: Bearer Auth" ;
163
+ if ( isOpenId ) return `OpenID Connect: ${ key } ` ;
133
164
134
- return isOAuth ? "OAuth 2.0" : isApiKey ? "API Key" : formattedLabel ;
165
+ return formattedLabel ;
135
166
} ;
136
167
137
168
return create ( "div" , {
@@ -141,12 +172,17 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
141
172
id : "authentication" ,
142
173
style : { marginBottom : "1rem" } ,
143
174
} ) ,
144
- create ( "Tabs" , {
175
+ create ( "SchemaTabs" , {
176
+ className : "openapi-tabs__security-schemes" ,
145
177
children : Object . entries ( securitySchemes ) . map (
146
- ( [ schemeType , schemeObj ] ) =>
178
+ ( [ schemeKey , schemeObj ] ) =>
147
179
create ( "TabItem" , {
148
- label : formatTabLabel ( schemeType ) ,
149
- value : `${ schemeType } ` ,
180
+ label : formatTabLabel (
181
+ schemeKey ,
182
+ schemeObj . type ,
183
+ schemeObj . scheme
184
+ ) ,
185
+ value : `${ schemeKey } ` ,
150
186
children : [
151
187
createDescription ( schemeObj . description ) ,
152
188
createAuthenticationTable ( schemeObj ) ,
0 commit comments