File tree Expand file tree Collapse file tree 3 files changed +52
-19
lines changed
packages/react-openapi/src Expand file tree Collapse file tree 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: {
3636 />
3737 </ OpenAPIDisclosure >
3838 ) : 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+ ) }
4648 </ div >
4749 ) ;
4850}
Original file line number Diff line number Diff line change @@ -21,7 +21,42 @@ export function OpenAPIResponses(props: {
2121 icon = { context . icons . chevronRight }
2222 groups = { Object . entries ( responses ) . map (
2323 ( [ 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+
2560 const description = response . description ;
2661
2762 return {
@@ -39,17 +74,7 @@ export function OpenAPIResponses(props: {
3974 ) : null }
4075 </ div >
4176 ) ,
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,
5378 } ;
5479 }
5580 ) }
You can’t perform that action at this time.
0 commit comments