'use client';
import clsx from 'classnames';
import type { OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
import type { OpenAPIClientContext } from './context';
import { Markdown } from './Markdown';
import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
import { OpenAPIResponse } from './OpenAPIResponse';
import { useResponseExamplesState } from './OpenAPIResponseExampleContent';
import type { Key } from './OpenAPISelect';
import { StaticSection } from './StaticSection';
import { t } from './translate';
import {
createStateKey,
getStatusCodeClassName,
getStatusCodeDefaultLabel,
resolveDescription,
} from './utils';
/**
* Display an interactive response body.
*/
export function OpenAPIResponses(props: {
responses: OpenAPIV3.ResponsesObject | OpenAPIV3_1.ResponsesObject;
context: OpenAPIClientContext;
}) {
const { responses, context } = props;
const groups = Object.entries(responses)
.filter(([_, response]) => response && typeof response === 'object')
.map(([statusCode, response]: [string, OpenAPIV3.ResponseObject]) => {
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 [
{
key: 'default',
label: '',
body: (
{t(context.translation, 'no_content')}
),
},
];
}
return Object.entries(response.content ?? {}).map(([contentType, mediaType]) => ({
key: contentType,
label: contentType,
body: (