File tree 3 files changed +52
-19
lines changed
packages/react-openapi/src
3 files changed +52
-19
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @gitbook/react-openapi ' : patch
3
+ ' gitbook ' : patch
4
+ ---
5
+
6
+ Fix missing headers in OpenAPIResponses
Original file line number Diff line number Diff line change @@ -36,13 +36,15 @@ export function OpenAPIResponse(props: {
36
36
/>
37
37
</ OpenAPIDisclosure >
38
38
) : null }
39
- < div className = "openapi-responsebody" >
40
- < OpenAPISchemaProperties
41
- id = { `response-${ context . blockKey } ` }
42
- properties = { mediaType . schema ? [ { schema : mediaType . schema } ] : [ ] }
43
- context = { context }
44
- />
45
- </ div >
39
+ { mediaType . schema && (
40
+ < div className = "openapi-responsebody" >
41
+ < OpenAPISchemaProperties
42
+ id = { `response-${ context . blockKey } ` }
43
+ properties = { [ { schema : mediaType . schema } ] }
44
+ context = { context }
45
+ />
46
+ </ div >
47
+ ) }
46
48
</ div >
47
49
) ;
48
50
}
Original file line number Diff line number Diff line change @@ -21,7 +21,42 @@ export function OpenAPIResponses(props: {
21
21
icon = { context . icons . chevronRight }
22
22
groups = { Object . entries ( responses ) . map (
23
23
( [ statusCode , response ] : [ string , OpenAPIV3 . ResponseObject ] ) => {
24
- const content = Object . entries ( response . content ?? { } ) ;
24
+ const tabs = ( ( ) => {
25
+ // If there is no content, but there are headers, we need to show the headers
26
+ if (
27
+ ( ! response . content || ! Object . keys ( response . content ) . length ) &&
28
+ response . headers &&
29
+ Object . keys ( response . headers ) . length
30
+ ) {
31
+ return [
32
+ {
33
+ id : 'default' ,
34
+ body : (
35
+ < OpenAPIResponse
36
+ response = { response }
37
+ mediaType = { { } }
38
+ context = { context }
39
+ />
40
+ ) ,
41
+ } ,
42
+ ] ;
43
+ }
44
+
45
+ return Object . entries ( response . content ?? { } ) . map (
46
+ ( [ contentType , mediaType ] ) => ( {
47
+ id : contentType ,
48
+ label : contentType ,
49
+ body : (
50
+ < OpenAPIResponse
51
+ response = { response }
52
+ mediaType = { mediaType }
53
+ context = { context }
54
+ />
55
+ ) ,
56
+ } )
57
+ ) ;
58
+ } ) ( ) ;
59
+
25
60
const description = response . description ;
26
61
27
62
return {
@@ -39,17 +74,7 @@ export function OpenAPIResponses(props: {
39
74
) : null }
40
75
</ div >
41
76
) ,
42
- tabs : content . map ( ( [ contentType , mediaType ] ) => ( {
43
- id : contentType ,
44
- label : contentType ,
45
- body : (
46
- < OpenAPIResponse
47
- response = { response }
48
- mediaType = { mediaType }
49
- context = { context }
50
- />
51
- ) ,
52
- } ) ) ,
77
+ tabs,
53
78
} ;
54
79
}
55
80
) }
You can’t perform that action at this time.
0 commit comments