@gitbook/react-openapi 1.1.10 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/InteractiveSection.d.ts +4 -0
- package/dist/InteractiveSection.jsx +11 -11
- package/dist/OpenAPICodeSample.d.ts +2 -1
- package/dist/OpenAPICodeSample.jsx +6 -5
- package/dist/OpenAPICodeSampleInteractive.d.ts +3 -0
- package/dist/OpenAPICodeSampleInteractive.jsx +19 -43
- package/dist/OpenAPICodeSampleSelector.d.ts +3 -4
- package/dist/OpenAPICodeSampleSelector.jsx +6 -11
- package/dist/OpenAPICopyButton.d.ts +2 -0
- package/dist/OpenAPICopyButton.jsx +5 -2
- package/dist/OpenAPIDisclosure.d.ts +4 -3
- package/dist/OpenAPIDisclosure.jsx +8 -11
- package/dist/OpenAPIDisclosureGroup.d.ts +7 -3
- package/dist/OpenAPIDisclosureGroup.jsx +18 -18
- package/dist/OpenAPIExample.d.ts +4 -22
- package/dist/OpenAPIExample.jsx +5 -72
- package/dist/OpenAPIMediaType.d.ts +21 -0
- package/dist/OpenAPIMediaType.jsx +61 -0
- package/dist/OpenAPIOperation.d.ts +3 -2
- package/dist/OpenAPIOperation.jsx +9 -68
- package/dist/OpenAPIOperationDescription.d.ts +9 -0
- package/dist/OpenAPIOperationDescription.jsx +22 -0
- package/dist/OpenAPIOperationStability.d.ts +9 -0
- package/dist/OpenAPIOperationStability.jsx +27 -0
- package/dist/OpenAPIPath.d.ts +2 -0
- package/dist/OpenAPIPath.jsx +3 -2
- package/dist/OpenAPIRequestBody.d.ts +3 -1
- package/dist/OpenAPIRequestBody.jsx +4 -3
- package/dist/OpenAPIResponse.d.ts +1 -1
- package/dist/OpenAPIResponse.jsx +1 -1
- package/dist/OpenAPIResponseExample.d.ts +3 -2
- package/dist/OpenAPIResponseExample.jsx +24 -63
- package/dist/OpenAPIResponseExampleContent.d.ts +19 -0
- package/dist/OpenAPIResponseExampleContent.jsx +57 -0
- package/dist/OpenAPIResponses.d.ts +1 -1
- package/dist/OpenAPIResponses.jsx +49 -36
- package/dist/OpenAPISchema.d.ts +1 -1
- package/dist/OpenAPISchema.jsx +103 -15
- package/dist/OpenAPISchemaName.d.ts +2 -0
- package/dist/OpenAPISchemaName.jsx +19 -10
- package/dist/OpenAPISchemaServer.d.ts +1 -1
- package/dist/OpenAPISecurities.d.ts +2 -1
- package/dist/OpenAPISecurities.jsx +11 -10
- package/dist/OpenAPISelect.d.ts +10 -3
- package/dist/OpenAPISelect.jsx +20 -9
- package/dist/OpenAPISpec.d.ts +3 -2
- package/dist/OpenAPISpec.jsx +11 -9
- package/dist/OpenAPIWebhook.d.ts +10 -0
- package/dist/OpenAPIWebhook.jsx +23 -0
- package/dist/OpenAPIWebhookExample.d.ts +6 -0
- package/dist/OpenAPIWebhookExample.jsx +41 -0
- package/dist/ScalarApiButton.d.ts +2 -0
- package/dist/ScalarApiButton.jsx +4 -3
- package/dist/StaticSection.d.ts +4 -1
- package/dist/StaticSection.jsx +13 -4
- package/dist/code-samples.js +57 -39
- package/dist/common/OpenAPIColumnSpec.d.ts +6 -0
- package/dist/common/OpenAPIColumnSpec.jsx +20 -0
- package/dist/common/OpenAPIOperationDescription.d.ts +6 -0
- package/dist/common/OpenAPIOperationDescription.jsx +19 -0
- package/dist/common/OpenAPIStability.d.ts +4 -0
- package/dist/common/OpenAPIStability.jsx +15 -0
- package/dist/common/OpenAPISummary.d.ts +6 -0
- package/dist/common/OpenAPISummary.jsx +30 -0
- package/dist/context.d.ts +23 -2
- package/dist/context.js +32 -0
- package/dist/getOrCreateStoreByKey.d.ts +1 -1
- package/dist/getOrCreateStoreByKey.js +0 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +3 -0
- package/dist/resolveOpenAPIWebhook.d.ts +11 -0
- package/dist/resolveOpenAPIWebhook.js +127 -0
- package/dist/schemas/OpenAPISchemas.d.ts +2 -2
- package/dist/schemas/OpenAPISchemas.jsx +19 -23
- package/dist/stringifyOpenAPI.d.ts +1 -1
- package/dist/stringifyOpenAPI.js +6 -3
- package/dist/translate.d.ts +10 -0
- package/dist/translate.jsx +75 -0
- package/dist/translations/de.d.ts +37 -0
- package/dist/translations/de.js +37 -0
- package/dist/translations/en.d.ts +37 -0
- package/dist/translations/en.js +37 -0
- package/dist/translations/es.d.ts +37 -0
- package/dist/translations/es.js +37 -0
- package/dist/translations/fr.d.ts +37 -0
- package/dist/translations/fr.js +37 -0
- package/dist/translations/index.d.ts +341 -0
- package/dist/translations/index.js +27 -0
- package/dist/translations/ja.d.ts +37 -0
- package/dist/translations/ja.js +37 -0
- package/dist/translations/nl.d.ts +37 -0
- package/dist/translations/nl.js +37 -0
- package/dist/translations/no.d.ts +37 -0
- package/dist/translations/no.js +37 -0
- package/dist/translations/pt-br.d.ts +37 -0
- package/dist/translations/pt-br.js +37 -0
- package/dist/translations/types.d.ts +5 -0
- package/dist/translations/types.js +1 -0
- package/dist/translations/zh.d.ts +37 -0
- package/dist/translations/zh.js +37 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types.d.ts +8 -50
- package/dist/util/example.d.ts +35 -0
- package/dist/util/example.jsx +103 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +57 -0
- package/package.json +3 -3
- package/src/InteractiveSection.tsx +16 -14
- package/src/OpenAPICodeSample.tsx +22 -4
- package/src/OpenAPICodeSampleInteractive.tsx +38 -58
- package/src/OpenAPICodeSampleSelector.tsx +19 -12
- package/src/OpenAPICopyButton.tsx +7 -2
- package/src/OpenAPIDisclosure.tsx +20 -22
- package/src/OpenAPIDisclosureGroup.tsx +41 -22
- package/src/OpenAPIExample.tsx +8 -82
- package/src/OpenAPIMediaType.tsx +139 -0
- package/src/OpenAPIOperation.tsx +11 -100
- package/src/OpenAPIOperationDescription.tsx +34 -0
- package/src/OpenAPIOperationStability.tsx +39 -0
- package/src/OpenAPIPath.tsx +4 -1
- package/src/OpenAPIRequestBody.tsx +9 -4
- package/src/OpenAPIResponse.tsx +2 -2
- package/src/OpenAPIResponseExample.tsx +39 -108
- package/src/OpenAPIResponseExampleContent.tsx +123 -0
- package/src/OpenAPIResponses.tsx +84 -62
- package/src/OpenAPISchema.test.ts +80 -0
- package/src/OpenAPISchema.tsx +123 -16
- package/src/OpenAPISchemaName.tsx +26 -11
- package/src/OpenAPISchemaServer.tsx +1 -1
- package/src/OpenAPISecurities.tsx +33 -12
- package/src/OpenAPISelect.tsx +42 -16
- package/src/OpenAPISpec.tsx +21 -10
- package/src/OpenAPIWebhook.tsx +33 -0
- package/src/OpenAPIWebhookExample.tsx +60 -0
- package/src/ScalarApiButton.tsx +6 -6
- package/src/StaticSection.tsx +37 -5
- package/src/code-samples.test.ts +3 -1
- package/src/code-samples.ts +67 -54
- package/src/common/OpenAPIColumnSpec.tsx +31 -0
- package/src/common/OpenAPIOperationDescription.tsx +31 -0
- package/src/common/OpenAPIStability.tsx +23 -0
- package/src/common/OpenAPISummary.tsx +45 -0
- package/src/context.ts +37 -2
- package/src/getOrCreateStoreByKey.ts +1 -3
- package/src/index.ts +5 -1
- package/src/resolveOpenAPIWebhook.ts +99 -0
- package/src/schemas/OpenAPISchemas.tsx +34 -34
- package/src/stringifyOpenAPI.ts +11 -3
- package/src/translate.tsx +80 -0
- package/src/translations/de.ts +37 -0
- package/src/translations/en.ts +37 -0
- package/src/translations/es.ts +37 -0
- package/src/translations/fr.ts +37 -0
- package/src/translations/index.ts +33 -0
- package/src/translations/ja.ts +37 -0
- package/src/translations/nl.ts +37 -0
- package/src/translations/no.ts +37 -0
- package/src/translations/pt-br.ts +37 -0
- package/src/translations/types.ts +7 -0
- package/src/translations/zh.ts +37 -0
- package/src/types.ts +11 -53
- package/src/util/example.tsx +129 -0
- package/src/utils.ts +67 -0
package/dist/OpenAPIExample.jsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { generateSchemaExample } from './generateSchemaExample';
|
|
2
1
|
import { json2xml } from './json2xml';
|
|
3
2
|
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
4
|
-
import {
|
|
3
|
+
import { t } from './translate';
|
|
5
4
|
/**
|
|
6
5
|
* Display an example.
|
|
7
6
|
*/
|
|
@@ -9,7 +8,7 @@ export function OpenAPIExample(props) {
|
|
|
9
8
|
var example = props.example, context = props.context, syntax = props.syntax;
|
|
10
9
|
var code = stringifyExample({ example: example, xml: syntax === 'xml' });
|
|
11
10
|
if (code === null) {
|
|
12
|
-
return <OpenAPIEmptyExample />;
|
|
11
|
+
return <OpenAPIEmptyExample context={context}/>;
|
|
13
12
|
}
|
|
14
13
|
return context.renderCodeBlock({ code: code, syntax: syntax });
|
|
15
14
|
}
|
|
@@ -29,75 +28,9 @@ function stringifyExample(args) {
|
|
|
29
28
|
/**
|
|
30
29
|
* Empty response example.
|
|
31
30
|
*/
|
|
32
|
-
export function OpenAPIEmptyExample() {
|
|
31
|
+
export function OpenAPIEmptyExample(props) {
|
|
32
|
+
var context = props.context;
|
|
33
33
|
return (<pre className="openapi-example-empty">
|
|
34
|
-
<p>
|
|
34
|
+
<p>{t(context.translation, 'no_content')}</p>
|
|
35
35
|
</pre>);
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Generate an example from a reference object.
|
|
39
|
-
*/
|
|
40
|
-
export function getExampleFromReference(ref) {
|
|
41
|
-
return { summary: 'Unresolved reference', value: { $ref: ref.$ref } };
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Get examples from a media type object.
|
|
45
|
-
*/
|
|
46
|
-
export function getExamplesFromMediaTypeObject(args) {
|
|
47
|
-
var _a;
|
|
48
|
-
var _b, _c;
|
|
49
|
-
var mediaTypeObject = args.mediaTypeObject, mediaType = args.mediaType;
|
|
50
|
-
if (mediaTypeObject.examples) {
|
|
51
|
-
return Object.entries(mediaTypeObject.examples).map(function (_a) {
|
|
52
|
-
var key = _a[0], example = _a[1];
|
|
53
|
-
return {
|
|
54
|
-
key: key,
|
|
55
|
-
example: checkIsReference(example) ? getExampleFromReference(example) : example,
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
if (mediaTypeObject.example) {
|
|
60
|
-
return [{ key: 'default', example: { value: mediaTypeObject.example } }];
|
|
61
|
-
}
|
|
62
|
-
if (mediaTypeObject.schema) {
|
|
63
|
-
if (mediaType === 'application/xml') {
|
|
64
|
-
// @TODO normally we should use the name of the schema but we don't have it
|
|
65
|
-
// fix it when we got the reference name
|
|
66
|
-
var root = (_c = (_b = mediaTypeObject.schema.xml) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : 'object';
|
|
67
|
-
return [
|
|
68
|
-
{
|
|
69
|
-
key: 'default',
|
|
70
|
-
example: {
|
|
71
|
-
value: (_a = {},
|
|
72
|
-
_a[root] = generateSchemaExample(mediaTypeObject.schema, {
|
|
73
|
-
xml: mediaType === 'application/xml',
|
|
74
|
-
mode: 'read',
|
|
75
|
-
}),
|
|
76
|
-
_a),
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
];
|
|
80
|
-
}
|
|
81
|
-
return [
|
|
82
|
-
{
|
|
83
|
-
key: 'default',
|
|
84
|
-
example: {
|
|
85
|
-
value: generateSchemaExample(mediaTypeObject.schema, {
|
|
86
|
-
mode: 'read',
|
|
87
|
-
}),
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
return [];
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Get example from a schema object.
|
|
96
|
-
*/
|
|
97
|
-
export function getExampleFromSchema(args) {
|
|
98
|
-
var schema = args.schema;
|
|
99
|
-
if (schema.example) {
|
|
100
|
-
return { value: schema.example };
|
|
101
|
-
}
|
|
102
|
-
return { value: generateSchemaExample(schema, { mode: 'read' }) };
|
|
103
|
-
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Key } from 'react-aria';
|
|
2
|
+
import { OpenAPISelectItem } from './OpenAPISelect';
|
|
3
|
+
import type { OpenAPIClientContext } from './context';
|
|
4
|
+
type OpenAPIMediaTypeItem = OpenAPISelectItem & {
|
|
5
|
+
body: React.ReactNode;
|
|
6
|
+
examples?: OpenAPIMediaTypeItem[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Get the state of the response examples select.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useMediaTypesState(stateKey: string | undefined, initialKey?: Key): {
|
|
12
|
+
key: (string | number) | null;
|
|
13
|
+
setKey: (key: Key | null) => void;
|
|
14
|
+
};
|
|
15
|
+
export declare function OpenAPIMediaTypeContent(props: {
|
|
16
|
+
items: OpenAPIMediaTypeItem[];
|
|
17
|
+
selectIcon?: React.ReactNode;
|
|
18
|
+
stateKey: string;
|
|
19
|
+
context: OpenAPIClientContext;
|
|
20
|
+
}): import("react").JSX.Element | null;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { OpenAPIEmptyExample } from './OpenAPIExample';
|
|
3
|
+
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
|
|
4
|
+
import { StaticSection } from './StaticSection';
|
|
5
|
+
/**
|
|
6
|
+
* Get the state of the response examples select.
|
|
7
|
+
*/
|
|
8
|
+
export function useMediaTypesState(stateKey, initialKey) {
|
|
9
|
+
if (initialKey === void 0) { initialKey = 'default'; }
|
|
10
|
+
return useSelectState(stateKey, initialKey);
|
|
11
|
+
}
|
|
12
|
+
function useMediaTypeExamplesState(stateKey, initialKey) {
|
|
13
|
+
if (initialKey === void 0) { initialKey = 'default'; }
|
|
14
|
+
return useSelectState(stateKey, initialKey);
|
|
15
|
+
}
|
|
16
|
+
export function OpenAPIMediaTypeContent(props) {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
var stateKey = props.stateKey, items = props.items, selectIcon = props.selectIcon, context = props.context;
|
|
19
|
+
var state = useMediaTypesState(stateKey, (_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
|
|
20
|
+
var examples = (_c = (_b = items.find(function (item) { return item.key === state.key; })) === null || _b === void 0 ? void 0 : _b.examples) !== null && _c !== void 0 ? _c : [];
|
|
21
|
+
if (!items.length && !examples.length) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return (<StaticSection footer={items.length > 1 || examples.length > 1 ? (<OpenAPIMediaTypeFooter items={items} examples={examples} selectIcon={selectIcon} stateKey={stateKey}/>) : null} className="openapi-response-media-types-examples">
|
|
25
|
+
<OpenAPIMediaTypeBody context={context} stateKey={stateKey} items={items} examples={examples}/>
|
|
26
|
+
</StaticSection>);
|
|
27
|
+
}
|
|
28
|
+
function OpenAPIMediaTypeFooter(props) {
|
|
29
|
+
var items = props.items, examples = props.examples, stateKey = props.stateKey, selectIcon = props.selectIcon;
|
|
30
|
+
return (<>
|
|
31
|
+
{items.length > 1 && (<OpenAPISelect icon={selectIcon} items={items} stateKey={stateKey} placement="bottom start">
|
|
32
|
+
{items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
|
|
33
|
+
<span>{item.label}</span>
|
|
34
|
+
</OpenAPISelectItem>); })}
|
|
35
|
+
</OpenAPISelect>)}
|
|
36
|
+
|
|
37
|
+
{examples && examples.length > 1 ? (<OpenAPISelect icon={selectIcon} items={examples} stateKey={"".concat(stateKey, "-examples")} placement="bottom start">
|
|
38
|
+
{examples.map(function (example) { return (<OpenAPISelectItem key={example.key} id={example.key} value={example}>
|
|
39
|
+
<span>{example.label}</span>
|
|
40
|
+
</OpenAPISelectItem>); })}
|
|
41
|
+
</OpenAPISelect>) : null}
|
|
42
|
+
</>);
|
|
43
|
+
}
|
|
44
|
+
function OpenAPIMediaTypeBody(props) {
|
|
45
|
+
var _a, _b, _c, _d, _e;
|
|
46
|
+
var stateKey = props.stateKey, items = props.items, examples = props.examples, context = props.context;
|
|
47
|
+
var state = useMediaTypesState(stateKey, (_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
|
|
48
|
+
var selectedItem = (_b = items.find(function (item) { return item.key === state.key; })) !== null && _b !== void 0 ? _b : items[0];
|
|
49
|
+
var exampleState = useMediaTypeExamplesState("".concat(stateKey, "-examples"), (_d = (_c = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.examples) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.key);
|
|
50
|
+
if (!selectedItem) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (examples) {
|
|
54
|
+
var selectedExample = (_e = examples.find(function (example) { return example.key === exampleState.key; })) !== null && _e !== void 0 ? _e : examples[0];
|
|
55
|
+
if (!selectedExample) {
|
|
56
|
+
return <OpenAPIEmptyExample context={context}/>;
|
|
57
|
+
}
|
|
58
|
+
return selectedExample.body;
|
|
59
|
+
}
|
|
60
|
+
return selectedItem.body;
|
|
61
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type OpenAPIContextInput } from './context';
|
|
2
|
+
import type { OpenAPIOperationData } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Display an interactive OpenAPI operation.
|
|
4
5
|
*/
|
|
5
6
|
export declare function OpenAPIOperation(props: {
|
|
6
7
|
className?: string;
|
|
7
8
|
data: OpenAPIOperationData;
|
|
8
|
-
context:
|
|
9
|
+
context: OpenAPIContextInput;
|
|
9
10
|
}): import("react").JSX.Element;
|
|
@@ -1,84 +1,25 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
|
-
import { Markdown } from './Markdown';
|
|
3
2
|
import { OpenAPICodeSample } from './OpenAPICodeSample';
|
|
4
|
-
import { OpenAPIPath } from './OpenAPIPath';
|
|
5
3
|
import { OpenAPIResponseExample } from './OpenAPIResponseExample';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec';
|
|
5
|
+
import { OpenAPISummary } from './common/OpenAPISummary';
|
|
6
|
+
import { resolveOpenAPIContext } from './context';
|
|
9
7
|
/**
|
|
10
8
|
* Display an interactive OpenAPI operation.
|
|
11
9
|
*/
|
|
12
10
|
export function OpenAPIOperation(props) {
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var operation = data.operation;
|
|
16
|
-
var clientContext = getOpenAPIClientContext(context);
|
|
11
|
+
var className = props.className, data = props.data, contextInput = props.context;
|
|
12
|
+
var context = resolveOpenAPIContext(contextInput);
|
|
17
13
|
return (<div className={clsx('openapi-operation', className)}>
|
|
18
|
-
<
|
|
19
|
-
{(operation.deprecated || operation['x-stability']) && (<div className="openapi-summary-tags">
|
|
20
|
-
{operation.deprecated && (<div className="openapi-deprecated">Deprecated</div>)}
|
|
21
|
-
{operation['x-stability'] && (<OpenAPIOperationStability stability={operation['x-stability']}/>)}
|
|
22
|
-
</div>)}
|
|
23
|
-
{operation.summary
|
|
24
|
-
? context.renderHeading({
|
|
25
|
-
deprecated: (_a = operation.deprecated) !== null && _a !== void 0 ? _a : false,
|
|
26
|
-
stability: operation['x-stability'],
|
|
27
|
-
title: operation.summary,
|
|
28
|
-
})
|
|
29
|
-
: null}
|
|
30
|
-
<OpenAPIPath data={data}/>
|
|
31
|
-
</div>
|
|
14
|
+
<OpenAPISummary data={data} context={context}/>
|
|
32
15
|
<div className="openapi-columns">
|
|
33
|
-
<
|
|
34
|
-
{operation['x-deprecated-sunset'] ? (<div className="openapi-deprecated-sunset openapi-description openapi-markdown">
|
|
35
|
-
This operation is deprecated and will be sunset on{' '}
|
|
36
|
-
<span className="openapi-deprecated-sunset-date">
|
|
37
|
-
{operation['x-deprecated-sunset']}
|
|
38
|
-
</span>
|
|
39
|
-
{'.'}
|
|
40
|
-
</div>) : null}
|
|
41
|
-
<OpenAPIOperationDescription operation={operation} context={context}/>
|
|
42
|
-
<OpenAPISpec data={data} context={clientContext}/>
|
|
43
|
-
</div>
|
|
16
|
+
<OpenAPIColumnSpec data={data} context={context}/>
|
|
44
17
|
<div className="openapi-column-preview">
|
|
45
18
|
<div className="openapi-column-preview-body">
|
|
46
|
-
<OpenAPICodeSample {
|
|
47
|
-
<OpenAPIResponseExample {
|
|
19
|
+
<OpenAPICodeSample data={data} context={context}/>
|
|
20
|
+
<OpenAPIResponseExample data={data} context={context}/>
|
|
48
21
|
</div>
|
|
49
22
|
</div>
|
|
50
23
|
</div>
|
|
51
24
|
</div>);
|
|
52
25
|
}
|
|
53
|
-
function OpenAPIOperationDescription(props) {
|
|
54
|
-
var operation = props.operation;
|
|
55
|
-
if (operation['x-gitbook-description-document']) {
|
|
56
|
-
return (<div className="openapi-intro">
|
|
57
|
-
{props.context.renderDocument({
|
|
58
|
-
document: operation['x-gitbook-description-document'],
|
|
59
|
-
})}
|
|
60
|
-
</div>);
|
|
61
|
-
}
|
|
62
|
-
var description = resolveDescription(operation);
|
|
63
|
-
if (!description) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return (<div className="openapi-intro">
|
|
67
|
-
<Markdown className="openapi-description" source={description}/>
|
|
68
|
-
</div>);
|
|
69
|
-
}
|
|
70
|
-
var stabilityEnum = {
|
|
71
|
-
experimental: 'Experimental',
|
|
72
|
-
alpha: 'Alpha',
|
|
73
|
-
beta: 'Beta',
|
|
74
|
-
};
|
|
75
|
-
function OpenAPIOperationStability(props) {
|
|
76
|
-
var stability = props.stability;
|
|
77
|
-
var foundStability = stabilityEnum[stability];
|
|
78
|
-
if (!foundStability) {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
return (<div className={"openapi-stability openapi-stability-".concat(foundStability.toLowerCase())}>
|
|
82
|
-
{foundStability}
|
|
83
|
-
</div>);
|
|
84
|
-
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OpenAPICustomOperationProperties, OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
+
import type { OpenAPIContext } from './context';
|
|
3
|
+
/**
|
|
4
|
+
* Display the description of an OpenAPI operation.
|
|
5
|
+
*/
|
|
6
|
+
export declare function OpenAPIOperationDescription(props: {
|
|
7
|
+
operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
|
|
8
|
+
context: OpenAPIContext;
|
|
9
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Markdown } from './Markdown';
|
|
2
|
+
import { resolveDescription } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* Display the description of an OpenAPI operation.
|
|
5
|
+
*/
|
|
6
|
+
export function OpenAPIOperationDescription(props) {
|
|
7
|
+
var operation = props.operation;
|
|
8
|
+
if (operation['x-gitbook-description-document']) {
|
|
9
|
+
return (<div className="openapi-intro">
|
|
10
|
+
{props.context.renderDocument({
|
|
11
|
+
document: operation['x-gitbook-description-document'],
|
|
12
|
+
})}
|
|
13
|
+
</div>);
|
|
14
|
+
}
|
|
15
|
+
var description = resolveDescription(operation);
|
|
16
|
+
if (!description) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return (<div className="openapi-intro">
|
|
20
|
+
<Markdown className="openapi-description" source={description}/>
|
|
21
|
+
</div>);
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OpenAPIStability } from '@gitbook/openapi-parser';
|
|
2
|
+
import type { OpenAPIContext } from './context';
|
|
3
|
+
/**
|
|
4
|
+
* Display the stability of an OpenAPI operation.
|
|
5
|
+
*/
|
|
6
|
+
export declare function OpenAPIOperationStability(props: {
|
|
7
|
+
stability: OpenAPIStability;
|
|
8
|
+
context: OpenAPIContext;
|
|
9
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t } from './translate';
|
|
2
|
+
/**
|
|
3
|
+
* Display the stability of an OpenAPI operation.
|
|
4
|
+
*/
|
|
5
|
+
export function OpenAPIOperationStability(props) {
|
|
6
|
+
var stability = props.stability, context = props.context;
|
|
7
|
+
var stabilityLabel = getStabilityLabel(stability, context);
|
|
8
|
+
if (!stabilityLabel) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return (<div className={"openapi-stability openapi-stability-".concat(stability)}>{stabilityLabel}</div>);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get the stability label for the given stability level.
|
|
15
|
+
*/
|
|
16
|
+
function getStabilityLabel(stability, context) {
|
|
17
|
+
switch (stability) {
|
|
18
|
+
case 'experimental':
|
|
19
|
+
return t(context.translation, 'stability_experimental');
|
|
20
|
+
case 'alpha':
|
|
21
|
+
return t(context.translation, 'stability_alpha');
|
|
22
|
+
case 'beta':
|
|
23
|
+
return t(context.translation, 'stability_beta');
|
|
24
|
+
default:
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/OpenAPIPath.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { type OpenAPIUniversalContext } from './context';
|
|
1
2
|
import type { OpenAPIOperationData } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Display the path of an operation.
|
|
4
5
|
*/
|
|
5
6
|
export declare function OpenAPIPath(props: {
|
|
6
7
|
data: OpenAPIOperationData;
|
|
8
|
+
context: OpenAPIUniversalContext;
|
|
7
9
|
/** Whether to show the server URL.
|
|
8
10
|
* @default true
|
|
9
11
|
*/
|
package/dist/OpenAPIPath.jsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { OpenAPICopyButton } from './OpenAPICopyButton';
|
|
2
|
+
import { getOpenAPIClientContext } from './context';
|
|
2
3
|
import { getDefaultServerURL } from './util/server';
|
|
3
4
|
/**
|
|
4
5
|
* Display the path of an operation.
|
|
5
6
|
*/
|
|
6
7
|
export function OpenAPIPath(props) {
|
|
7
|
-
var data = props.data, _a = props.withServer, withServer = _a === void 0 ? true : _a, _b = props.canCopy, canCopy = _b === void 0 ? true : _b;
|
|
8
|
+
var data = props.data, context = props.context, _a = props.withServer, withServer = _a === void 0 ? true : _a, _b = props.canCopy, canCopy = _b === void 0 ? true : _b;
|
|
8
9
|
var method = data.method, path = data.path, operation = data.operation;
|
|
9
10
|
var server = getDefaultServerURL(data.servers);
|
|
10
11
|
var formattedPath = formatPath(path);
|
|
@@ -17,7 +18,7 @@ export function OpenAPIPath(props) {
|
|
|
17
18
|
return (<div className="openapi-path">
|
|
18
19
|
<div className={"openapi-method openapi-method-".concat(method)}>{method}</div>
|
|
19
20
|
|
|
20
|
-
<OpenAPICopyButton value={"".concat(withServer ? server : '').concat(path)} className="openapi-path-title" data-deprecated={operation.deprecated} isDisabled={!canCopy}>
|
|
21
|
+
<OpenAPICopyButton value={"".concat(withServer ? server : '').concat(path)} className="openapi-path-title" data-deprecated={operation.deprecated} isDisabled={!canCopy} context={getOpenAPIClientContext(context)}>
|
|
21
22
|
{element}
|
|
22
23
|
</OpenAPICopyButton>
|
|
23
24
|
</div>);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import type { OpenAPIClientContext } from './
|
|
2
|
+
import type { OpenAPIClientContext } from './context';
|
|
3
|
+
import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Display an interactive request body.
|
|
5
6
|
*/
|
|
6
7
|
export declare function OpenAPIRequestBody(props: {
|
|
7
8
|
requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
|
|
8
9
|
context: OpenAPIClientContext;
|
|
10
|
+
data: OpenAPIOperationData | OpenAPIWebhookData;
|
|
9
11
|
}): import("react").JSX.Element | null;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { InteractiveSection } from './InteractiveSection';
|
|
2
2
|
import { OpenAPIRootSchema } from './OpenAPISchemaServer';
|
|
3
|
-
import {
|
|
3
|
+
import { t } from './translate';
|
|
4
|
+
import { checkIsReference, createStateKey } from './utils';
|
|
4
5
|
/**
|
|
5
6
|
* Display an interactive request body.
|
|
6
7
|
*/
|
|
7
8
|
export function OpenAPIRequestBody(props) {
|
|
8
9
|
var _a;
|
|
9
|
-
var requestBody = props.requestBody, context = props.context;
|
|
10
|
+
var requestBody = props.requestBody, context = props.context, data = props.data;
|
|
10
11
|
if (checkIsReference(requestBody)) {
|
|
11
12
|
return null;
|
|
12
13
|
}
|
|
13
|
-
return (<InteractiveSection header=
|
|
14
|
+
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((_a = requestBody.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
14
15
|
var _b;
|
|
15
16
|
var contentType = _a[0], mediaTypeObject = _a[1];
|
|
16
17
|
return {
|
package/dist/OpenAPIResponse.jsx
CHANGED
|
@@ -28,7 +28,7 @@ export function OpenAPIResponse(props) {
|
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
return (<div className="openapi-response-body">
|
|
31
|
-
{headers.length > 0 ? (<OpenAPIDisclosure
|
|
31
|
+
{headers.length > 0 ? (<OpenAPIDisclosure icon={context.icons.plus} label="Headers">
|
|
32
32
|
<OpenAPISchemaProperties properties={headers.map(function (_a) {
|
|
33
33
|
var name = _a[0], header = _a[1];
|
|
34
34
|
return parameterToProperty(__assign({ name: name }, header));
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type OpenAPIContext } from './context';
|
|
2
|
+
import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Display an example of the response content.
|
|
4
5
|
*/
|
|
5
6
|
export declare function OpenAPIResponseExample(props: {
|
|
6
|
-
data: OpenAPIOperationData;
|
|
7
|
+
data: OpenAPIOperationData | OpenAPIWebhookData;
|
|
7
8
|
context: OpenAPIContext;
|
|
8
9
|
}): import("react").JSX.Element | null;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Markdown } from './Markdown';
|
|
2
|
-
import { OpenAPIEmptyExample, OpenAPIExample
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { OpenAPIEmptyExample, OpenAPIExample } from './OpenAPIExample';
|
|
3
|
+
import { OpenAPIMediaTypeContent } from './OpenAPIMediaType';
|
|
4
|
+
import { OpenAPIResponseExampleContent } from './OpenAPIResponseExampleContent';
|
|
5
|
+
import { getOpenAPIClientContext } from './context';
|
|
6
|
+
import { getExampleFromReference, getExamples } from './util/example';
|
|
7
|
+
import { createStateKey, getStatusCodeDefaultLabel } from './utils';
|
|
8
|
+
import { checkIsReference, resolveDescription } from './utils';
|
|
6
9
|
/**
|
|
7
10
|
* Display an example of the response content.
|
|
8
11
|
*/
|
|
@@ -34,37 +37,34 @@ export function OpenAPIResponseExample(props) {
|
|
|
34
37
|
var tabs = responses.map(function (_a) {
|
|
35
38
|
var key = _a[0], responseObject = _a[1];
|
|
36
39
|
var description = resolveDescription(responseObject);
|
|
40
|
+
var label = description ? (<Markdown source={description}/>) : (getStatusCodeDefaultLabel(key, context));
|
|
37
41
|
if (checkIsReference(responseObject)) {
|
|
38
42
|
return {
|
|
39
43
|
key: key,
|
|
40
|
-
label:
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
label: label,
|
|
45
|
+
statusCode: key,
|
|
46
|
+
body: (<OpenAPIExample example={getExampleFromReference(responseObject, context)} context={context} syntax="json"/>),
|
|
43
47
|
};
|
|
44
48
|
}
|
|
45
49
|
if (!responseObject.content || Object.keys(responseObject.content).length === 0) {
|
|
46
50
|
return {
|
|
47
51
|
key: key,
|
|
48
|
-
label:
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
label: label,
|
|
53
|
+
statusCode: key,
|
|
54
|
+
body: <OpenAPIEmptyExample context={context}/>,
|
|
51
55
|
};
|
|
52
56
|
}
|
|
53
57
|
return {
|
|
54
58
|
key: key,
|
|
55
|
-
label:
|
|
59
|
+
label: label,
|
|
60
|
+
statusCode: key,
|
|
56
61
|
body: <OpenAPIResponse context={context} content={responseObject.content}/>,
|
|
57
|
-
footer: description ? <Markdown source={description}/> : undefined,
|
|
58
62
|
};
|
|
59
63
|
});
|
|
60
64
|
if (tabs.length === 0) {
|
|
61
65
|
return null;
|
|
62
66
|
}
|
|
63
|
-
return (<
|
|
64
|
-
<StaticSection header={<OpenAPITabsList />} className="openapi-panel">
|
|
65
|
-
<OpenAPITabsPanels />
|
|
66
|
-
</StaticSection>
|
|
67
|
-
</OpenAPITabs>);
|
|
67
|
+
return (<OpenAPIResponseExampleContent selectIcon={context.icons.chevronDown} blockKey={context.blockKey} items={tabs}/>);
|
|
68
68
|
}
|
|
69
69
|
function OpenAPIResponse(props) {
|
|
70
70
|
var context = props.context, content = props.content;
|
|
@@ -73,57 +73,18 @@ function OpenAPIResponse(props) {
|
|
|
73
73
|
if (!firstEntry) {
|
|
74
74
|
throw new Error('One media type is required');
|
|
75
75
|
}
|
|
76
|
-
if (entries.length === 1) {
|
|
77
|
-
var mediaType = firstEntry[0], mediaTypeObject = firstEntry[1];
|
|
78
|
-
return (<OpenAPIResponseMediaType context={context} mediaType={mediaType} mediaTypeObject={mediaTypeObject}/>);
|
|
79
|
-
}
|
|
80
76
|
var tabs = entries.map(function (entry) {
|
|
81
77
|
var mediaType = entry[0], mediaTypeObject = entry[1];
|
|
82
78
|
return {
|
|
83
79
|
key: mediaType,
|
|
84
80
|
label: mediaType,
|
|
85
|
-
body:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
</StaticSection>
|
|
92
|
-
</OpenAPITabs>);
|
|
93
|
-
}
|
|
94
|
-
function OpenAPIResponseMediaType(props) {
|
|
95
|
-
var mediaTypeObject = props.mediaTypeObject, mediaType = props.mediaType;
|
|
96
|
-
var examples = getExamplesFromMediaTypeObject({ mediaTypeObject: mediaTypeObject, mediaType: mediaType });
|
|
97
|
-
var syntax = getSyntaxFromMediaType(mediaType);
|
|
98
|
-
var firstExample = examples[0];
|
|
99
|
-
if (!firstExample) {
|
|
100
|
-
return <OpenAPIEmptyExample />;
|
|
101
|
-
}
|
|
102
|
-
if (examples.length === 1) {
|
|
103
|
-
return (<OpenAPIExample example={firstExample.example} context={props.context} syntax={syntax}/>);
|
|
104
|
-
}
|
|
105
|
-
var tabs = examples.map(function (example) {
|
|
106
|
-
return {
|
|
107
|
-
key: example.key,
|
|
108
|
-
label: example.example.summary || example.key,
|
|
109
|
-
body: (<OpenAPIExample example={example.example} context={props.context} syntax={syntax}/>),
|
|
81
|
+
body: <></>,
|
|
82
|
+
examples: getExamples({
|
|
83
|
+
mediaTypeObject: mediaTypeObject,
|
|
84
|
+
mediaType: mediaType,
|
|
85
|
+
context: context,
|
|
86
|
+
}),
|
|
110
87
|
};
|
|
111
88
|
});
|
|
112
|
-
return (<
|
|
113
|
-
<StaticSection header={<OpenAPITabsList />} className="openapi-response-media-type-examples">
|
|
114
|
-
<OpenAPITabsPanels />
|
|
115
|
-
</StaticSection>
|
|
116
|
-
</OpenAPITabs>);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Get the syntax from a media type.
|
|
120
|
-
*/
|
|
121
|
-
function getSyntaxFromMediaType(mediaType) {
|
|
122
|
-
if (mediaType.includes('json')) {
|
|
123
|
-
return 'json';
|
|
124
|
-
}
|
|
125
|
-
if (mediaType === 'application/xml') {
|
|
126
|
-
return 'xml';
|
|
127
|
-
}
|
|
128
|
-
return 'text';
|
|
89
|
+
return (<OpenAPIMediaTypeContent selectIcon={context.icons.chevronDown} stateKey={createStateKey('response-media-types', context.blockKey)} items={tabs} context={getOpenAPIClientContext(context)}/>);
|
|
129
90
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Key } from 'react-aria';
|
|
2
|
+
import { OpenAPISelectItem } from './OpenAPISelect';
|
|
3
|
+
type OpenAPIResponseExampleItem = OpenAPISelectItem & {
|
|
4
|
+
statusCode: string;
|
|
5
|
+
body: React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Get the state of the response examples select.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useResponseExamplesState(blockKey: string | undefined, initialKey?: Key): {
|
|
11
|
+
key: (string | number) | null;
|
|
12
|
+
setKey: (key: Key | null) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare function OpenAPIResponseExampleContent(props: {
|
|
15
|
+
items: OpenAPIResponseExampleItem[];
|
|
16
|
+
blockKey?: string;
|
|
17
|
+
selectIcon?: React.ReactNode;
|
|
18
|
+
}): import("react").JSX.Element;
|
|
19
|
+
export {};
|