@@ -47,23 +47,6 @@ export function OpenAPISchemaProperty(
47
47
? null
48
48
: getSchemaAlternatives ( schema , new Set ( circularRefs . keys ( ) ) ) ;
49
49
50
- if ( ( properties && properties . length > 0 ) || schema . type === 'object' ) {
51
- return (
52
- < InteractiveSection id = { id } className = { clsx ( 'openapi-schema' , className ) } >
53
- < OpenAPISchemaPresentation { ...props } />
54
- { properties && properties . length > 0 ? (
55
- < OpenAPIDisclosure context = { context } >
56
- < OpenAPISchemaProperties
57
- properties = { properties }
58
- circularRefs = { circularRefs }
59
- context = { context }
60
- />
61
- </ OpenAPIDisclosure >
62
- ) : null }
63
- </ InteractiveSection >
64
- ) ;
65
- }
66
-
67
50
if ( alternatives ?. [ 0 ] ?. length ) {
68
51
return (
69
52
< InteractiveSection id = { id } className = { clsx ( 'openapi-schema' , className ) } >
@@ -80,6 +63,23 @@ export function OpenAPISchemaProperty(
80
63
) ;
81
64
}
82
65
66
+ if ( ( properties && properties . length > 0 ) || schema . type === 'object' ) {
67
+ return (
68
+ < InteractiveSection id = { id } className = { clsx ( 'openapi-schema' , className ) } >
69
+ < OpenAPISchemaPresentation { ...props } />
70
+ { properties && properties . length > 0 ? (
71
+ < OpenAPIDisclosure context = { context } label = { getDisclosureLabel ( schema ) } >
72
+ < OpenAPISchemaProperties
73
+ properties = { properties }
74
+ circularRefs = { circularRefs }
75
+ context = { context }
76
+ />
77
+ </ OpenAPIDisclosure >
78
+ ) : null }
79
+ </ InteractiveSection >
80
+ ) ;
81
+ }
82
+
83
83
return (
84
84
< InteractiveSection id = { id } className = { clsx ( 'openapi-schema' , className ) } >
85
85
< OpenAPISchemaPresentation { ...props } />
@@ -166,16 +166,24 @@ function OpenAPISchemaAlternative(props: {
166
166
const { schema, circularRefs, context } = props ;
167
167
const id = useId ( ) ;
168
168
const subProperties = getSchemaProperties ( schema ) ;
169
+ const description = resolveDescription ( schema ) ;
169
170
170
171
return (
171
- < OpenAPIDisclosure context = { context } >
172
- < OpenAPISchemaProperties
173
- id = { id }
174
- properties = { subProperties ?? [ { schema } ] }
175
- circularRefs = { subProperties ? new Map ( circularRefs ) . set ( schema , id ) : circularRefs }
176
- context = { context }
177
- />
178
- </ OpenAPIDisclosure >
172
+ < >
173
+ { description ? (
174
+ < Markdown source = { description } className = "openapi-schema-description" />
175
+ ) : null }
176
+ < OpenAPIDisclosure context = { context } label = { getDisclosureLabel ( schema ) } >
177
+ < OpenAPISchemaProperties
178
+ id = { id }
179
+ properties = { subProperties ?? [ { schema } ] }
180
+ circularRefs = {
181
+ subProperties ? new Map ( circularRefs ) . set ( schema , id ) : circularRefs
182
+ }
183
+ context = { context }
184
+ />
185
+ </ OpenAPIDisclosure >
186
+ </ >
179
187
) ;
180
188
}
181
189
@@ -219,7 +227,7 @@ export function OpenAPISchemaPresentation(props: OpenAPISchemaPropertyEntry) {
219
227
220
228
const shouldDisplayExample = ( schema : OpenAPIV3 . SchemaObject ) : boolean => {
221
229
return (
222
- typeof schema . example === 'string' ||
230
+ ( typeof schema . example === 'string' && ! ! schema . example ) ||
223
231
typeof schema . example === 'number' ||
224
232
typeof schema . example === 'boolean' ||
225
233
( Array . isArray ( schema . example ) && schema . example . length > 0 ) ||
@@ -234,10 +242,10 @@ export function OpenAPISchemaPresentation(props: OpenAPISchemaPropertyEntry) {
234
242
return (
235
243
< div className = "openapi-schema-presentation" >
236
244
< OpenAPISchemaName
245
+ schema = { schema }
237
246
type = { getSchemaTitle ( schema ) }
238
247
propertyName = { propertyName }
239
248
required = { required }
240
- deprecated = { schema . deprecated }
241
249
/>
242
250
{ schema [ 'x-deprecated-sunset' ] ? (
243
251
< div className = "openapi-deprecated-sunset openapi-schema-description openapi-markdown" >
@@ -276,17 +284,6 @@ export function OpenAPISchemaPresentation(props: OpenAPISchemaPropertyEntry) {
276
284
* Get the sub-properties of a schema.
277
285
*/
278
286
function getSchemaProperties ( schema : OpenAPIV3 . SchemaObject ) : null | OpenAPISchemaPropertyEntry [ ] {
279
- if ( schema . allOf ) {
280
- return schema . allOf . reduce ( ( acc , subSchema ) => {
281
- const properties = getSchemaProperties ( subSchema ) ?? [
282
- {
283
- schema : subSchema ,
284
- } ,
285
- ] ;
286
- return [ ...acc , ...properties ] ;
287
- } , [ ] as OpenAPISchemaPropertyEntry [ ] ) ;
288
- }
289
-
290
287
// check array AND schema.items as this is sometimes null despite what the type indicates
291
288
if ( schema . type === 'array' && ! ! schema . items ) {
292
289
const items = schema . items ;
@@ -295,6 +292,11 @@ function getSchemaProperties(schema: OpenAPIV3.SchemaObject): null | OpenAPISche
295
292
return itemProperties ;
296
293
}
297
294
295
+ // If the items are a primitive type, we don't need to display them
296
+ if ( [ 'string' , 'number' , 'boolean' , 'integer' ] . includes ( items . type ) && ! items . enum ) {
297
+ return null ;
298
+ }
299
+
298
300
return [
299
301
{
300
302
propertyName : 'items' ,
@@ -351,8 +353,7 @@ export function getSchemaAlternatives(
351
353
}
352
354
353
355
if ( schema . allOf ) {
354
- // allOf is managed in `getSchemaProperties`
355
- return null ;
356
+ return [ flattenAlternatives ( 'allOf' , schema . allOf , downAncestors ) , schema . discriminator ] ;
356
357
}
357
358
358
359
return null ;
@@ -378,11 +379,6 @@ export function getSchemaTitle(
378
379
/** If the title is inferred in a oneOf with discriminator, we can use it to optimize the title */
379
380
discriminator ?: OpenAPIV3 . DiscriminatorObject ,
380
381
) : string {
381
- if ( schema . title ) {
382
- // If the schema has a title, use it
383
- return schema . title ;
384
- }
385
-
386
382
// Try using the discriminator
387
383
if ( discriminator ?. propertyName && schema . properties ) {
388
384
const discriminatorProperty = schema . properties [ discriminator . propertyName ] ;
@@ -419,21 +415,22 @@ export function getSchemaTitle(
419
415
type = 'not' ;
420
416
}
421
417
422
- if ( schema . minimum || schema . minLength ) {
423
- type += ` · min: ${ schema . minimum || schema . minLength } ` ;
424
- }
418
+ return type ;
419
+ }
425
420
426
- if ( schema . maximum || schema . maxLength ) {
427
- type += ` · max: ${ schema . maximum || schema . maxLength } ` ;
428
- }
421
+ function getDisclosureLabel ( schema : OpenAPIV3 . SchemaObject ) : string | undefined {
422
+ if ( schema . type === 'array' && ! ! schema . items ) {
423
+ if ( schema . items . oneOf ) {
424
+ return 'available items' ;
425
+ }
429
426
430
- if ( schema . default ) {
431
- type += ` · default: ${ schema . default } ` ;
432
- }
427
+ // Fallback to "child attributes" for enums and objects
428
+ if ( schema . items . enum || schema . items . type === 'object' ) {
429
+ return ;
430
+ }
433
431
434
- if ( schema . nullable ) {
435
- type = `${ type } | nullable` ;
432
+ return schema . items . title ?? schema . title ?? getSchemaTitle ( schema . items ) ;
436
433
}
437
434
438
- return type ;
435
+ return schema . title ;
439
436
}
0 commit comments