Files
gitbook/packages/react-openapi/src/OpenAPIRequestBody.tsx
T
Samy Pessé f8fde8cec8 OpenAPI improvements (#127)
* Fix display of authentication infos

* Fix property names

* Fix body / request starting with oneOf

* CSS fixes

* Show description

* Format

* Fix code samples
2024-01-31 14:36:20 +01:00

45 lines
1.4 KiB
TypeScript

import { OpenAPIV3 } from 'openapi-types';
import { OpenAPIRootSchema } from './OpenAPISchema';
import { noReference } from './utils';
import { OpenAPIClientContext } from './types';
import { InteractiveSection } from './InteractiveSection';
import { Markdown } from './Markdown';
/**
* Display an interactive request body.
*/
export function OpenAPIRequestBody(props: {
requestBody: OpenAPIV3.RequestBodyObject;
context: OpenAPIClientContext;
}) {
const { requestBody, context } = props;
return (
<InteractiveSection
header="Body"
className="openapi-requestbody"
tabs={Object.entries(requestBody.content ?? {}).map(
([contentType, mediaTypeObject]) => {
return {
key: contentType,
label: contentType,
body: (
<OpenAPIRootSchema
schema={noReference(mediaTypeObject.schema) ?? {}}
context={context}
/>
),
};
},
)}
>
{requestBody.description ? (
<Markdown
source={requestBody.description}
className="openapi-requestbody-description"
/>
) : null}
</InteractiveSection>
);
}