-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathOpenAPIRequestBody.tsx
40 lines (37 loc) · 1.24 KB
/
OpenAPIRequestBody.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
import { InteractiveSection } from './InteractiveSection';
import { OpenAPIRootSchema } from './OpenAPISchema';
import type { OpenAPIClientContext } from './types';
import { checkIsReference } from './utils';
/**
* Display an interactive request body.
*/
export function OpenAPIRequestBody(props: {
requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
context: OpenAPIClientContext;
}) {
const { requestBody, context } = props;
if (checkIsReference(requestBody)) {
return null;
}
return (
<InteractiveSection
header="Body"
className="openapi-requestbody"
tabs={Object.entries(requestBody.content ?? {}).map(
([contentType, mediaTypeObject]) => {
return {
key: contentType,
label: contentType,
body: (
<OpenAPIRootSchema
schema={mediaTypeObject.schema ?? {}}
context={context}
/>
),
};
}
)}
/>
);
}