@@ -6,8 +6,8 @@ import { OpenAPIResponseExampleContent } from './OpenAPIResponseExampleContent';
66import { type OpenAPIContext , getOpenAPIClientContext } from './context' ;
77import type { OpenAPIOperationData , OpenAPIWebhookData } from './types' ;
88import { 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' ;
1111
1212/**
1313 * Display an example of the response content.
@@ -41,45 +41,47 @@ export function OpenAPIResponseExample(props: {
4141 return Number ( a ) - Number ( b ) ;
4242 } ) ;
4343
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+ ) ;
5153
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+ }
6677
67- if ( ! responseObject . content || Object . keys ( responseObject . content ) . length === 0 ) {
6878 return {
6979 key : key ,
7080 label,
7181 statusCode : key ,
72- body : < OpenAPIEmptyExample context = { context } /> ,
82+ body : < OpenAPIResponse context = { context } content = { responseObject . content } /> ,
7383 } ;
74- }
75-
76- return {
77- key : key ,
78- label,
79- statusCode : key ,
80- body : < OpenAPIResponse context = { context } content = { responseObject . content } /> ,
81- } ;
82- } ) ;
84+ } ) ;
8385
8486 if ( tabs . length === 0 ) {
8587 return null ;
0 commit comments