@@ -6,8 +6,8 @@ import { OpenAPIResponseExampleContent } from './OpenAPIResponseExampleContent';
6
6
import { type OpenAPIContext , getOpenAPIClientContext } from './context' ;
7
7
import type { OpenAPIOperationData , OpenAPIWebhookData } from './types' ;
8
8
import { getExampleFromReference , getExamples } from './util/example' ;
9
- import { createStateKey , getStatusCodeDefaultLabel } from './utils' ;
10
- import { checkIsReference , resolveDescription } from './utils' ;
9
+ import { createStateKey , getStatusCodeDefaultLabel , resolveDescription } from './utils' ;
10
+ import { checkIsReference } from './utils' ;
11
11
12
12
/**
13
13
* Display an example of the response content.
@@ -41,45 +41,47 @@ export function OpenAPIResponseExample(props: {
41
41
return Number ( a ) - Number ( b ) ;
42
42
} ) ;
43
43
44
- const tabs = responses . map ( ( [ key , responseObject ] ) => {
45
- const description = resolveDescription ( responseObject ) ;
46
- const label = description ? (
47
- < Markdown source = { description } />
48
- ) : (
49
- getStatusCodeDefaultLabel ( key , context )
50
- ) ;
44
+ const tabs = responses
45
+ . filter ( ( [ _ , responseObject ] ) => responseObject && typeof responseObject === 'object' )
46
+ . map ( ( [ key , responseObject ] ) => {
47
+ const description = resolveDescription ( responseObject ) ;
48
+ const label = description ? (
49
+ < Markdown source = { description } />
50
+ ) : (
51
+ getStatusCodeDefaultLabel ( key , context )
52
+ ) ;
51
53
52
- if ( checkIsReference ( responseObject ) ) {
53
- return {
54
- key : key ,
55
- label,
56
- statusCode : key ,
57
- body : (
58
- < OpenAPIExample
59
- example = { getExampleFromReference ( responseObject , context ) }
60
- context = { context }
61
- syntax = "json"
62
- />
63
- ) ,
64
- } ;
65
- }
54
+ if ( checkIsReference ( responseObject ) ) {
55
+ return {
56
+ key : key ,
57
+ label,
58
+ statusCode : key ,
59
+ body : (
60
+ < OpenAPIExample
61
+ example = { getExampleFromReference ( responseObject , context ) }
62
+ context = { context }
63
+ syntax = "json"
64
+ />
65
+ ) ,
66
+ } ;
67
+ }
68
+
69
+ if ( ! responseObject . content || Object . keys ( responseObject . content ) . length === 0 ) {
70
+ return {
71
+ key : key ,
72
+ label,
73
+ statusCode : key ,
74
+ body : < OpenAPIEmptyExample context = { context } /> ,
75
+ } ;
76
+ }
66
77
67
- if ( ! responseObject . content || Object . keys ( responseObject . content ) . length === 0 ) {
68
78
return {
69
79
key : key ,
70
80
label,
71
81
statusCode : key ,
72
- body : < OpenAPIEmptyExample context = { context } /> ,
82
+ body : < OpenAPIResponse context = { context } content = { responseObject . content } /> ,
73
83
} ;
74
- }
75
-
76
- return {
77
- key : key ,
78
- label,
79
- statusCode : key ,
80
- body : < OpenAPIResponse context = { context } content = { responseObject . content } /> ,
81
- } ;
82
- } ) ;
84
+ } ) ;
83
85
84
86
if ( tabs . length === 0 ) {
85
87
return null ;
0 commit comments