@@ -242,38 +242,52 @@ function OpenAPISchemaEnum(props: {
242
242
} ) {
243
243
const { schema } = props ;
244
244
245
- if ( ! schema . enum || ! schema . enum . length || ! schema [ 'x-enumDescriptions' ] ) {
245
+ if ( ! schema . enum ?. length || ( ! schema [ 'x-enumDescriptions' ] && ! schema [ 'x-gitbook-enum' ] ) ) {
246
246
return null ;
247
247
}
248
248
249
249
const enumValues = ( ( ) => {
250
+ // Render x-gitbook-enum first, as it has a different format
251
+ if ( schema [ 'x-gitbook-enum' ] ) {
252
+ return Object . entries ( schema [ 'x-gitbook-enum' ] ) . map ( ( [ name , { description } ] ) => {
253
+ return {
254
+ value : name ,
255
+ description,
256
+ } ;
257
+ } ) ;
258
+ }
259
+
260
+ if ( schema [ 'x-enumDescriptions' ] ) {
261
+ return Object . entries ( schema [ 'x-enumDescriptions' ] ) . map ( ( [ value , description ] ) => {
262
+ return {
263
+ value,
264
+ description,
265
+ } ;
266
+ } ) ;
267
+ }
268
+
250
269
return schema . enum . map ( ( value ) => {
251
270
return {
252
271
value,
253
- description : schema [ 'x-enumDescriptions' ] ?. [ value ] ,
272
+ description : undefined ,
254
273
} ;
255
274
} ) ;
256
275
} ) ( ) ;
257
276
258
277
return (
259
278
< div className = "openapi-schema-enum" >
260
- < span >
261
- Options: { ' ' }
279
+ < span > Available options: </ span >
280
+ < div className = "openapi-schema-enum-list" >
262
281
{ enumValues . map ( ( item , index ) => (
263
282
< span key = { index } className = "openapi-schema-enum-value" >
264
- { item . description ? (
265
- < OpenAPITooltip label = { item . description } delay = { 200 } >
266
- < OpenAPITooltip . Button className = "cursor-default" >
267
- < code > { `${ item . value } ` } </ code >
268
- </ OpenAPITooltip . Button >
269
- </ OpenAPITooltip >
270
- ) : (
271
- < code > { `${ item . value } ` } </ code >
272
- ) }
273
- { index < enumValues . length - 1 ? ', ' : '' }
283
+ < OpenAPITooltip label = { item . description } delay = { 200 } >
284
+ < OpenAPITooltip . Button className = "cursor-default" >
285
+ < code > { `${ item . value } ` } </ code >
286
+ </ OpenAPITooltip . Button >
287
+ </ OpenAPITooltip >
274
288
</ span >
275
289
) ) }
276
- </ span >
290
+ </ div >
277
291
</ div >
278
292
) ;
279
293
}
@@ -443,7 +457,7 @@ function getSchemaTitle(schema: OpenAPIV3.SchemaObject): string {
443
457
// Otherwise try to infer a nice title
444
458
let type = 'any' ;
445
459
446
- if ( schema . enum ) {
460
+ if ( schema . enum || schema [ 'x-enumDescriptions' ] || schema [ 'x-gitbook-enum' ] ) {
447
461
type = `${ schema . type } · enum` ;
448
462
// check array AND schema.items as this is sometimes null despite what the type indicates
449
463
} else if ( schema . type === 'array' && ! ! schema . items ) {
0 commit comments