@gitbook/react-openapi 1.4.3 → 1.5.2
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 +36 -0
- package/dist/InteractiveSection.js +59 -0
- package/dist/Markdown.js +10 -0
- package/dist/OpenAPICodeSample.js +219 -0
- package/dist/OpenAPICodeSampleInteractive.js +66 -0
- package/dist/OpenAPICodeSampleSelector.js +45 -0
- package/dist/OpenAPICopyButton.js +39 -0
- package/dist/OpenAPIDisclosure.js +30 -0
- package/dist/OpenAPIDisclosureGroup.js +75 -0
- package/dist/OpenAPIExample.js +41 -0
- package/dist/OpenAPIMediaType.js +58 -0
- package/dist/OpenAPIOperation.d.ts +12 -7
- package/dist/OpenAPIOperation.js +30 -0
- package/dist/OpenAPIOperationContext.d.ts +10 -6
- package/dist/OpenAPIOperationContext.js +30 -0
- package/dist/OpenAPIPath.js +51 -0
- package/dist/OpenAPIPrefillContextProvider.d.ts +11 -7
- package/dist/OpenAPIPrefillContextProvider.js +25 -0
- package/dist/OpenAPIRequestBody.js +28 -0
- package/dist/OpenAPIRequestBodyHeaderType.js +23 -0
- package/dist/OpenAPIResponse.js +39 -0
- package/dist/OpenAPIResponseExample.js +75 -0
- package/dist/OpenAPIResponseExampleContent.js +61 -0
- package/dist/OpenAPIResponses.js +61 -0
- package/dist/OpenAPISchema.js +373 -0
- package/dist/OpenAPISchemaName.js +45 -0
- package/dist/OpenAPISchemaServer.js +13 -0
- package/dist/OpenAPISecurities.js +124 -0
- package/dist/OpenAPISelect.js +45 -0
- package/dist/OpenAPISpec.js +73 -0
- package/dist/OpenAPIWebhook.d.ts +12 -7
- package/dist/OpenAPIWebhook.js +28 -0
- package/dist/OpenAPIWebhookExample.js +40 -0
- package/dist/ScalarApiButton.js +87 -0
- package/dist/StaticSection.js +37 -0
- package/dist/code-samples.js +267 -419
- package/dist/common/OpenAPIColumnSpec.js +23 -0
- package/dist/common/OpenAPIOperationDescription.js +18 -0
- package/dist/common/OpenAPIStability.js +17 -0
- package/dist/common/OpenAPISummary.js +27 -0
- package/dist/contentTypeChecks.js +24 -20
- package/dist/context.d.ts +68 -72
- package/dist/context.js +25 -39
- package/dist/decycle.js +39 -68
- package/dist/dereference.js +20 -64
- package/dist/generateSchemaExample.js +188 -332
- package/dist/getDisclosureLabel.js +15 -16
- package/dist/getOrCreateStoreByKey.js +20 -17
- package/dist/index.d.ts +12 -10
- package/dist/index.js +11 -8
- package/dist/json2xml.js +10 -5
- package/dist/resolveOpenAPIOperation.d.ts +11 -7
- package/dist/resolveOpenAPIOperation.js +88 -159
- package/dist/resolveOpenAPIWebhook.d.ts +11 -7
- package/dist/resolveOpenAPIWebhook.js +41 -116
- package/dist/schemas/OpenAPISchemaItem.js +26 -0
- package/dist/schemas/OpenAPISchemas.d.ts +16 -11
- package/dist/schemas/OpenAPISchemas.js +57 -0
- package/dist/schemas/resolveOpenAPISchemas.d.ts +9 -4
- package/dist/schemas/resolveOpenAPISchemas.js +15 -59
- package/dist/stringifyOpenAPI.js +12 -13
- package/dist/translate.js +43 -0
- package/dist/translations/de.js +47 -42
- package/dist/translations/en.d.ts +46 -42
- package/dist/translations/en.js +47 -42
- package/dist/translations/es.js +47 -42
- package/dist/translations/fr.js +47 -42
- package/dist/translations/index.d.ts +404 -391
- package/dist/translations/index.js +28 -24
- package/dist/translations/ja.js +47 -42
- package/dist/translations/nl.js +47 -42
- package/dist/translations/no.js +47 -42
- package/dist/translations/pt-br.js +47 -42
- package/dist/translations/types.d.ts +7 -5
- package/dist/translations/zh.js +47 -42
- package/dist/types.d.ts +30 -24
- package/dist/util/example.js +84 -0
- package/dist/util/server.js +32 -38
- package/dist/util/tryit-prefill.js +135 -121
- package/dist/utils.js +135 -196
- package/package.json +18 -11
- package/dist/InteractiveSection.d.ts +0 -33
- package/dist/InteractiveSection.jsx +0 -61
- package/dist/Markdown.d.ts +0 -4
- package/dist/Markdown.jsx +0 -5
- package/dist/OpenAPICodeSample.d.ts +0 -19
- package/dist/OpenAPICodeSample.jsx +0 -230
- package/dist/OpenAPICodeSampleInteractive.d.ts +0 -14
- package/dist/OpenAPICodeSampleInteractive.jsx +0 -73
- package/dist/OpenAPICodeSampleSelector.d.ts +0 -14
- package/dist/OpenAPICodeSampleSelector.jsx +0 -44
- package/dist/OpenAPICopyButton.d.ts +0 -13
- package/dist/OpenAPICopyButton.jsx +0 -35
- package/dist/OpenAPIDisclosure.d.ts +0 -11
- package/dist/OpenAPIDisclosure.jsx +0 -30
- package/dist/OpenAPIDisclosureGroup.d.ts +0 -23
- package/dist/OpenAPIDisclosureGroup.jsx +0 -83
- package/dist/OpenAPIExample.d.ts +0 -16
- package/dist/OpenAPIExample.jsx +0 -36
- package/dist/OpenAPIMediaType.d.ts +0 -21
- package/dist/OpenAPIMediaType.jsx +0 -61
- package/dist/OpenAPIOperation.jsx +0 -25
- package/dist/OpenAPIOperationContext.jsx +0 -26
- package/dist/OpenAPIOperationDescription.d.ts +0 -9
- package/dist/OpenAPIOperationDescription.jsx +0 -22
- package/dist/OpenAPIOperationStability.d.ts +0 -9
- package/dist/OpenAPIOperationStability.jsx +0 -27
- package/dist/OpenAPIPath.d.ts +0 -18
- package/dist/OpenAPIPath.jsx +0 -55
- package/dist/OpenAPIPrefillContextProvider.jsx +0 -19
- package/dist/OpenAPIRequestBody.d.ts +0 -11
- package/dist/OpenAPIRequestBody.jsx +0 -28
- package/dist/OpenAPIRequestBodyHeaderType.d.ts +0 -8
- package/dist/OpenAPIRequestBodyHeaderType.jsx +0 -25
- package/dist/OpenAPIResponse.d.ts +0 -10
- package/dist/OpenAPIResponse.jsx +0 -57
- package/dist/OpenAPIResponseExample.d.ts +0 -9
- package/dist/OpenAPIResponseExample.jsx +0 -105
- package/dist/OpenAPIResponseExampleContent.d.ts +0 -22
- package/dist/OpenAPIResponseExampleContent.jsx +0 -60
- package/dist/OpenAPIResponses.d.ts +0 -9
- package/dist/OpenAPIResponses.jsx +0 -77
- package/dist/OpenAPISchema.d.ts +0 -27
- package/dist/OpenAPISchema.jsx +0 -400
- package/dist/OpenAPISchemaName.d.ts +0 -16
- package/dist/OpenAPISchemaName.jsx +0 -43
- package/dist/OpenAPISchemaServer.d.ts +0 -12
- package/dist/OpenAPISchemaServer.jsx +0 -8
- package/dist/OpenAPISecurities.d.ts +0 -9
- package/dist/OpenAPISecurities.jsx +0 -114
- package/dist/OpenAPISelect.d.ts +0 -22
- package/dist/OpenAPISelect.jsx +0 -44
- package/dist/OpenAPISpec.d.ts +0 -6
- package/dist/OpenAPISpec.jsx +0 -80
- package/dist/OpenAPITabs.d.ts +0 -26
- package/dist/OpenAPITabs.jsx +0 -109
- package/dist/OpenAPIWebhook.jsx +0 -23
- package/dist/OpenAPIWebhookExample.d.ts +0 -6
- package/dist/OpenAPIWebhookExample.jsx +0 -41
- package/dist/ScalarApiButton.d.ts +0 -14
- package/dist/ScalarApiButton.jsx +0 -81
- package/dist/StaticSection.d.ts +0 -13
- package/dist/StaticSection.jsx +0 -32
- package/dist/code-samples.d.ts +0 -17
- package/dist/common/OpenAPIColumnSpec.d.ts +0 -6
- package/dist/common/OpenAPIColumnSpec.jsx +0 -20
- package/dist/common/OpenAPIOperationDescription.d.ts +0 -6
- package/dist/common/OpenAPIOperationDescription.jsx +0 -19
- package/dist/common/OpenAPIStability.d.ts +0 -4
- package/dist/common/OpenAPIStability.jsx +0 -15
- package/dist/common/OpenAPISummary.d.ts +0 -6
- package/dist/common/OpenAPISummary.jsx +0 -30
- package/dist/contentTypeChecks.d.ts +0 -10
- package/dist/decycle.d.ts +0 -2
- package/dist/dereference.d.ts +0 -5
- package/dist/generateSchemaExample.d.ts +0 -45
- package/dist/getDisclosureLabel.d.ts +0 -7
- package/dist/getOrCreateStoreByKey.d.ts +0 -10
- package/dist/json2xml.d.ts +0 -4
- package/dist/schemas/OpenAPISchemaItem.d.ts +0 -7
- package/dist/schemas/OpenAPISchemaItem.jsx +0 -16
- package/dist/schemas/OpenAPISchemas.jsx +0 -59
- package/dist/schemas/index.d.ts +0 -2
- package/dist/schemas/index.js +0 -2
- package/dist/stringifyOpenAPI.d.ts +0 -4
- package/dist/translate.d.ts +0 -10
- package/dist/translate.jsx +0 -75
- package/dist/translations/de.d.ts +0 -43
- package/dist/translations/es.d.ts +0 -43
- package/dist/translations/fr.d.ts +0 -43
- package/dist/translations/ja.d.ts +0 -43
- package/dist/translations/nl.d.ts +0 -43
- package/dist/translations/no.d.ts +0 -43
- package/dist/translations/pt-br.d.ts +0 -43
- package/dist/translations/types.js +0 -1
- package/dist/translations/zh.d.ts +0 -43
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types.js +0 -1
- package/dist/util/example.d.ts +0 -35
- package/dist/util/example.jsx +0 -103
- package/dist/util/server.d.ts +0 -9
- package/dist/util/tryit-prefill.d.ts +0 -20
- package/dist/utils.d.ts +0 -50
- package/src/InteractiveSection.tsx +0 -147
- package/src/Markdown.tsx +0 -12
- package/src/OpenAPICodeSample.tsx +0 -330
- package/src/OpenAPICodeSampleInteractive.tsx +0 -136
- package/src/OpenAPICodeSampleSelector.tsx +0 -94
- package/src/OpenAPICopyButton.tsx +0 -72
- package/src/OpenAPIDisclosure.tsx +0 -46
- package/src/OpenAPIDisclosureGroup.tsx +0 -158
- package/src/OpenAPIExample.tsx +0 -55
- package/src/OpenAPIMediaType.tsx +0 -139
- package/src/OpenAPIOperation.tsx +0 -35
- package/src/OpenAPIOperationContext.tsx +0 -45
- package/src/OpenAPIOperationDescription.tsx +0 -34
- package/src/OpenAPIOperationStability.tsx +0 -39
- package/src/OpenAPIPath.tsx +0 -90
- package/src/OpenAPIPrefillContextProvider.tsx +0 -40
- package/src/OpenAPIRequestBody.tsx +0 -54
- package/src/OpenAPIRequestBodyHeaderType.tsx +0 -36
- package/src/OpenAPIResponse.tsx +0 -82
- package/src/OpenAPIResponseExample.tsx +0 -151
- package/src/OpenAPIResponseExampleContent.tsx +0 -125
- package/src/OpenAPIResponses.tsx +0 -125
- package/src/OpenAPISchema.test.ts +0 -172
- package/src/OpenAPISchema.tsx +0 -654
- package/src/OpenAPISchemaName.tsx +0 -80
- package/src/OpenAPISchemaServer.tsx +0 -34
- package/src/OpenAPISecurities.tsx +0 -231
- package/src/OpenAPISelect.tsx +0 -96
- package/src/OpenAPISpec.tsx +0 -138
- package/src/OpenAPITabs.tsx +0 -147
- package/src/OpenAPIWebhook.tsx +0 -33
- package/src/OpenAPIWebhookExample.tsx +0 -60
- package/src/ScalarApiButton.tsx +0 -132
- package/src/StaticSection.tsx +0 -91
- package/src/__snapshots__/json2xml.test.ts.snap +0 -18
- package/src/code-samples.test.ts +0 -714
- package/src/code-samples.ts +0 -448
- package/src/common/OpenAPIColumnSpec.tsx +0 -31
- package/src/common/OpenAPIOperationDescription.tsx +0 -31
- package/src/common/OpenAPIStability.tsx +0 -23
- package/src/common/OpenAPISummary.tsx +0 -45
- package/src/contentTypeChecks.ts +0 -39
- package/src/context.ts +0 -99
- package/src/decycle.ts +0 -68
- package/src/dereference.ts +0 -29
- package/src/generateSchemaExample.test.ts +0 -1040
- package/src/generateSchemaExample.ts +0 -530
- package/src/getDisclosureLabel.ts +0 -25
- package/src/getOrCreateStoreByKey.ts +0 -33
- package/src/index.ts +0 -10
- package/src/json2xml.test.ts +0 -46
- package/src/json2xml.ts +0 -8
- package/src/resolveOpenAPIOperation.test.ts +0 -177
- package/src/resolveOpenAPIOperation.ts +0 -151
- package/src/resolveOpenAPIWebhook.ts +0 -99
- package/src/schemas/OpenAPISchemaItem.tsx +0 -34
- package/src/schemas/OpenAPISchemas.tsx +0 -98
- package/src/schemas/index.ts +0 -2
- package/src/schemas/resolveOpenAPISchemas.test.ts +0 -174
- package/src/schemas/resolveOpenAPISchemas.ts +0 -28
- package/src/stringifyOpenAPI.ts +0 -25
- package/src/translate.tsx +0 -80
- package/src/translations/de.ts +0 -43
- package/src/translations/en.ts +0 -43
- package/src/translations/es.ts +0 -43
- package/src/translations/fr.ts +0 -43
- package/src/translations/index.ts +0 -33
- package/src/translations/ja.ts +0 -43
- package/src/translations/nl.ts +0 -43
- package/src/translations/no.ts +0 -43
- package/src/translations/pt-br.ts +0 -43
- package/src/translations/types.ts +0 -7
- package/src/translations/zh.ts +0 -43
- package/src/types.ts +0 -46
- package/src/util/example.tsx +0 -129
- package/src/util/server.test.ts +0 -58
- package/src/util/server.ts +0 -47
- package/src/util/tryit-prefill.test.ts +0 -311
- package/src/util/tryit-prefill.ts +0 -160
- package/src/utils.ts +0 -255
|
@@ -1,61 +0,0 @@
|
|
|
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,25 +0,0 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
|
-
import { OpenAPICodeSample } from './OpenAPICodeSample';
|
|
3
|
-
import { OpenAPIResponseExample } from './OpenAPIResponseExample';
|
|
4
|
-
import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec';
|
|
5
|
-
import { OpenAPISummary } from './common/OpenAPISummary';
|
|
6
|
-
import { resolveOpenAPIContext } from './context';
|
|
7
|
-
/**
|
|
8
|
-
* Display an interactive OpenAPI operation.
|
|
9
|
-
*/
|
|
10
|
-
export function OpenAPIOperation(props) {
|
|
11
|
-
var className = props.className, data = props.data, contextInput = props.context;
|
|
12
|
-
var context = resolveOpenAPIContext(contextInput);
|
|
13
|
-
return (<div className={clsx('openapi-operation', className)}>
|
|
14
|
-
<OpenAPISummary data={data} context={context}/>
|
|
15
|
-
<div className="openapi-columns">
|
|
16
|
-
<OpenAPIColumnSpec data={data} context={context}/>
|
|
17
|
-
<div className="openapi-column-preview">
|
|
18
|
-
<div className="openapi-column-preview-body">
|
|
19
|
-
<OpenAPICodeSample data={data} context={context}/>
|
|
20
|
-
<OpenAPIResponseExample data={data} context={context}/>
|
|
21
|
-
</div>
|
|
22
|
-
</div>
|
|
23
|
-
</div>
|
|
24
|
-
</div>);
|
|
25
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { createContext, useContext, useMemo } from 'react';
|
|
3
|
-
import { useEventCallback } from 'usehooks-ts';
|
|
4
|
-
var OpenAPIOperationContext = createContext({
|
|
5
|
-
onOpenClient: function () { },
|
|
6
|
-
});
|
|
7
|
-
/**
|
|
8
|
-
* Provider for the OpenAPIOperationContext.
|
|
9
|
-
*/
|
|
10
|
-
export function OpenAPIOperationContextProvider(props) {
|
|
11
|
-
var children = props.children;
|
|
12
|
-
var onOpenClient = useEventCallback(function (pointer) {
|
|
13
|
-
var _a;
|
|
14
|
-
(_a = props.onOpenClient) === null || _a === void 0 ? void 0 : _a.call(props, pointer);
|
|
15
|
-
});
|
|
16
|
-
var value = useMemo(function () { return ({ onOpenClient: onOpenClient }); }, [onOpenClient]);
|
|
17
|
-
return (<OpenAPIOperationContext.Provider value={value}>
|
|
18
|
-
{children}
|
|
19
|
-
</OpenAPIOperationContext.Provider>);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Hook to access the OpenAPIOperationContext.
|
|
23
|
-
*/
|
|
24
|
-
export function useOpenAPIOperationContext() {
|
|
25
|
-
return useContext(OpenAPIOperationContext);
|
|
26
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
|
@@ -1,27 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type OpenAPIUniversalContext } from './context';
|
|
2
|
-
import type { OpenAPIOperationData } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Display the path of an operation.
|
|
5
|
-
*/
|
|
6
|
-
export declare function OpenAPIPath(props: {
|
|
7
|
-
data: OpenAPIOperationData;
|
|
8
|
-
context: OpenAPIUniversalContext;
|
|
9
|
-
/** Whether to show the server URL.
|
|
10
|
-
* @default true
|
|
11
|
-
*/
|
|
12
|
-
withServer?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Whether the path is copyable.
|
|
15
|
-
* @default true
|
|
16
|
-
*/
|
|
17
|
-
canCopy?: boolean;
|
|
18
|
-
}): import("react").JSX.Element;
|
package/dist/OpenAPIPath.jsx
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { OpenAPICopyButton } from './OpenAPICopyButton';
|
|
2
|
-
import { getOpenAPIClientContext } from './context';
|
|
3
|
-
import { getDefaultServerURL } from './util/server';
|
|
4
|
-
/**
|
|
5
|
-
* Display the path of an operation.
|
|
6
|
-
*/
|
|
7
|
-
export function OpenAPIPath(props) {
|
|
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;
|
|
9
|
-
var method = data.method, path = data.path, operation = data.operation;
|
|
10
|
-
var server = getDefaultServerURL(data.servers);
|
|
11
|
-
var formattedPath = formatPath(path);
|
|
12
|
-
var element = (function () {
|
|
13
|
-
return (<>
|
|
14
|
-
{withServer ? <span className="openapi-path-server">{server}</span> : null}
|
|
15
|
-
{formattedPath}
|
|
16
|
-
</>);
|
|
17
|
-
})();
|
|
18
|
-
return (<div className="openapi-path">
|
|
19
|
-
<div className={"openapi-method openapi-method-".concat(method)}>{method}</div>
|
|
20
|
-
|
|
21
|
-
<OpenAPICopyButton value={"".concat(withServer ? server : '').concat(path)} className="openapi-path-title" data-deprecated={operation.deprecated} isDisabled={!canCopy} context={getOpenAPIClientContext(context)}>
|
|
22
|
-
{element}
|
|
23
|
-
</OpenAPICopyButton>
|
|
24
|
-
</div>);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Format the path by wrapping placeholders in <span> tags.
|
|
28
|
-
*/
|
|
29
|
-
function formatPath(path) {
|
|
30
|
-
// Matches placeholders like {id}, {userId}, etc.
|
|
31
|
-
var regex = /\{\s*(\w+)\s*\}|:\w+/g;
|
|
32
|
-
var parts = [];
|
|
33
|
-
var lastIndex = 0;
|
|
34
|
-
//Wrap the variables in <span> tags and maintain either {variable} or :variable
|
|
35
|
-
path.replace(regex, function (match, _, offset) {
|
|
36
|
-
if (offset > lastIndex) {
|
|
37
|
-
parts.push(path.slice(lastIndex, offset));
|
|
38
|
-
}
|
|
39
|
-
parts.push(<span key={"offset-".concat(offset)} className="openapi-path-variable">
|
|
40
|
-
{match}
|
|
41
|
-
</span>);
|
|
42
|
-
lastIndex = offset + match.length;
|
|
43
|
-
return match;
|
|
44
|
-
});
|
|
45
|
-
if (lastIndex < path.length) {
|
|
46
|
-
parts.push(path.slice(lastIndex));
|
|
47
|
-
}
|
|
48
|
-
var formattedPath = parts.map(function (part, index) {
|
|
49
|
-
if (typeof part === 'string') {
|
|
50
|
-
return <span key={"part-".concat(index)}>{part}</span>;
|
|
51
|
-
}
|
|
52
|
-
return part;
|
|
53
|
-
});
|
|
54
|
-
return formattedPath;
|
|
55
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
var OpenAPIPrefillContext = React.createContext(null);
|
|
4
|
-
/**
|
|
5
|
-
* Provide context to help prefill dynamic info like visitor data in OpenAPI blocks.
|
|
6
|
-
*/
|
|
7
|
-
export function OpenAPIPrefillContextProvider(props) {
|
|
8
|
-
var getPrefillInputContextData = props.getPrefillInputContextData, children = props.children;
|
|
9
|
-
return (<OpenAPIPrefillContext.Provider value={getPrefillInputContextData}>
|
|
10
|
-
{children}
|
|
11
|
-
</OpenAPIPrefillContext.Provider>);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Hook to access the prefill context function.
|
|
15
|
-
*/
|
|
16
|
-
export function useOpenAPIPrefillContext() {
|
|
17
|
-
var _a;
|
|
18
|
-
return (_a = React.useContext(OpenAPIPrefillContext)) !== null && _a !== void 0 ? _a : (function () { return null; });
|
|
19
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import type { OpenAPIClientContext } from './context';
|
|
3
|
-
import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Display an interactive request body.
|
|
6
|
-
*/
|
|
7
|
-
export declare function OpenAPIRequestBody(props: {
|
|
8
|
-
requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
|
|
9
|
-
context: OpenAPIClientContext;
|
|
10
|
-
data: OpenAPIOperationData | OpenAPIWebhookData;
|
|
11
|
-
}): import("react").JSX.Element | null;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { InteractiveSection } from './InteractiveSection';
|
|
2
|
-
import { OpenAPIRequestBodyHeaderType } from './OpenAPIRequestBodyHeaderType';
|
|
3
|
-
import { OpenAPIRootSchema } from './OpenAPISchemaServer';
|
|
4
|
-
import { t } from './translate';
|
|
5
|
-
import { checkIsReference, createStateKey } from './utils';
|
|
6
|
-
/**
|
|
7
|
-
* Display an interactive request body.
|
|
8
|
-
*/
|
|
9
|
-
export function OpenAPIRequestBody(props) {
|
|
10
|
-
var _a;
|
|
11
|
-
var requestBody = props.requestBody, context = props.context, data = props.data;
|
|
12
|
-
if (checkIsReference(requestBody)) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
var stateKey = createStateKey('request-body-media-type', context.blockKey);
|
|
16
|
-
return (<InteractiveSection header={<>
|
|
17
|
-
<span>{t(context.translation, 'name' in data ? 'payload' : 'body')}</span>
|
|
18
|
-
<OpenAPIRequestBodyHeaderType requestBody={requestBody} stateKey={stateKey}/>
|
|
19
|
-
</>} className="openapi-requestbody" stateKey={stateKey} selectIcon={context.icons.chevronDown} tabs={Object.entries((_a = requestBody.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
20
|
-
var _b;
|
|
21
|
-
var contentType = _a[0], mediaTypeObject = _a[1];
|
|
22
|
-
return {
|
|
23
|
-
key: contentType,
|
|
24
|
-
label: contentType,
|
|
25
|
-
body: (<OpenAPIRootSchema schema={(_b = mediaTypeObject.schema) !== null && _b !== void 0 ? _b : {}} context={context} key={contentType}/>),
|
|
26
|
-
};
|
|
27
|
-
})}/>);
|
|
28
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
/**
|
|
3
|
-
* Display the type of a request body. It only displays the type if the selected content is an array.
|
|
4
|
-
*/
|
|
5
|
-
export declare function OpenAPIRequestBodyHeaderType(props: {
|
|
6
|
-
requestBody: OpenAPIV3.RequestBodyObject;
|
|
7
|
-
stateKey: string;
|
|
8
|
-
}): import("react").JSX.Element | null;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useSelectState } from './OpenAPISelect';
|
|
3
|
-
import { getSchemaTitle } from './utils';
|
|
4
|
-
/**
|
|
5
|
-
* Display the type of a request body. It only displays the type if the selected content is an array.
|
|
6
|
-
*/
|
|
7
|
-
export function OpenAPIRequestBodyHeaderType(props) {
|
|
8
|
-
var _a, _b, _c;
|
|
9
|
-
var requestBody = props.requestBody, stateKey = props.stateKey;
|
|
10
|
-
var content = (_a = requestBody.content) !== null && _a !== void 0 ? _a : {};
|
|
11
|
-
var state = useSelectState(stateKey, Object.keys(content)[0]);
|
|
12
|
-
var selectedContentMediaType = (_b = Object.entries(content).find(function (_a) {
|
|
13
|
-
var contentType = _a[0];
|
|
14
|
-
return contentType === state.key;
|
|
15
|
-
})) === null || _b === void 0 ? void 0 : _b[1];
|
|
16
|
-
// If the selected content is not an array, we don't display the type
|
|
17
|
-
if (!selectedContentMediaType ||
|
|
18
|
-
!((_c = selectedContentMediaType.schema) === null || _c === void 0 ? void 0 : _c.type) ||
|
|
19
|
-
selectedContentMediaType.schema.type !== 'array') {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
return (<span className="openapi-requestbody-header-type">
|
|
23
|
-
{"".concat(getSchemaTitle(selectedContentMediaType.schema))}
|
|
24
|
-
</span>);
|
|
25
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import type { OpenAPIClientContext } from './context';
|
|
3
|
-
/**
|
|
4
|
-
* Display an interactive response body.
|
|
5
|
-
*/
|
|
6
|
-
export declare function OpenAPIResponse(props: {
|
|
7
|
-
response: OpenAPIV3.ResponseObject;
|
|
8
|
-
mediaType: OpenAPIV3.MediaTypeObject | null;
|
|
9
|
-
context: OpenAPIClientContext;
|
|
10
|
-
}): import("react").JSX.Element | null;
|
package/dist/OpenAPIResponse.jsx
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { OpenAPIDisclosure } from './OpenAPIDisclosure';
|
|
13
|
-
import { OpenAPISchemaPresentation } from './OpenAPISchema';
|
|
14
|
-
import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
|
|
15
|
-
import { tString } from './translate';
|
|
16
|
-
import { parameterToProperty, resolveDescription } from './utils';
|
|
17
|
-
/**
|
|
18
|
-
* Display an interactive response body.
|
|
19
|
-
*/
|
|
20
|
-
export function OpenAPIResponse(props) {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
var response = props.response, context = props.context, mediaType = props.mediaType;
|
|
23
|
-
var headers = Object.entries((_a = response.headers) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
24
|
-
var name = _a[0], header = _a[1];
|
|
25
|
-
return [name, header !== null && header !== void 0 ? header : {}];
|
|
26
|
-
});
|
|
27
|
-
var content = Object.entries((_b = mediaType === null || mediaType === void 0 ? void 0 : mediaType.schema) !== null && _b !== void 0 ? _b : {});
|
|
28
|
-
var description = resolveDescription(response);
|
|
29
|
-
if (content.length === 0 && !description && headers.length === 0) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
return (<div className="openapi-response-body">
|
|
33
|
-
{headers.length > 0 ? (<OpenAPIDisclosure header={<OpenAPISchemaPresentation context={context} property={{
|
|
34
|
-
propertyName: tString(context.translation, 'headers'),
|
|
35
|
-
schema: {
|
|
36
|
-
type: 'object',
|
|
37
|
-
},
|
|
38
|
-
required: null,
|
|
39
|
-
}}/>} icon={context.icons.plus} label={function (isExpanded) {
|
|
40
|
-
return tString(context.translation, isExpanded ? 'hide' : 'show', tString(context.translation, headers.length === 1 ? 'header' : 'headers'));
|
|
41
|
-
}}>
|
|
42
|
-
<OpenAPISchemaProperties properties={headers.map(function (_a) {
|
|
43
|
-
var name = _a[0], header = _a[1];
|
|
44
|
-
return parameterToProperty(__assign({ name: name }, header));
|
|
45
|
-
})} context={context}/>
|
|
46
|
-
</OpenAPIDisclosure>) : null}
|
|
47
|
-
{(mediaType === null || mediaType === void 0 ? void 0 : mediaType.schema) && (<div className="openapi-responsebody">
|
|
48
|
-
<OpenAPISchemaProperties id={"response-".concat(context.blockKey)} properties={[
|
|
49
|
-
{
|
|
50
|
-
schema: mediaType.schema,
|
|
51
|
-
propertyName: tString(context.translation, 'response'),
|
|
52
|
-
required: null,
|
|
53
|
-
},
|
|
54
|
-
]} context={context}/>
|
|
55
|
-
</div>)}
|
|
56
|
-
</div>);
|
|
57
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type OpenAPIContext } from './context';
|
|
2
|
-
import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Display an example of the response content.
|
|
5
|
-
*/
|
|
6
|
-
export declare function OpenAPIResponseExample(props: {
|
|
7
|
-
data: OpenAPIOperationData | OpenAPIWebhookData;
|
|
8
|
-
context: OpenAPIContext;
|
|
9
|
-
}): import("react").JSX.Element | null;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { Markdown } from './Markdown';
|
|
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, resolveDescription } from './utils';
|
|
8
|
-
import { checkIsReference } from './utils';
|
|
9
|
-
/**
|
|
10
|
-
* Display an example of the response content.
|
|
11
|
-
*/
|
|
12
|
-
export function OpenAPIResponseExample(props) {
|
|
13
|
-
var data = props.data, context = props.context;
|
|
14
|
-
// if there are no responses defined for the operation
|
|
15
|
-
if (!data.operation.responses) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
var responses = Object.entries(data.operation.responses);
|
|
19
|
-
// Sort response to get 200, and 2xx first
|
|
20
|
-
responses.sort(function (_a, _b) {
|
|
21
|
-
var a = _a[0];
|
|
22
|
-
var b = _b[0];
|
|
23
|
-
if (a === 'default') {
|
|
24
|
-
return 1;
|
|
25
|
-
}
|
|
26
|
-
if (b === 'default') {
|
|
27
|
-
return -1;
|
|
28
|
-
}
|
|
29
|
-
if (a === '200') {
|
|
30
|
-
return -1;
|
|
31
|
-
}
|
|
32
|
-
if (b === '200') {
|
|
33
|
-
return 1;
|
|
34
|
-
}
|
|
35
|
-
return Number(a) - Number(b);
|
|
36
|
-
});
|
|
37
|
-
var tabs = responses
|
|
38
|
-
.filter(function (_a) {
|
|
39
|
-
var _ = _a[0], responseObject = _a[1];
|
|
40
|
-
return responseObject &&
|
|
41
|
-
typeof responseObject === 'object' &&
|
|
42
|
-
// Make sure the response is not hidden
|
|
43
|
-
!responseObject['x-hideSample'];
|
|
44
|
-
})
|
|
45
|
-
.map(function (_a) {
|
|
46
|
-
var key = _a[0], responseObject = _a[1];
|
|
47
|
-
var description = resolveDescription(responseObject);
|
|
48
|
-
var label = description ? (<Markdown key={"response-description-".concat(key)} source={description}/>) : (getStatusCodeDefaultLabel(key, context));
|
|
49
|
-
if (checkIsReference(responseObject)) {
|
|
50
|
-
return {
|
|
51
|
-
key: key,
|
|
52
|
-
label: label,
|
|
53
|
-
statusCode: key,
|
|
54
|
-
body: (<OpenAPIExample example={getExampleFromReference(responseObject, context)} context={context} syntax="json"/>),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
if (!responseObject.content || Object.keys(responseObject.content).length === 0) {
|
|
58
|
-
return {
|
|
59
|
-
key: key,
|
|
60
|
-
label: label,
|
|
61
|
-
statusCode: key,
|
|
62
|
-
body: <OpenAPIEmptyExample context={context}/>,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
key: key,
|
|
67
|
-
label: label,
|
|
68
|
-
statusCode: key,
|
|
69
|
-
body: <OpenAPIResponse context={context} content={responseObject.content}/>,
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
if (tabs.length === 0) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
return (<OpenAPIResponseExampleContent selectIcon={context.icons.chevronDown} blockKey={context.blockKey} items={tabs}/>);
|
|
76
|
-
}
|
|
77
|
-
function OpenAPIResponse(props) {
|
|
78
|
-
var context = props.context, content = props.content;
|
|
79
|
-
var entries = Object.entries(content);
|
|
80
|
-
var firstEntry = entries[0];
|
|
81
|
-
if (!firstEntry) {
|
|
82
|
-
throw new Error('One media type is required');
|
|
83
|
-
}
|
|
84
|
-
var tabs = entries.map(function (entry) {
|
|
85
|
-
var mediaType = entry[0], mediaTypeObject = entry[1];
|
|
86
|
-
if (!mediaTypeObject) {
|
|
87
|
-
return {
|
|
88
|
-
key: mediaType,
|
|
89
|
-
label: mediaType,
|
|
90
|
-
body: <OpenAPIEmptyExample context={context}/>,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
key: mediaType,
|
|
95
|
-
label: mediaType,
|
|
96
|
-
body: <></>,
|
|
97
|
-
examples: getExamples({
|
|
98
|
-
mediaTypeObject: mediaTypeObject,
|
|
99
|
-
mediaType: mediaType,
|
|
100
|
-
context: context,
|
|
101
|
-
}),
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
return (<OpenAPIMediaTypeContent selectIcon={context.icons.chevronDown} stateKey={createStateKey('response-media-types', context.blockKey)} items={tabs} context={getOpenAPIClientContext(context)}/>);
|
|
105
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
declare function OpenAPIResponseExampleItem(props: {
|
|
20
|
-
item: OpenAPIResponseExampleItem;
|
|
21
|
-
}): import("react").JSX.Element;
|
|
22
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
|
|
4
|
-
import { StaticSection } from './StaticSection';
|
|
5
|
-
import { createStateKey, getStatusCodeClassName } from './utils';
|
|
6
|
-
/**
|
|
7
|
-
* Get the state of the response examples select.
|
|
8
|
-
*/
|
|
9
|
-
export function useResponseExamplesState(blockKey, initialKey) {
|
|
10
|
-
if (initialKey === void 0) { initialKey = 'default'; }
|
|
11
|
-
return useSelectState(getResponseExampleStateKey(blockKey), initialKey);
|
|
12
|
-
}
|
|
13
|
-
export function OpenAPIResponseExampleContent(props) {
|
|
14
|
-
var blockKey = props.blockKey, items = props.items, selectIcon = props.selectIcon;
|
|
15
|
-
return (<StaticSection header={<OpenAPIResponseExampleHeader selectIcon={selectIcon} blockKey={blockKey} items={items}/>} className="openapi-response-examples">
|
|
16
|
-
<OpenAPIResponseExampleBody blockKey={blockKey} items={items}/>
|
|
17
|
-
</StaticSection>);
|
|
18
|
-
}
|
|
19
|
-
function OpenAPIResponseExampleHeader(props) {
|
|
20
|
-
var items = props.items, blockKey = props.blockKey, selectIcon = props.selectIcon;
|
|
21
|
-
if (items.length === 1) {
|
|
22
|
-
var item = items[0];
|
|
23
|
-
if (!item) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
return (<span className="openapi-response-examples-statuscode-title">
|
|
27
|
-
<OpenAPIResponseExampleItem item={item}/>
|
|
28
|
-
</span>);
|
|
29
|
-
}
|
|
30
|
-
return (<OpenAPISelect items={items} icon={selectIcon} stateKey={getResponseExampleStateKey(blockKey)} placement="bottom start">
|
|
31
|
-
{items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
|
|
32
|
-
<OpenAPIResponseExampleItem item={item}/>
|
|
33
|
-
</OpenAPISelectItem>); })}
|
|
34
|
-
</OpenAPISelect>);
|
|
35
|
-
}
|
|
36
|
-
function OpenAPIResponseExampleItem(props) {
|
|
37
|
-
var item = props.item;
|
|
38
|
-
return (<>
|
|
39
|
-
<span className={clsx('openapi-statuscode', "openapi-statuscode-".concat(getStatusCodeClassName(item.statusCode)), 'openapi-response-examples-statuscode')}>
|
|
40
|
-
{item.statusCode}
|
|
41
|
-
</span>
|
|
42
|
-
<span className="openapi-response-examples-statuscode-label">{item.label}</span>
|
|
43
|
-
</>);
|
|
44
|
-
}
|
|
45
|
-
function OpenAPIResponseExampleBody(props) {
|
|
46
|
-
var _a, _b;
|
|
47
|
-
var blockKey = props.blockKey, items = props.items;
|
|
48
|
-
var state = useResponseExamplesState(blockKey, (_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
|
|
49
|
-
var selectedItem = (_b = items.find(function (item) { return item.key === state.key; })) !== null && _b !== void 0 ? _b : items[0];
|
|
50
|
-
if (!selectedItem) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return <div className="openapi-response-examples-panel">{selectedItem.body}</div>;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Return the state key for the response examples.
|
|
57
|
-
*/
|
|
58
|
-
function getResponseExampleStateKey(blockKey) {
|
|
59
|
-
return createStateKey('openapi-responses', blockKey);
|
|
60
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
|
|
2
|
-
import type { OpenAPIClientContext } from './context';
|
|
3
|
-
/**
|
|
4
|
-
* Display an interactive response body.
|
|
5
|
-
*/
|
|
6
|
-
export declare function OpenAPIResponses(props: {
|
|
7
|
-
responses: OpenAPIV3.ResponsesObject | OpenAPIV3_1.ResponsesObject;
|
|
8
|
-
context: OpenAPIClientContext;
|
|
9
|
-
}): import("react").JSX.Element;
|