1
+ import type { OpenAPIV3 } from '@gitbook/openapi-parser' ;
1
2
import { InteractiveSection } from './InteractiveSection' ;
2
3
import { Markdown } from './Markdown' ;
4
+ import { OpenAPICopyButton } from './OpenAPICopyButton' ;
3
5
import { OpenAPISchemaName } from './OpenAPISchemaName' ;
4
6
import type { OpenAPIClientContext } from './context' ;
5
7
import { t } from './translate' ;
@@ -105,13 +107,7 @@ function getLabelForType(security: OpenAPISecurityWithRequired, context: OpenAPI
105
107
/>
106
108
) ;
107
109
case 'oauth2' :
108
- return (
109
- < OpenAPISchemaName
110
- context = { context }
111
- propertyName = "OAuth2"
112
- required = { security . required }
113
- />
114
- ) ;
110
+ return < OpenAPISchemaOAuth2Flows context = { context } security = { security } /> ;
115
111
case 'openIdConnect' :
116
112
return (
117
113
< OpenAPISchemaName
@@ -125,3 +121,111 @@ function getLabelForType(security: OpenAPISecurityWithRequired, context: OpenAPI
125
121
return security . type ;
126
122
}
127
123
}
124
+
125
+ function OpenAPISchemaOAuth2Flows ( props : {
126
+ context : OpenAPIClientContext ;
127
+ security : OpenAPIV3 . OAuth2SecurityScheme & { required ?: boolean } ;
128
+ } ) {
129
+ const { context, security } = props ;
130
+
131
+ const flows = Object . entries ( security . flows ?? { } ) ;
132
+
133
+ return (
134
+ < div className = "openapi-securities-oauth-flows" >
135
+ { flows . map ( ( [ name , flow ] , index ) => (
136
+ < OpenAPISchemaOAuth2Item
137
+ key = { index }
138
+ flow = { flow }
139
+ name = { name }
140
+ context = { context }
141
+ security = { security }
142
+ />
143
+ ) ) }
144
+ </ div >
145
+ ) ;
146
+ }
147
+
148
+ function OpenAPISchemaOAuth2Item ( props : {
149
+ flow : NonNullable < OpenAPIV3 . OAuth2SecurityScheme [ 'flows' ] > [ keyof NonNullable <
150
+ OpenAPIV3 . OAuth2SecurityScheme [ 'flows' ]
151
+ > ] ;
152
+ name : string ;
153
+ context : OpenAPIClientContext ;
154
+ security : OpenAPIV3 . OAuth2SecurityScheme & { required ?: boolean } ;
155
+ } ) {
156
+ const { flow, context, security, name } = props ;
157
+
158
+ if ( ! flow ) {
159
+ return null ;
160
+ }
161
+
162
+ const scopes = Object . entries ( flow ?. scopes ?? { } ) ;
163
+
164
+ return (
165
+ < div >
166
+ < OpenAPISchemaName
167
+ context = { context }
168
+ propertyName = "OAuth2"
169
+ type = { name }
170
+ required = { security . required }
171
+ />
172
+ < div className = "openapi-securities-oauth-content openapi-markdown" >
173
+ { security . description ? < Markdown source = { security . description } /> : null }
174
+ { 'authorizationUrl' in flow && flow . authorizationUrl ? (
175
+ < span >
176
+ Authorization URL:{ ' ' }
177
+ < OpenAPICopyButton
178
+ value = { flow . authorizationUrl }
179
+ context = { context }
180
+ className = "openapi-securities-url"
181
+ withTooltip
182
+ >
183
+ { flow . authorizationUrl }
184
+ </ OpenAPICopyButton >
185
+ </ span >
186
+ ) : null }
187
+ { 'tokenUrl' in flow && flow . tokenUrl ? (
188
+ < span >
189
+ Token URL:{ ' ' }
190
+ < OpenAPICopyButton
191
+ value = { flow . tokenUrl }
192
+ context = { context }
193
+ className = "openapi-securities-url"
194
+ withTooltip
195
+ >
196
+ { flow . tokenUrl }
197
+ </ OpenAPICopyButton >
198
+ </ span >
199
+ ) : null }
200
+ { 'refreshUrl' in flow && flow . refreshUrl ? (
201
+ < span >
202
+ Refresh URL:{ ' ' }
203
+ < OpenAPICopyButton
204
+ value = { flow . refreshUrl }
205
+ context = { context }
206
+ className = "openapi-securities-url"
207
+ withTooltip
208
+ >
209
+ { flow . refreshUrl }
210
+ </ OpenAPICopyButton >
211
+ </ span >
212
+ ) : null }
213
+ { scopes . length ? (
214
+ < div >
215
+ { t ( context . translation , 'available_scopes' ) } :{ ' ' }
216
+ < ul >
217
+ { scopes . map ( ( [ key , value ] ) => (
218
+ < li key = { key } >
219
+ < OpenAPICopyButton value = { key } context = { context } withTooltip >
220
+ < code > { key } </ code >
221
+ </ OpenAPICopyButton >
222
+ : { value }
223
+ </ li >
224
+ ) ) }
225
+ </ ul >
226
+ </ div >
227
+ ) : null }
228
+ </ div >
229
+ </ div >
230
+ ) ;
231
+ }
0 commit comments