-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathOpenAPIRequestBody.tsx
45 lines (42 loc) · 1.61 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
41
42
43
44
45
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
import { InteractiveSection } from './InteractiveSection';
import { OpenAPIRootSchema } from './OpenAPISchemaServer';
import type { OpenAPIClientContext } from './context';
import { t } from './translate';
import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
import { checkIsReference, createStateKey } from './utils';
/**
* Display an interactive request body.
*/
export function OpenAPIRequestBody(props: {
requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
context: OpenAPIClientContext;
data: OpenAPIOperationData | OpenAPIWebhookData;
}) {
const { requestBody, context, data } = props;
if (checkIsReference(requestBody)) {
return null;
}
return (
<InteractiveSection
header={t(context.translation, 'name' in data ? 'payload' : 'body')}
className="openapi-requestbody"
stateKey={createStateKey('request-body-media-type', context.blockKey)}
selectIcon={context.icons.chevronDown}
tabs={Object.entries(requestBody.content ?? {}).map(
([contentType, mediaTypeObject]) => {
return {
key: contentType,
label: contentType,
body: (
<OpenAPIRootSchema
schema={mediaTypeObject.schema ?? {}}
context={context}
/>
),
};
}
)}
/>
);
}