@gitbook/react-openapi 1.1.9 → 1.2.0
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 +27 -0
- package/dist/InteractiveSection.d.ts +4 -0
- package/dist/InteractiveSection.jsx +14 -13
- package/dist/OpenAPICodeSample.d.ts +3 -2
- package/dist/OpenAPICodeSample.jsx +8 -12
- package/dist/OpenAPICodeSampleInteractive.d.ts +3 -0
- package/dist/OpenAPICodeSampleInteractive.jsx +37 -49
- package/dist/OpenAPICodeSampleSelector.d.ts +14 -0
- package/dist/OpenAPICodeSampleSelector.jsx +44 -0
- 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 +16 -0
- package/dist/OpenAPIExample.jsx +36 -0
- 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 -72
- 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 +12 -2
- package/dist/OpenAPIPath.jsx +10 -4
- 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 +4 -3
- package/dist/OpenAPIResponseExample.jsx +24 -154
- 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 +121 -20
- package/dist/OpenAPISchemaName.d.ts +2 -0
- package/dist/OpenAPISchemaName.jsx +21 -17
- 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 +22 -0
- package/dist/OpenAPISelect.jsx +43 -0
- package/dist/OpenAPISpec.d.ts +3 -2
- package/dist/OpenAPISpec.jsx +11 -9
- package/dist/OpenAPITabs.jsx +9 -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 +75 -0
- package/dist/context.js +43 -0
- package/dist/generateSchemaExample.js +4 -0
- package/dist/getOrCreateStoreByKey.d.ts +10 -0
- package/dist/getOrCreateStoreByKey.js +19 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +3 -0
- package/dist/resolveOpenAPIOperation.js +10 -5
- package/dist/resolveOpenAPIWebhook.d.ts +11 -0
- package/dist/resolveOpenAPIWebhook.js +127 -0
- package/dist/schemas/OpenAPISchemas.d.ts +5 -6
- package/dist/schemas/OpenAPISchemas.jsx +52 -49
- package/dist/schemas/resolveOpenAPISchemas.d.ts +4 -3
- package/dist/schemas/resolveOpenAPISchemas.js +0 -1
- 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 +12 -48
- 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 +22 -18
- package/src/OpenAPICodeSample.tsx +26 -15
- package/src/OpenAPICodeSampleInteractive.tsx +67 -70
- package/src/OpenAPICodeSampleSelector.tsx +94 -0
- package/src/OpenAPICopyButton.tsx +7 -2
- package/src/OpenAPIDisclosure.tsx +20 -22
- package/src/OpenAPIDisclosureGroup.tsx +40 -22
- package/src/OpenAPIExample.tsx +55 -0
- package/src/OpenAPIMediaType.tsx +139 -0
- package/src/OpenAPIOperation.tsx +11 -104
- package/src/OpenAPIOperationDescription.tsx +34 -0
- package/src/OpenAPIOperationStability.tsx +39 -0
- package/src/OpenAPIPath.tsx +26 -6
- package/src/OpenAPIRequestBody.tsx +9 -4
- package/src/OpenAPIResponse.tsx +2 -2
- package/src/OpenAPIResponseExample.tsx +41 -215
- package/src/OpenAPIResponseExampleContent.tsx +123 -0
- package/src/OpenAPIResponses.tsx +83 -62
- package/src/OpenAPISchema.test.ts +80 -0
- package/src/OpenAPISchema.tsx +149 -25
- package/src/OpenAPISchemaName.tsx +28 -19
- package/src/OpenAPISchemaServer.tsx +1 -1
- package/src/OpenAPISecurities.tsx +46 -12
- package/src/OpenAPISelect.tsx +96 -0
- package/src/OpenAPISpec.tsx +21 -10
- package/src/OpenAPITabs.tsx +9 -9
- 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 +99 -0
- package/src/generateSchemaExample.test.ts +1020 -0
- package/src/generateSchemaExample.ts +5 -0
- package/src/getOrCreateStoreByKey.ts +33 -0
- package/src/index.ts +5 -1
- package/src/resolveOpenAPIOperation.ts +14 -3
- package/src/resolveOpenAPIWebhook.ts +99 -0
- package/src/schemas/OpenAPISchemas.tsx +76 -71
- package/src/schemas/resolveOpenAPISchemas.ts +4 -5
- 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 -46
- package/src/util/example.tsx +129 -0
- package/src/utils.ts +67 -0
- package/dist/useSyncedTabsGlobalState.d.ts +0 -10
- package/dist/useSyncedTabsGlobalState.js +0 -20
- package/src/useSyncedTabsGlobalState.ts +0 -35
package/dist/OpenAPISpec.jsx
CHANGED
|
@@ -3,13 +3,15 @@ import { OpenAPIResponses } from './OpenAPIResponses';
|
|
|
3
3
|
import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
|
|
4
4
|
import { OpenAPISecurities } from './OpenAPISecurities';
|
|
5
5
|
import { StaticSection } from './StaticSection';
|
|
6
|
+
import { tString } from './translate';
|
|
6
7
|
import { parameterToProperty } from './utils';
|
|
7
8
|
export function OpenAPISpec(props) {
|
|
8
9
|
var _a;
|
|
9
10
|
var data = props.data, context = props.context;
|
|
10
|
-
var operation = data.operation
|
|
11
|
+
var operation = data.operation;
|
|
11
12
|
var parameters = (_a = operation.parameters) !== null && _a !== void 0 ? _a : [];
|
|
12
|
-
var parameterGroups = groupParameters(parameters);
|
|
13
|
+
var parameterGroups = groupParameters(parameters, context);
|
|
14
|
+
var securities = 'securities' in data ? data.securities : [];
|
|
13
15
|
return (<>
|
|
14
16
|
{securities.length > 0 ? (<OpenAPISecurities key="securities" securities={securities} context={context}/>) : null}
|
|
15
17
|
|
|
@@ -19,18 +21,18 @@ export function OpenAPISpec(props) {
|
|
|
19
21
|
</StaticSection>);
|
|
20
22
|
})}
|
|
21
23
|
|
|
22
|
-
{operation.requestBody ? (<OpenAPIRequestBody key="body" requestBody={operation.requestBody} context={context}/>) : null}
|
|
24
|
+
{operation.requestBody ? (<OpenAPIRequestBody key="body" requestBody={operation.requestBody} context={context} data={data}/>) : null}
|
|
23
25
|
{operation.responses ? (<OpenAPIResponses key="responses" responses={operation.responses} context={context}/>) : null}
|
|
24
26
|
</>);
|
|
25
27
|
}
|
|
26
|
-
function groupParameters(parameters) {
|
|
28
|
+
function groupParameters(parameters, context) {
|
|
27
29
|
var sorted = ['path', 'query', 'header'];
|
|
28
30
|
var groups = [];
|
|
29
31
|
parameters
|
|
30
32
|
.filter(function (parameter) { return parameter.in; })
|
|
31
33
|
.forEach(function (parameter) {
|
|
32
34
|
var key = parameter.in;
|
|
33
|
-
var label = getParameterGroupName(parameter.in);
|
|
35
|
+
var label = getParameterGroupName(parameter.in, context);
|
|
34
36
|
var group = groups.find(function (group) { return group.key === key; });
|
|
35
37
|
if (group) {
|
|
36
38
|
group.parameters.push(parameter);
|
|
@@ -46,14 +48,14 @@ function groupParameters(parameters) {
|
|
|
46
48
|
groups.sort(function (a, b) { return sorted.indexOf(a.key) - sorted.indexOf(b.key); });
|
|
47
49
|
return groups;
|
|
48
50
|
}
|
|
49
|
-
function getParameterGroupName(paramIn) {
|
|
51
|
+
function getParameterGroupName(paramIn, context) {
|
|
50
52
|
switch (paramIn) {
|
|
51
53
|
case 'path':
|
|
52
|
-
return
|
|
54
|
+
return tString(context.translation, 'path_parameters');
|
|
53
55
|
case 'query':
|
|
54
|
-
return
|
|
56
|
+
return tString(context.translation, 'query_parameters');
|
|
55
57
|
case 'header':
|
|
56
|
-
return
|
|
58
|
+
return tString(context.translation, 'header_parameters');
|
|
57
59
|
default:
|
|
58
60
|
return paramIn;
|
|
59
61
|
}
|
package/dist/OpenAPITabs.jsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { Tab, TabList, TabPanel, Tabs } from 'react-aria-components';
|
|
4
4
|
import { useEventCallback } from 'usehooks-ts';
|
|
5
|
-
import {
|
|
5
|
+
import { getOrCreateStoreByKey } from './getOrCreateStoreByKey';
|
|
6
6
|
var OpenAPITabsContext = createContext(null);
|
|
7
7
|
function useOpenAPITabsContext() {
|
|
8
8
|
var context = useContext(OpenAPITabsContext);
|
|
@@ -20,8 +20,8 @@ export function OpenAPITabs(props) {
|
|
|
20
20
|
var _c = useState(function () {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
if (stateKey && typeof window !== 'undefined') {
|
|
23
|
-
var store =
|
|
24
|
-
var tabKey_1 = store.getState().
|
|
23
|
+
var store = getOrCreateStoreByKey(stateKey);
|
|
24
|
+
var tabKey_1 = store.getState().key;
|
|
25
25
|
if (tabKey_1) {
|
|
26
26
|
return tabKey_1;
|
|
27
27
|
}
|
|
@@ -44,11 +44,11 @@ export function OpenAPITabs(props) {
|
|
|
44
44
|
if (!stateKey) {
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
|
-
var store =
|
|
47
|
+
var store = getOrCreateStoreByKey(stateKey);
|
|
48
48
|
return store.subscribe(function (state) {
|
|
49
49
|
var _a;
|
|
50
50
|
(_a = cancelDeferRef.current) === null || _a === void 0 ? void 0 : _a.call(cancelDeferRef);
|
|
51
|
-
cancelDeferRef.current = defer(function () { return selectTab(state.
|
|
51
|
+
cancelDeferRef.current = defer(function () { return selectTab(state.key); });
|
|
52
52
|
});
|
|
53
53
|
}, [stateKey, selectTab]);
|
|
54
54
|
useEffect(function () {
|
|
@@ -59,8 +59,8 @@ export function OpenAPITabs(props) {
|
|
|
59
59
|
<Tabs className="openapi-tabs" onSelectionChange={function (tabKey) {
|
|
60
60
|
selectTab(tabKey);
|
|
61
61
|
if (stateKey) {
|
|
62
|
-
var store =
|
|
63
|
-
store.setState({
|
|
62
|
+
var store = getOrCreateStoreByKey(stateKey);
|
|
63
|
+
store.setState({ key: tabKey });
|
|
64
64
|
}
|
|
65
65
|
}} selectedKey={tabKey}>
|
|
66
66
|
{children}
|
|
@@ -103,7 +103,7 @@ export function OpenAPITabsPanels() {
|
|
|
103
103
|
}
|
|
104
104
|
var key = selectedTab.key.toString();
|
|
105
105
|
return (<TabPanel id={key} className="openapi-tabs-panel">
|
|
106
|
-
<div className="openapi-
|
|
107
|
-
{selectedTab.footer ? (<div className="openapi-
|
|
106
|
+
<div className="openapi-panel-body">{selectedTab.body}</div>
|
|
107
|
+
{selectedTab.footer ? (<div className="openapi-panel-footer">{selectedTab.footer}</div>) : null}
|
|
108
108
|
</TabPanel>);
|
|
109
109
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type OpenAPIContextInput } from './context';
|
|
2
|
+
import type { OpenAPIWebhookData } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Display an interactive OpenAPI webhook.
|
|
5
|
+
*/
|
|
6
|
+
export declare function OpenAPIWebhook(props: {
|
|
7
|
+
className?: string;
|
|
8
|
+
data: OpenAPIWebhookData;
|
|
9
|
+
context: OpenAPIContextInput;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import { OpenAPIWebhookExample } from './OpenAPIWebhookExample';
|
|
3
|
+
import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec';
|
|
4
|
+
import { OpenAPISummary } from './common/OpenAPISummary';
|
|
5
|
+
import { resolveOpenAPIContext } from './context';
|
|
6
|
+
/**
|
|
7
|
+
* Display an interactive OpenAPI webhook.
|
|
8
|
+
*/
|
|
9
|
+
export function OpenAPIWebhook(props) {
|
|
10
|
+
var className = props.className, data = props.data, contextInput = props.context;
|
|
11
|
+
var context = resolveOpenAPIContext(contextInput);
|
|
12
|
+
return (<div className={clsx('openapi-webhook', className)}>
|
|
13
|
+
<OpenAPISummary data={data} context={context}/>
|
|
14
|
+
<div className="openapi-columns">
|
|
15
|
+
<OpenAPIColumnSpec data={data} context={context}/>
|
|
16
|
+
<div className="openapi-column-preview">
|
|
17
|
+
<div className="openapi-column-preview-body">
|
|
18
|
+
<OpenAPIWebhookExample data={data} context={context}/>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</div>);
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { OpenAPIEmptyExample } from './OpenAPIExample';
|
|
2
|
+
import { OpenAPIMediaTypeContent } from './OpenAPIMediaType';
|
|
3
|
+
import { getOpenAPIClientContext } from './context';
|
|
4
|
+
import { getExamples } from './util/example';
|
|
5
|
+
import { createStateKey } from './utils';
|
|
6
|
+
export function OpenAPIWebhookExample(props) {
|
|
7
|
+
var data = props.data, context = props.context;
|
|
8
|
+
var operation = data.operation;
|
|
9
|
+
var items = (function () {
|
|
10
|
+
if (!operation.requestBody) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
return Object.entries(operation.requestBody.content).map(function (_a) {
|
|
14
|
+
var key = _a[0], value = _a[1];
|
|
15
|
+
var schema = value.schema;
|
|
16
|
+
if (!schema) {
|
|
17
|
+
return {
|
|
18
|
+
key: key,
|
|
19
|
+
label: key,
|
|
20
|
+
body: <OpenAPIEmptyExample context={context}/>,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
key: key,
|
|
25
|
+
label: key,
|
|
26
|
+
body: <></>,
|
|
27
|
+
examples: getExamples({
|
|
28
|
+
mediaTypeObject: value,
|
|
29
|
+
mediaType: key,
|
|
30
|
+
context: context,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
})();
|
|
35
|
+
return (<div className="openapi-panel">
|
|
36
|
+
<h4 className="openapi-panel-heading">Payload</h4>
|
|
37
|
+
<div className="openapi-panel-body">
|
|
38
|
+
<OpenAPIMediaTypeContent selectIcon={context.icons.chevronDown} stateKey={createStateKey('request-body-media-type', context.blockKey)} items={items} context={getOpenAPIClientContext(context)}/>
|
|
39
|
+
</div>
|
|
40
|
+
</div>);
|
|
41
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { OpenAPIV3_1 } from '@gitbook/openapi-parser';
|
|
2
|
+
import type { OpenAPIClientContext } from './context';
|
|
2
3
|
/**
|
|
3
4
|
* Button which launches the Scalar API Client
|
|
4
5
|
*/
|
|
@@ -6,4 +7,5 @@ export declare function ScalarApiButton(props: {
|
|
|
6
7
|
method: OpenAPIV3_1.HttpMethods;
|
|
7
8
|
path: string;
|
|
8
9
|
specUrl: string;
|
|
10
|
+
context: OpenAPIClientContext;
|
|
9
11
|
}): import("react").JSX.Element;
|
package/dist/ScalarApiButton.jsx
CHANGED
|
@@ -3,11 +3,12 @@ import { ApiClientModalProvider, useApiClientModal } from '@scalar/api-client-re
|
|
|
3
3
|
import { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
5
|
import { useOpenAPIOperationContext } from './OpenAPIOperationContext';
|
|
6
|
+
import { t } from './translate';
|
|
6
7
|
/**
|
|
7
8
|
* Button which launches the Scalar API Client
|
|
8
9
|
*/
|
|
9
10
|
export function ScalarApiButton(props) {
|
|
10
|
-
var method = props.method, path = props.path, specUrl = props.specUrl;
|
|
11
|
+
var method = props.method, path = props.path, specUrl = props.specUrl, context = props.context;
|
|
11
12
|
var _a = useState(false), isOpen = _a[0], setIsOpen = _a[1];
|
|
12
13
|
var controllerRef = useRef(null);
|
|
13
14
|
return (<div className="scalar scalar-activate">
|
|
@@ -16,7 +17,7 @@ export function ScalarApiButton(props) {
|
|
|
16
17
|
(_b = (_a = controllerRef.current) === null || _a === void 0 ? void 0 : _a.openClient) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
17
18
|
setIsOpen(true);
|
|
18
19
|
}}>
|
|
19
|
-
|
|
20
|
+
{t(context.translation, 'test_it')}
|
|
20
21
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 12" fill="currentColor">
|
|
21
22
|
<path stroke="currentColor" strokeWidth="1.5" d="M1 10.05V1.43c0-.2.2-.31.37-.22l7.26 4.08c.17.1.17.33.01.43l-7.26 4.54a.25.25 0 0 1-.38-.21Z"/>
|
|
22
23
|
</svg>
|
|
@@ -28,7 +29,7 @@ export function ScalarApiButton(props) {
|
|
|
28
29
|
}
|
|
29
30
|
function ScalarModal(props) {
|
|
30
31
|
var method = props.method, path = props.path, specUrl = props.specUrl, controllerRef = props.controllerRef;
|
|
31
|
-
return (<ApiClientModalProvider configuration={{
|
|
32
|
+
return (<ApiClientModalProvider configuration={{ url: specUrl }} initialRequest={{ method: method, path: path }}>
|
|
32
33
|
<ScalarModalController method={method} path={path} controllerRef={controllerRef}/>
|
|
33
34
|
</ApiClientModalProvider>);
|
|
34
35
|
}
|
package/dist/StaticSection.d.ts
CHANGED
|
@@ -3,8 +3,11 @@ export declare function Section(props: ComponentPropsWithoutRef<'div'>): import(
|
|
|
3
3
|
export declare function SectionHeader(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
|
|
4
4
|
export declare function SectionHeaderContent(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
|
|
5
5
|
export declare const SectionBody: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
6
|
+
export declare function SectionFooter(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
|
|
7
|
+
export declare function SectionFooterContent(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
|
|
6
8
|
export declare function StaticSection(props: {
|
|
7
9
|
className: string;
|
|
8
|
-
header
|
|
10
|
+
header?: React.ReactNode;
|
|
9
11
|
children: React.ReactNode;
|
|
12
|
+
footer?: React.ReactNode;
|
|
10
13
|
}): import("react").JSX.Element;
|
package/dist/StaticSection.jsx
CHANGED
|
@@ -12,12 +12,21 @@ export function SectionHeaderContent(props) {
|
|
|
12
12
|
export var SectionBody = forwardRef(function SectionBody(props, ref) {
|
|
13
13
|
return (<div ref={ref} {...props} className={clsx('openapi-section-body', props.className && "".concat(props.className, "-body"))}/>);
|
|
14
14
|
});
|
|
15
|
+
export function SectionFooter(props) {
|
|
16
|
+
return (<div {...props} className={clsx('openapi-section-footer', props.className && "".concat(props.className, "-footer"))}/>);
|
|
17
|
+
}
|
|
18
|
+
export function SectionFooterContent(props) {
|
|
19
|
+
return (<div {...props} className={clsx('openapi-section-footer-content', props.className && "".concat(props.className, "-footer-content"))}/>);
|
|
20
|
+
}
|
|
15
21
|
export function StaticSection(props) {
|
|
16
|
-
var className = props.className, header = props.header, children = props.children;
|
|
22
|
+
var className = props.className, header = props.header, children = props.children, footer = props.footer;
|
|
17
23
|
return (<Section className={className}>
|
|
18
|
-
<SectionHeader className={className}>
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
{header ? (<SectionHeader className={className}>
|
|
25
|
+
<SectionHeaderContent className={className}>{header}</SectionHeaderContent>
|
|
26
|
+
</SectionHeader>) : null}
|
|
21
27
|
<SectionBody className={className}>{children}</SectionBody>
|
|
28
|
+
{footer ? (<SectionFooter className={className}>
|
|
29
|
+
<SectionFooterContent className={className}>{footer}</SectionFooterContent>
|
|
30
|
+
</SectionFooter>) : null}
|
|
22
31
|
</Section>);
|
|
23
32
|
}
|
package/dist/code-samples.js
CHANGED
|
@@ -9,10 +9,44 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import { isCSV, isFormData, isFormUrlEncoded, isGraphQL, isPDF, isPlainObject, isText, isXML, } from './contentTypeChecks';
|
|
12
|
+
import { isCSV, isFormData, isFormUrlEncoded, isGraphQL, isJSON, isPDF, isPlainObject, isText, isXML, } from './contentTypeChecks';
|
|
13
13
|
import { json2xml } from './json2xml';
|
|
14
14
|
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
15
15
|
export var codeSampleGenerators = [
|
|
16
|
+
{
|
|
17
|
+
id: 'http',
|
|
18
|
+
label: 'HTTP',
|
|
19
|
+
syntax: 'bash',
|
|
20
|
+
generate: function (_a) {
|
|
21
|
+
var method = _a.method, url = _a.url, _b = _a.headers, headers = _b === void 0 ? {} : _b, body = _a.body;
|
|
22
|
+
var _c = parseHostAndPath(url), host = _c.host, path = _c.path;
|
|
23
|
+
if (body) {
|
|
24
|
+
// if we had a body add a content length header
|
|
25
|
+
var bodyContent = body ? stringifyOpenAPI(body) : '';
|
|
26
|
+
// handle unicode chars with a text encoder
|
|
27
|
+
var encoder = new TextEncoder();
|
|
28
|
+
var bodyString_1 = BodyGenerators.getHTTPBody(body, headers);
|
|
29
|
+
if (bodyString_1) {
|
|
30
|
+
body = bodyString_1;
|
|
31
|
+
}
|
|
32
|
+
headers = __assign(__assign({}, headers), { 'Content-Length': encoder.encode(bodyContent).length.toString() });
|
|
33
|
+
}
|
|
34
|
+
if (!headers.hasOwnProperty('Accept')) {
|
|
35
|
+
headers.Accept = '*/*';
|
|
36
|
+
}
|
|
37
|
+
var headerString = headers
|
|
38
|
+
? "".concat(Object.entries(headers)
|
|
39
|
+
.map(function (_a) {
|
|
40
|
+
var key = _a[0], value = _a[1];
|
|
41
|
+
return key.toLowerCase() !== 'host' ? "".concat(key, ": ").concat(value) : '';
|
|
42
|
+
})
|
|
43
|
+
.join('\n'), "\n")
|
|
44
|
+
: '';
|
|
45
|
+
var bodyString = body ? "\n".concat(body) : '';
|
|
46
|
+
var httpRequest = "".concat(method.toUpperCase(), " ").concat(decodeURI(path), " HTTP/1.1\nHost: ").concat(host, "\n").concat(headerString).concat(bodyString);
|
|
47
|
+
return httpRequest;
|
|
48
|
+
},
|
|
49
|
+
},
|
|
16
50
|
{
|
|
17
51
|
id: 'curl',
|
|
18
52
|
label: 'cURL',
|
|
@@ -98,12 +132,16 @@ export var codeSampleGenerators = [
|
|
|
98
132
|
if (headers && Object.keys(headers).length > 0) {
|
|
99
133
|
code += indent("headers=".concat(stringifyOpenAPI(headers), ",\n"), 4);
|
|
100
134
|
}
|
|
135
|
+
var contentType = headers === null || headers === void 0 ? void 0 : headers['Content-Type'];
|
|
101
136
|
if (body) {
|
|
102
137
|
if (body === 'files') {
|
|
103
138
|
code += indent("files=".concat(body, "\n"), 4);
|
|
104
139
|
}
|
|
140
|
+
else if (isJSON(contentType)) {
|
|
141
|
+
code += indent("data=json.dumps(".concat(body, ")\n"), 4);
|
|
142
|
+
}
|
|
105
143
|
else {
|
|
106
|
-
code += indent("data=".concat(
|
|
144
|
+
code += indent("data=".concat(body, "\n"), 4);
|
|
107
145
|
}
|
|
108
146
|
}
|
|
109
147
|
code += ')\n\n';
|
|
@@ -111,40 +149,6 @@ export var codeSampleGenerators = [
|
|
|
111
149
|
return code;
|
|
112
150
|
},
|
|
113
151
|
},
|
|
114
|
-
{
|
|
115
|
-
id: 'http',
|
|
116
|
-
label: 'HTTP',
|
|
117
|
-
syntax: 'bash',
|
|
118
|
-
generate: function (_a) {
|
|
119
|
-
var method = _a.method, url = _a.url, _b = _a.headers, headers = _b === void 0 ? {} : _b, body = _a.body;
|
|
120
|
-
var _c = parseHostAndPath(url), host = _c.host, path = _c.path;
|
|
121
|
-
if (body) {
|
|
122
|
-
// if we had a body add a content length header
|
|
123
|
-
var bodyContent = body ? stringifyOpenAPI(body) : '';
|
|
124
|
-
// handle unicode chars with a text encoder
|
|
125
|
-
var encoder = new TextEncoder();
|
|
126
|
-
var bodyString_1 = BodyGenerators.getHTTPBody(body, headers);
|
|
127
|
-
if (bodyString_1) {
|
|
128
|
-
body = bodyString_1;
|
|
129
|
-
}
|
|
130
|
-
headers = __assign(__assign({}, headers), { 'Content-Length': encoder.encode(bodyContent).length.toString() });
|
|
131
|
-
}
|
|
132
|
-
if (!headers.hasOwnProperty('Accept')) {
|
|
133
|
-
headers.Accept = '*/*';
|
|
134
|
-
}
|
|
135
|
-
var headerString = headers
|
|
136
|
-
? "".concat(Object.entries(headers)
|
|
137
|
-
.map(function (_a) {
|
|
138
|
-
var key = _a[0], value = _a[1];
|
|
139
|
-
return key.toLowerCase() !== 'host' ? "".concat(key, ": ").concat(value) : '';
|
|
140
|
-
})
|
|
141
|
-
.join('\n'), "\n")
|
|
142
|
-
: '';
|
|
143
|
-
var bodyString = body ? "\n".concat(body) : '';
|
|
144
|
-
var httpRequest = "".concat(method.toUpperCase(), " ").concat(decodeURI(path), " HTTP/1.1\nHost: ").concat(host, "\n").concat(headerString).concat(bodyString);
|
|
145
|
-
return httpRequest;
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
152
|
];
|
|
149
153
|
function indent(code, spaces) {
|
|
150
154
|
var indent = ' '.repeat(spaces);
|
|
@@ -319,15 +323,29 @@ var BodyGenerators = {
|
|
|
319
323
|
code += '}\n\n';
|
|
320
324
|
body = 'files';
|
|
321
325
|
}
|
|
322
|
-
if (isPDF(contentType)) {
|
|
326
|
+
else if (isPDF(contentType)) {
|
|
323
327
|
code += 'files = {\n';
|
|
324
328
|
code += "".concat(indent("\"file\": \"".concat(body, "\","), 4), "\n");
|
|
325
329
|
code += '}\n\n';
|
|
326
330
|
body = 'files';
|
|
327
331
|
}
|
|
328
|
-
if (isXML(contentType)) {
|
|
332
|
+
else if (isXML(contentType)) {
|
|
329
333
|
// Convert JSON to XML if needed
|
|
330
|
-
body = convertBodyToXML(body);
|
|
334
|
+
body = JSON.stringify(convertBodyToXML(body));
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
body = stringifyOpenAPI(body, function (_key, value) {
|
|
338
|
+
switch (value) {
|
|
339
|
+
case true:
|
|
340
|
+
return '$$__TRUE__$$';
|
|
341
|
+
case false:
|
|
342
|
+
return '$$__FALSE__$$';
|
|
343
|
+
default:
|
|
344
|
+
return value;
|
|
345
|
+
}
|
|
346
|
+
})
|
|
347
|
+
.replaceAll('"$$__TRUE__$$"', 'True')
|
|
348
|
+
.replaceAll('"$$__FALSE__$$"', 'False');
|
|
331
349
|
}
|
|
332
350
|
return { body: body, code: code, headers: headers };
|
|
333
351
|
},
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type OpenAPIContext } from '../context';
|
|
2
|
+
import type { OpenAPIOperationData, OpenAPIWebhookData } from '../types';
|
|
3
|
+
export declare function OpenAPIColumnSpec(props: {
|
|
4
|
+
data: OpenAPIOperationData | OpenAPIWebhookData;
|
|
5
|
+
context: OpenAPIContext;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OpenAPISpec } from '../OpenAPISpec';
|
|
2
|
+
import { getOpenAPIClientContext } from '../context';
|
|
3
|
+
import { t } from '../translate';
|
|
4
|
+
import { OpenAPIOperationDescription } from './OpenAPIOperationDescription';
|
|
5
|
+
export function OpenAPIColumnSpec(props) {
|
|
6
|
+
var data = props.data, context = props.context;
|
|
7
|
+
var operation = data.operation;
|
|
8
|
+
var clientContext = getOpenAPIClientContext(context);
|
|
9
|
+
return (<div className="openapi-column-spec">
|
|
10
|
+
{operation['x-deprecated-sunset'] ? (<div className="openapi-deprecated-sunset openapi-description openapi-markdown">
|
|
11
|
+
{t(context.translation, 'deprecated_and_sunset_on', [
|
|
12
|
+
<span key="date" className="openapi-deprecated-sunset-date">
|
|
13
|
+
{operation['x-deprecated-sunset']}
|
|
14
|
+
</span>,
|
|
15
|
+
])}
|
|
16
|
+
</div>) : null}
|
|
17
|
+
<OpenAPIOperationDescription operation={operation} context={context}/>
|
|
18
|
+
<OpenAPISpec data={data} context={clientContext}/>
|
|
19
|
+
</div>);
|
|
20
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { OpenAPICustomOperationProperties, OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
+
import type { OpenAPIContext } from '../context';
|
|
3
|
+
export declare function OpenAPIOperationDescription(props: {
|
|
4
|
+
operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
|
|
5
|
+
context: OpenAPIContext;
|
|
6
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Markdown } from '../Markdown';
|
|
2
|
+
import { resolveDescription } from '../utils';
|
|
3
|
+
export function OpenAPIOperationDescription(props) {
|
|
4
|
+
var operation = props.operation;
|
|
5
|
+
if (operation['x-gitbook-description-document']) {
|
|
6
|
+
return (<div className="openapi-intro">
|
|
7
|
+
{props.context.renderDocument({
|
|
8
|
+
document: operation['x-gitbook-description-document'],
|
|
9
|
+
})}
|
|
10
|
+
</div>);
|
|
11
|
+
}
|
|
12
|
+
var description = resolveDescription(operation);
|
|
13
|
+
if (!description) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return (<div className="openapi-intro">
|
|
17
|
+
<Markdown className="openapi-description" source={description}/>
|
|
18
|
+
</div>);
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var stabilityEnum = {
|
|
2
|
+
experimental: 'Experimental',
|
|
3
|
+
alpha: 'Alpha',
|
|
4
|
+
beta: 'Beta',
|
|
5
|
+
};
|
|
6
|
+
export function OpenAPIStability(props) {
|
|
7
|
+
var stability = props.stability;
|
|
8
|
+
var foundStability = stabilityEnum[stability];
|
|
9
|
+
if (!foundStability) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return (<div className={"openapi-stability openapi-stability-".concat(foundStability.toLowerCase())}>
|
|
13
|
+
{foundStability}
|
|
14
|
+
</div>);
|
|
15
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { OpenAPIContext } from '../context';
|
|
2
|
+
import type { OpenAPIOperationData, OpenAPIWebhookData } from '../types';
|
|
3
|
+
export declare function OpenAPISummary(props: {
|
|
4
|
+
data: OpenAPIOperationData | OpenAPIWebhookData;
|
|
5
|
+
context: OpenAPIContext;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { OpenAPIPath } from '../OpenAPIPath';
|
|
2
|
+
import { OpenAPIStability } from './OpenAPIStability';
|
|
3
|
+
export function OpenAPISummary(props) {
|
|
4
|
+
var _a;
|
|
5
|
+
var data = props.data, context = props.context;
|
|
6
|
+
var operation = data.operation;
|
|
7
|
+
var title = (function () {
|
|
8
|
+
if (operation.summary) {
|
|
9
|
+
return operation.summary;
|
|
10
|
+
}
|
|
11
|
+
if ('name' in data) {
|
|
12
|
+
return data.name;
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
})();
|
|
16
|
+
return (<div className="openapi-summary" id={operation.summary ? undefined : context.id}>
|
|
17
|
+
{(operation.deprecated || operation['x-stability']) && (<div className="openapi-summary-tags">
|
|
18
|
+
{operation.deprecated && <div className="openapi-deprecated">Deprecated</div>}
|
|
19
|
+
{operation['x-stability'] && (<OpenAPIStability stability={operation['x-stability']}/>)}
|
|
20
|
+
</div>)}
|
|
21
|
+
{title
|
|
22
|
+
? context.renderHeading({
|
|
23
|
+
deprecated: (_a = operation.deprecated) !== null && _a !== void 0 ? _a : false,
|
|
24
|
+
stability: operation['x-stability'],
|
|
25
|
+
title: title,
|
|
26
|
+
})
|
|
27
|
+
: null}
|
|
28
|
+
{'path' in data ? <OpenAPIPath data={data} context={context}/> : null}
|
|
29
|
+
</div>);
|
|
30
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type Translation, type TranslationLocale } from './translations';
|
|
2
|
+
export interface OpenAPIClientContext {
|
|
3
|
+
/**
|
|
4
|
+
* The translation language to use.
|
|
5
|
+
*/
|
|
6
|
+
translation: Translation;
|
|
7
|
+
/**
|
|
8
|
+
* Icons used in the block.
|
|
9
|
+
*/
|
|
10
|
+
icons: {
|
|
11
|
+
chevronDown: React.ReactNode;
|
|
12
|
+
chevronRight: React.ReactNode;
|
|
13
|
+
plus: React.ReactNode;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Force all sections to be opened by default.
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
defaultInteractiveOpened?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The key of the block
|
|
22
|
+
*/
|
|
23
|
+
blockKey?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Optional id attached to the heading and used as an anchor.
|
|
26
|
+
*/
|
|
27
|
+
id?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Mark the context as a client context.
|
|
30
|
+
*/
|
|
31
|
+
$$isClientContext$$: true;
|
|
32
|
+
}
|
|
33
|
+
export interface OpenAPIContext extends Omit<OpenAPIClientContext, '$$isClientContext$$'> {
|
|
34
|
+
/**
|
|
35
|
+
* Render a code block.
|
|
36
|
+
*/
|
|
37
|
+
renderCodeBlock: (props: {
|
|
38
|
+
code: string;
|
|
39
|
+
syntax: string;
|
|
40
|
+
}) => React.ReactNode;
|
|
41
|
+
/**
|
|
42
|
+
* Render the heading of the operation.
|
|
43
|
+
*/
|
|
44
|
+
renderHeading: (props: {
|
|
45
|
+
deprecated: boolean;
|
|
46
|
+
title: string;
|
|
47
|
+
stability?: string;
|
|
48
|
+
}) => React.ReactNode;
|
|
49
|
+
/**
|
|
50
|
+
* Render the document of the operation.
|
|
51
|
+
*/
|
|
52
|
+
renderDocument: (props: {
|
|
53
|
+
document: object;
|
|
54
|
+
}) => React.ReactNode;
|
|
55
|
+
/**
|
|
56
|
+
* Specification URL.
|
|
57
|
+
*/
|
|
58
|
+
specUrl: string;
|
|
59
|
+
}
|
|
60
|
+
export type OpenAPIUniversalContext = OpenAPIClientContext | OpenAPIContext;
|
|
61
|
+
export interface OpenAPIContextInput extends Omit<OpenAPIContext, 'translation'> {
|
|
62
|
+
/**
|
|
63
|
+
* The translation language to use.
|
|
64
|
+
* @default 'en'
|
|
65
|
+
*/
|
|
66
|
+
locale?: TranslationLocale | undefined;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve OpenAPI context from the input.
|
|
70
|
+
*/
|
|
71
|
+
export declare function resolveOpenAPIContext(context: OpenAPIContextInput): OpenAPIContext;
|
|
72
|
+
/**
|
|
73
|
+
* Get the client context from the OpenAPI context.
|
|
74
|
+
*/
|
|
75
|
+
export declare function getOpenAPIClientContext(context: OpenAPIUniversalContext): OpenAPIClientContext;
|