Fix missing headers in OpenAPIResponses (#3074)

This commit is contained in:
Nolann B.
2025-04-01 21:57:36 +02:00
committed by GitHub
parent 432da64919
commit da7b369ffd
3 changed files with 52 additions and 19 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@gitbook/react-openapi': patch
'gitbook': patch
---
Fix missing headers in OpenAPIResponses
@@ -36,13 +36,15 @@ export function OpenAPIResponse(props: {
/>
</OpenAPIDisclosure>
) : null}
<div className="openapi-responsebody">
<OpenAPISchemaProperties
id={`response-${context.blockKey}`}
properties={mediaType.schema ? [{ schema: mediaType.schema }] : []}
context={context}
/>
</div>
{mediaType.schema && (
<div className="openapi-responsebody">
<OpenAPISchemaProperties
id={`response-${context.blockKey}`}
properties={[{ schema: mediaType.schema }]}
context={context}
/>
</div>
)}
</div>
);
}
+37 -12
View File
@@ -21,7 +21,42 @@ export function OpenAPIResponses(props: {
icon={context.icons.chevronRight}
groups={Object.entries(responses).map(
([statusCode, response]: [string, OpenAPIV3.ResponseObject]) => {
const content = Object.entries(response.content ?? {});
const tabs = (() => {
// If there is no content, but there are headers, we need to show the headers
if (
(!response.content || !Object.keys(response.content).length) &&
response.headers &&
Object.keys(response.headers).length
) {
return [
{
id: 'default',
body: (
<OpenAPIResponse
response={response}
mediaType={{}}
context={context}
/>
),
},
];
}
return Object.entries(response.content ?? {}).map(
([contentType, mediaType]) => ({
id: contentType,
label: contentType,
body: (
<OpenAPIResponse
response={response}
mediaType={mediaType}
context={context}
/>
),
})
);
})();
const description = response.description;
return {
@@ -39,17 +74,7 @@ export function OpenAPIResponses(props: {
) : null}
</div>
),
tabs: content.map(([contentType, mediaType]) => ({
id: contentType,
label: contentType,
body: (
<OpenAPIResponse
response={response}
mediaType={mediaType}
context={context}
/>
),
})),
tabs,
};
}
)}