@gitbook/react-openapi 1.0.0 → 1.0.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 +8 -0
- package/dist/InteractiveSection.d.ts +0 -2
- package/dist/InteractiveSection.jsx +8 -44
- package/dist/OpenAPICodeSample.jsx +9 -11
- package/dist/OpenAPIRequestBody.d.ts +2 -2
- package/dist/OpenAPIRequestBody.jsx +5 -2
- package/dist/OpenAPIResponse.jsx +4 -14
- package/dist/OpenAPIResponseExample.jsx +5 -5
- package/dist/OpenAPIResponses.jsx +2 -3
- package/dist/OpenAPISchema.jsx +15 -25
- package/dist/OpenAPISpec.jsx +4 -4
- package/dist/OpenAPITabs.d.ts +1 -0
- package/dist/OpenAPITabs.jsx +52 -16
- package/dist/generateSchemaExample.js +2 -3
- package/dist/resolveOpenAPIOperation.js +4 -4
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/useSyncedTabsGlobalState.d.ts +1 -0
- package/dist/useSyncedTabsGlobalState.js +16 -0
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +0 -6
- package/package.json +3 -2
- package/src/InteractiveSection.tsx +4 -41
- package/src/OpenAPICodeSample.tsx +9 -11
- package/src/OpenAPIRequestBody.tsx +7 -3
- package/src/OpenAPIResponse.tsx +4 -18
- package/src/OpenAPIResponseExample.tsx +5 -5
- package/src/OpenAPIResponses.tsx +2 -7
- package/src/OpenAPISchema.tsx +16 -27
- package/src/OpenAPISpec.tsx +4 -7
- package/src/OpenAPITabs.tsx +63 -23
- package/src/generateSchemaExample.ts +2 -3
- package/src/resolveOpenAPIOperation.ts +8 -7
- package/src/useSyncedTabsGlobalState.ts +23 -0
- package/src/utils.ts +0 -8
- package/dist/fetchOpenAPIOperation.d.ts +0 -27
- package/dist/fetchOpenAPIOperation.js +0 -195
- package/dist/tsconfig.tsbuildinfo +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -27,7 +27,5 @@ export declare function InteractiveSection(props: {
|
|
|
27
27
|
children?: React.ReactNode;
|
|
28
28
|
/** Children to display within the container */
|
|
29
29
|
overlay?: React.ReactNode;
|
|
30
|
-
/** An optional key referencing a value in global state */
|
|
31
|
-
stateKey?: string;
|
|
32
30
|
}): import("react").JSX.Element;
|
|
33
31
|
export {};
|
|
@@ -1,55 +1,25 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
import clsx from 'clsx';
|
|
14
|
-
import {
|
|
3
|
+
import { useRef, useState } from 'react';
|
|
15
4
|
import { mergeProps, useButton, useDisclosure, useFocusRing } from 'react-aria';
|
|
16
5
|
import { useDisclosureState } from 'react-stately';
|
|
17
|
-
var globalState = {};
|
|
18
|
-
var listeners = new Set();
|
|
19
|
-
function useSyncedTabsGlobalState() {
|
|
20
|
-
var subscribe = useCallback(function (callback) {
|
|
21
|
-
listeners.add(callback);
|
|
22
|
-
return function () { return listeners.delete(callback); };
|
|
23
|
-
}, []);
|
|
24
|
-
var getSnapshot = useCallback(function () { return globalState; }, []);
|
|
25
|
-
var setSyncedTabs = useCallback(function (updater) {
|
|
26
|
-
globalState = updater(globalState);
|
|
27
|
-
listeners.forEach(function (listener) { return listener(); });
|
|
28
|
-
}, []);
|
|
29
|
-
var tabs = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
30
|
-
return [tabs, setSyncedTabs];
|
|
31
|
-
}
|
|
32
6
|
/**
|
|
33
7
|
* To optimize rendering, most of the components are server-components,
|
|
34
8
|
* and the interactiveness is mainly handled by a few key components like this one.
|
|
35
9
|
*/
|
|
36
10
|
export function InteractiveSection(props) {
|
|
37
|
-
var _a, _b, _c
|
|
38
|
-
var id = props.id, className = props.className,
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
? tabs.find(function (tab) { return tab.key === syncedTabs[stateKey]; })
|
|
42
|
-
: undefined;
|
|
43
|
-
var _l = useState((_b = tabFromState === null || tabFromState === void 0 ? void 0 : tabFromState.key) !== null && _b !== void 0 ? _b : defaultTab), selectedTabKey = _l[0], setSelectedTab = _l[1];
|
|
44
|
-
var selectedTab = (_c = tabFromState !== null && tabFromState !== void 0 ? tabFromState : tabs.find(function (tab) { return tab.key === selectedTabKey; })) !== null && _c !== void 0 ? _c : tabs[0];
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
var id = props.id, className = props.className, _d = props.toggeable, toggeable = _d === void 0 ? false : _d, _e = props.defaultOpened, defaultOpened = _e === void 0 ? true : _e, _f = props.tabs, tabs = _f === void 0 ? [] : _f, _g = props.defaultTab, defaultTab = _g === void 0 ? (_a = tabs[0]) === null || _a === void 0 ? void 0 : _a.key : _g, header = props.header, children = props.children, overlay = props.overlay, _h = props.toggleIcon, toggleIcon = _h === void 0 ? '▶' : _h;
|
|
13
|
+
var _j = useState(defaultTab), selectedTabKey = _j[0], setSelectedTab = _j[1];
|
|
14
|
+
var selectedTab = (_b = tabs.find(function (tab) { return tab.key === selectedTabKey; })) !== null && _b !== void 0 ? _b : tabs[0];
|
|
45
15
|
var state = useDisclosureState({
|
|
46
16
|
defaultExpanded: defaultOpened,
|
|
47
17
|
});
|
|
48
18
|
var panelRef = useRef(null);
|
|
49
19
|
var triggerRef = useRef(null);
|
|
50
|
-
var
|
|
20
|
+
var _k = useDisclosure({}, state, panelRef), triggerProps = _k.buttonProps, panelProps = _k.panelProps;
|
|
51
21
|
var buttonProps = useButton(triggerProps, triggerRef).buttonProps;
|
|
52
|
-
var
|
|
22
|
+
var _l = useFocusRing(), isFocusVisible = _l.isFocusVisible, focusProps = _l.focusProps;
|
|
53
23
|
return (<div id={id} className={clsx('openapi-section', toggeable ? 'openapi-section-toggeable' : null, className, toggeable ? "".concat(className, "-").concat(state.isExpanded ? 'opened' : 'closed') : null)}>
|
|
54
24
|
{header ? (<div onClick={function () {
|
|
55
25
|
if (toggeable) {
|
|
@@ -69,14 +39,8 @@ export function InteractiveSection(props) {
|
|
|
69
39
|
<div className={clsx('openapi-section-header-controls', "".concat(className, "-header-controls"))} onClick={function (event) {
|
|
70
40
|
event.stopPropagation();
|
|
71
41
|
}}>
|
|
72
|
-
{tabs.length > 1 ? (<select className={clsx('openapi-section-select', 'openapi-select', "".concat(className, "-tabs-select"))} value={(
|
|
42
|
+
{tabs.length > 1 ? (<select className={clsx('openapi-section-select', 'openapi-select', "".concat(className, "-tabs-select"))} value={(_c = selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.key) !== null && _c !== void 0 ? _c : ''} onChange={function (event) {
|
|
73
43
|
setSelectedTab(event.target.value);
|
|
74
|
-
if (stateKey) {
|
|
75
|
-
setSyncedTabs(function (state) {
|
|
76
|
-
var _a;
|
|
77
|
-
return (__assign(__assign({}, state), (_a = {}, _a[stateKey] = event.target.value, _a)));
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
44
|
state.expand();
|
|
81
45
|
}}>
|
|
82
46
|
{tabs.map(function (tab) { return (<option key={tab.key} value={tab.key}>
|
|
@@ -13,9 +13,10 @@ import { codeSampleGenerators } from './code-samples';
|
|
|
13
13
|
import { generateMediaTypeExample, generateSchemaExample } from './generateSchemaExample';
|
|
14
14
|
import { InteractiveSection } from './InteractiveSection';
|
|
15
15
|
import { getServersURL } from './OpenAPIServerURL';
|
|
16
|
-
import {
|
|
16
|
+
import { createStateKey } from './utils';
|
|
17
17
|
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
18
18
|
import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
|
|
19
|
+
import { checkIsReference } from './utils';
|
|
19
20
|
/**
|
|
20
21
|
* Display code samples to execute the operation.
|
|
21
22
|
* It supports the Redocly custom syntax as well (https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples/)
|
|
@@ -25,30 +26,27 @@ export function OpenAPICodeSample(props) {
|
|
|
25
26
|
var data = props.data, context = props.context;
|
|
26
27
|
var searchParams = new URLSearchParams();
|
|
27
28
|
var headersObject = {};
|
|
28
|
-
(_a = data.operation.parameters) === null || _a === void 0 ? void 0 : _a.forEach(function (
|
|
29
|
-
var param = noReference(rawParam);
|
|
29
|
+
(_a = data.operation.parameters) === null || _a === void 0 ? void 0 : _a.forEach(function (param) {
|
|
30
30
|
if (!param) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
if (param.in === 'header' && param.required) {
|
|
34
|
-
var example = param.schema
|
|
35
|
-
? generateSchemaExample(noReference(param.schema))
|
|
36
|
-
: undefined;
|
|
34
|
+
var example = param.schema ? generateSchemaExample(param.schema) : undefined;
|
|
37
35
|
if (example !== undefined && param.name) {
|
|
38
36
|
headersObject[param.name] =
|
|
39
37
|
typeof example !== 'string' ? stringifyOpenAPI(example) : example;
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
else if (param.in === 'query' && param.required) {
|
|
43
|
-
var example = param.schema
|
|
44
|
-
? generateSchemaExample(noReference(param.schema))
|
|
45
|
-
: undefined;
|
|
41
|
+
var example = param.schema ? generateSchemaExample(param.schema) : undefined;
|
|
46
42
|
if (example !== undefined && param.name) {
|
|
47
43
|
searchParams.append(param.name, String(Array.isArray(example) ? example[0] : example));
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
46
|
});
|
|
51
|
-
var requestBody =
|
|
47
|
+
var requestBody = !checkIsReference(data.operation.requestBody)
|
|
48
|
+
? data.operation.requestBody
|
|
49
|
+
: undefined;
|
|
52
50
|
var requestBodyContentEntries = (requestBody === null || requestBody === void 0 ? void 0 : requestBody.content)
|
|
53
51
|
? Object.entries(requestBody.content)
|
|
54
52
|
: undefined;
|
|
@@ -97,7 +95,7 @@ export function OpenAPICodeSample(props) {
|
|
|
97
95
|
if (samples.length === 0) {
|
|
98
96
|
return null;
|
|
99
97
|
}
|
|
100
|
-
return (<OpenAPITabs items={samples}>
|
|
98
|
+
return (<OpenAPITabs stateKey={createStateKey('codesample')} items={samples}>
|
|
101
99
|
<InteractiveSection header={<OpenAPITabsList />} className="openapi-codesample">
|
|
102
100
|
<OpenAPITabsPanels />
|
|
103
101
|
</InteractiveSection>
|
|
@@ -4,6 +4,6 @@ import type { OpenAPIClientContext } from './types';
|
|
|
4
4
|
* Display an interactive request body.
|
|
5
5
|
*/
|
|
6
6
|
export declare function OpenAPIRequestBody(props: {
|
|
7
|
-
requestBody: OpenAPIV3.RequestBodyObject;
|
|
7
|
+
requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
|
|
8
8
|
context: OpenAPIClientContext;
|
|
9
|
-
}): import("react").JSX.Element;
|
|
9
|
+
}): import("react").JSX.Element | null;
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { OpenAPIRootSchema } from './OpenAPISchema';
|
|
2
|
-
import { noReference } from './utils';
|
|
3
2
|
import { InteractiveSection } from './InteractiveSection';
|
|
3
|
+
import { checkIsReference } from './utils';
|
|
4
4
|
/**
|
|
5
5
|
* Display an interactive request body.
|
|
6
6
|
*/
|
|
7
7
|
export function OpenAPIRequestBody(props) {
|
|
8
8
|
var _a;
|
|
9
9
|
var requestBody = props.requestBody, context = props.context;
|
|
10
|
+
if (checkIsReference(requestBody)) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
10
13
|
return (<InteractiveSection header="Body" className="openapi-requestbody" tabs={Object.entries((_a = requestBody.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
11
14
|
var _b;
|
|
12
15
|
var contentType = _a[0], mediaTypeObject = _a[1];
|
|
13
16
|
return {
|
|
14
17
|
key: contentType,
|
|
15
18
|
label: contentType,
|
|
16
|
-
body: (<OpenAPIRootSchema schema={(_b =
|
|
19
|
+
body: (<OpenAPIRootSchema schema={(_b = mediaTypeObject.schema) !== null && _b !== void 0 ? _b : {}} context={context}/>),
|
|
17
20
|
};
|
|
18
21
|
})}/>);
|
|
19
22
|
}
|
package/dist/OpenAPIResponse.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OpenAPISchemaProperties } from './OpenAPISchema';
|
|
2
|
-
import {
|
|
2
|
+
import { resolveDescription } from './utils';
|
|
3
3
|
import { OpenAPIDisclosure } from './OpenAPIDisclosure';
|
|
4
4
|
/**
|
|
5
5
|
* Display an interactive response body.
|
|
@@ -8,9 +8,8 @@ export function OpenAPIResponse(props) {
|
|
|
8
8
|
var _a, _b, _c;
|
|
9
9
|
var response = props.response, context = props.context, mediaType = props.mediaType;
|
|
10
10
|
var headers = Object.entries((_a = response.headers) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
11
|
-
var _b;
|
|
12
11
|
var name = _a[0], header = _a[1];
|
|
13
|
-
return [name,
|
|
12
|
+
return [name, header !== null && header !== void 0 ? header : {}];
|
|
14
13
|
});
|
|
15
14
|
var content = Object.entries((_b = mediaType.schema) !== null && _b !== void 0 ? _b : {});
|
|
16
15
|
var description = resolveDescription(response);
|
|
@@ -24,7 +23,7 @@ export function OpenAPIResponse(props) {
|
|
|
24
23
|
var name = _a[0], header = _a[1];
|
|
25
24
|
return ({
|
|
26
25
|
propertyName: name,
|
|
27
|
-
schema: (_b =
|
|
26
|
+
schema: (_b = header.schema) !== null && _b !== void 0 ? _b : {},
|
|
28
27
|
required: header.required,
|
|
29
28
|
});
|
|
30
29
|
})} context={context}/>
|
|
@@ -32,18 +31,9 @@ export function OpenAPIResponse(props) {
|
|
|
32
31
|
<div className="openapi-responsebody">
|
|
33
32
|
<OpenAPISchemaProperties id={"response-".concat(context.blockKey)} properties={[
|
|
34
33
|
{
|
|
35
|
-
schema: (_c =
|
|
34
|
+
schema: (_c = mediaType.schema) !== null && _c !== void 0 ? _c : {},
|
|
36
35
|
},
|
|
37
36
|
]} context={context}/>
|
|
38
37
|
</div>
|
|
39
38
|
</div>);
|
|
40
39
|
}
|
|
41
|
-
function handleUnresolvedReference(input) {
|
|
42
|
-
var isReference = checkIsReference(input);
|
|
43
|
-
if (isReference || input === undefined) {
|
|
44
|
-
// If we find a reference that wasn't resolved or needed to be resolved externally, do not try to render it.
|
|
45
|
-
// Instead we render `any`
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
return input;
|
|
49
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { generateSchemaExample } from './generateSchemaExample';
|
|
2
|
-
import { checkIsReference,
|
|
2
|
+
import { checkIsReference, createStateKey, resolveDescription } from './utils';
|
|
3
3
|
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
4
4
|
import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
|
|
5
5
|
import { InteractiveSection } from './InteractiveSection';
|
|
@@ -34,7 +34,7 @@ export function OpenAPIResponseExample(props) {
|
|
|
34
34
|
var examples = responses
|
|
35
35
|
.map(function (_a) {
|
|
36
36
|
var key = _a[0], value = _a[1];
|
|
37
|
-
var responseObject =
|
|
37
|
+
var responseObject = value;
|
|
38
38
|
var mediaTypeObject = (function () {
|
|
39
39
|
var _a;
|
|
40
40
|
if (!responseObject.content) {
|
|
@@ -57,7 +57,7 @@ export function OpenAPIResponseExample(props) {
|
|
|
57
57
|
var key_1 = Object.keys(examples)[0];
|
|
58
58
|
if (key_1) {
|
|
59
59
|
// @TODO handle multiple examples
|
|
60
|
-
var firstExample =
|
|
60
|
+
var firstExample = examples[key_1];
|
|
61
61
|
if (firstExample) {
|
|
62
62
|
return firstExample;
|
|
63
63
|
}
|
|
@@ -66,7 +66,7 @@ export function OpenAPIResponseExample(props) {
|
|
|
66
66
|
if (example) {
|
|
67
67
|
return { value: example };
|
|
68
68
|
}
|
|
69
|
-
var schema =
|
|
69
|
+
var schema = mediaTypeObject.schema;
|
|
70
70
|
if (!schema) {
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
@@ -87,7 +87,7 @@ export function OpenAPIResponseExample(props) {
|
|
|
87
87
|
if (examples.length === 0) {
|
|
88
88
|
return null;
|
|
89
89
|
}
|
|
90
|
-
return (<OpenAPITabs items={examples}>
|
|
90
|
+
return (<OpenAPITabs stateKey={createStateKey('response-example')} items={examples}>
|
|
91
91
|
<InteractiveSection header={<OpenAPITabsList />} className="openapi-response-example">
|
|
92
92
|
<OpenAPITabsPanels />
|
|
93
93
|
</InteractiveSection>
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createStateKey, resolveDescription } from './utils';
|
|
2
1
|
import { OpenAPIResponse } from './OpenAPIResponse';
|
|
3
2
|
import { InteractiveSection } from './InteractiveSection';
|
|
4
3
|
import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
|
|
@@ -8,12 +7,12 @@ import { Markdown } from './Markdown';
|
|
|
8
7
|
*/
|
|
9
8
|
export function OpenAPIResponses(props) {
|
|
10
9
|
var responses = props.responses, context = props.context;
|
|
11
|
-
return (<InteractiveSection
|
|
10
|
+
return (<InteractiveSection header="Responses" className="openapi-responses">
|
|
12
11
|
<OpenAPIDisclosureGroup allowsMultipleExpanded icon={context.icons.chevronRight} groups={Object.entries(responses).map(function (_a) {
|
|
13
12
|
var _b;
|
|
14
13
|
var statusCode = _a[0], response = _a[1];
|
|
15
14
|
var content = Object.entries((_b = response.content) !== null && _b !== void 0 ? _b : {});
|
|
16
|
-
var description =
|
|
15
|
+
var description = response.description;
|
|
17
16
|
return {
|
|
18
17
|
id: statusCode,
|
|
19
18
|
label: (<div className="openapi-response-tab-content" key={"response-".concat(statusCode)}>
|
package/dist/OpenAPISchema.jsx
CHANGED
|
@@ -11,7 +11,7 @@ import clsx from 'clsx';
|
|
|
11
11
|
import { useId } from 'react';
|
|
12
12
|
import { InteractiveSection } from './InteractiveSection';
|
|
13
13
|
import { Markdown } from './Markdown';
|
|
14
|
-
import { checkIsReference,
|
|
14
|
+
import { checkIsReference, resolveDescription } from './utils';
|
|
15
15
|
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
16
16
|
import { OpenAPISchemaName } from './OpenAPISchemaName';
|
|
17
17
|
import { OpenAPIDisclosure } from './OpenAPIDisclosure';
|
|
@@ -32,15 +32,15 @@ export function OpenAPISchemaProperty(props) {
|
|
|
32
32
|
if ((properties && !!properties.length) || schema.type === 'object') {
|
|
33
33
|
return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
|
|
34
34
|
<OpenAPISchemaPresentation {...props}/>
|
|
35
|
-
<OpenAPIDisclosure context={context}>
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
{properties && properties.length > 0 ? (<OpenAPIDisclosure context={context}>
|
|
36
|
+
<OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>
|
|
37
|
+
</OpenAPIDisclosure>) : null}
|
|
38
38
|
</InteractiveSection>);
|
|
39
39
|
}
|
|
40
40
|
if ((_a = alternatives === null || alternatives === void 0 ? void 0 : alternatives[0]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
41
41
|
return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
|
|
42
42
|
<OpenAPISchemaPresentation {...props}/>
|
|
43
|
-
{alternatives[0].map(function (alternative, index) { return (<OpenAPISchemaAlternative key={index} schema={alternative} circularRefs={circularRefs} context={context}/>); })}
|
|
43
|
+
{alternatives[0].map(function (alternative, index) { return (<OpenAPISchemaAlternative key={"alternative-".concat(index)} schema={alternative} circularRefs={circularRefs} context={context}/>); })}
|
|
44
44
|
</InteractiveSection>);
|
|
45
45
|
}
|
|
46
46
|
return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
|
|
@@ -157,9 +157,9 @@ function getSchemaProperties(schema) {
|
|
|
157
157
|
if (schema.allOf) {
|
|
158
158
|
return schema.allOf.reduce(function (acc, subSchema) {
|
|
159
159
|
var _a;
|
|
160
|
-
var properties = (_a = getSchemaProperties(
|
|
160
|
+
var properties = (_a = getSchemaProperties(subSchema)) !== null && _a !== void 0 ? _a : [
|
|
161
161
|
{
|
|
162
|
-
schema:
|
|
162
|
+
schema: subSchema,
|
|
163
163
|
},
|
|
164
164
|
];
|
|
165
165
|
return __spreadArray(__spreadArray([], acc, true), properties, true);
|
|
@@ -167,7 +167,7 @@ function getSchemaProperties(schema) {
|
|
|
167
167
|
}
|
|
168
168
|
// check array AND schema.items as this is sometimes null despite what the type indicates
|
|
169
169
|
if (schema.type === 'array' && !!schema.items) {
|
|
170
|
-
var items =
|
|
170
|
+
var items = schema.items;
|
|
171
171
|
var itemProperties = getSchemaProperties(items);
|
|
172
172
|
if (itemProperties) {
|
|
173
173
|
return itemProperties;
|
|
@@ -183,11 +183,7 @@ function getSchemaProperties(schema) {
|
|
|
183
183
|
var result_1 = [];
|
|
184
184
|
if (schema.properties) {
|
|
185
185
|
Object.entries(schema.properties).forEach(function (_a) {
|
|
186
|
-
var propertyName = _a[0],
|
|
187
|
-
var isReference = checkIsReference(rawPropertySchema);
|
|
188
|
-
var propertySchema = isReference
|
|
189
|
-
? { propertyName: propertyName }
|
|
190
|
-
: rawPropertySchema;
|
|
186
|
+
var propertyName = _a[0], propertySchema = _a[1];
|
|
191
187
|
result_1.push({
|
|
192
188
|
propertyName: propertyName,
|
|
193
189
|
required: Array.isArray(schema.required)
|
|
@@ -198,7 +194,7 @@ function getSchemaProperties(schema) {
|
|
|
198
194
|
});
|
|
199
195
|
}
|
|
200
196
|
if (schema.additionalProperties) {
|
|
201
|
-
var additionalProperties =
|
|
197
|
+
var additionalProperties = schema.additionalProperties;
|
|
202
198
|
result_1.push({
|
|
203
199
|
propertyName: 'Other properties',
|
|
204
200
|
schema: additionalProperties === true ? {} : additionalProperties,
|
|
@@ -215,16 +211,10 @@ export function getSchemaAlternatives(schema, ancestors) {
|
|
|
215
211
|
if (ancestors === void 0) { ancestors = new Set(); }
|
|
216
212
|
var downAncestors = new Set(ancestors).add(schema);
|
|
217
213
|
if (schema.anyOf) {
|
|
218
|
-
return [
|
|
219
|
-
flattenAlternatives('anyOf', schema.anyOf.map(noReference), downAncestors),
|
|
220
|
-
noReference(schema.discriminator),
|
|
221
|
-
];
|
|
214
|
+
return [flattenAlternatives('anyOf', schema.anyOf, downAncestors), schema.discriminator];
|
|
222
215
|
}
|
|
223
216
|
if (schema.oneOf) {
|
|
224
|
-
return [
|
|
225
|
-
flattenAlternatives('oneOf', schema.oneOf.map(noReference), downAncestors),
|
|
226
|
-
noReference(schema.discriminator),
|
|
227
|
-
];
|
|
217
|
+
return [flattenAlternatives('oneOf', schema.oneOf, downAncestors), schema.discriminator];
|
|
228
218
|
}
|
|
229
219
|
if (schema.allOf) {
|
|
230
220
|
// allOf is managed in `getSchemaProperties`
|
|
@@ -251,8 +241,8 @@ discriminator) {
|
|
|
251
241
|
}
|
|
252
242
|
// Try using the discriminator
|
|
253
243
|
if ((discriminator === null || discriminator === void 0 ? void 0 : discriminator.propertyName) && schema.properties) {
|
|
254
|
-
var discriminatorProperty =
|
|
255
|
-
if (discriminatorProperty) {
|
|
244
|
+
var discriminatorProperty = schema.properties[discriminator.propertyName];
|
|
245
|
+
if (discriminatorProperty && !checkIsReference(discriminatorProperty)) {
|
|
256
246
|
if (discriminatorProperty.enum) {
|
|
257
247
|
return discriminatorProperty.enum.map(function (value) { return value.toString(); }).join(' | ');
|
|
258
248
|
}
|
|
@@ -265,7 +255,7 @@ discriminator) {
|
|
|
265
255
|
// check array AND schema.items as this is sometimes null despite what the type indicates
|
|
266
256
|
}
|
|
267
257
|
else if (schema.type === 'array' && !!schema.items) {
|
|
268
|
-
type = "".concat(getSchemaTitle(
|
|
258
|
+
type = "".concat(getSchemaTitle(schema.items), "[]");
|
|
269
259
|
}
|
|
270
260
|
else if (Array.isArray(schema.type)) {
|
|
271
261
|
type = schema.type.join(' | ');
|
package/dist/OpenAPISpec.jsx
CHANGED
|
@@ -15,7 +15,7 @@ import { OpenAPIRequestBody } from './OpenAPIRequestBody';
|
|
|
15
15
|
import { OpenAPIResponses } from './OpenAPIResponses';
|
|
16
16
|
import { OpenAPISchemaProperties } from './OpenAPISchema';
|
|
17
17
|
import { OpenAPISecurities } from './OpenAPISecurities';
|
|
18
|
-
import {
|
|
18
|
+
import { resolveDescription } from './utils';
|
|
19
19
|
/**
|
|
20
20
|
* Client component to render the spec for the request and response.
|
|
21
21
|
*
|
|
@@ -43,15 +43,15 @@ export function OpenAPISpec(props) {
|
|
|
43
43
|
// we use display it if the schema doesn't override it
|
|
44
44
|
description: description, example: parameter.example,
|
|
45
45
|
// Deprecated can be defined at the parameter level
|
|
46
|
-
deprecated: parameter.deprecated }, ((_a =
|
|
46
|
+
deprecated: parameter.deprecated }, ((_a = parameter.schema) !== null && _a !== void 0 ? _a : {})),
|
|
47
47
|
required: parameter.required,
|
|
48
48
|
};
|
|
49
49
|
})} context={context}/>
|
|
50
50
|
</InteractiveSection>);
|
|
51
51
|
})}
|
|
52
52
|
|
|
53
|
-
{operation.requestBody ? (<OpenAPIRequestBody requestBody={
|
|
54
|
-
{operation.responses ? (<OpenAPIResponses responses={
|
|
53
|
+
{operation.requestBody ? (<OpenAPIRequestBody requestBody={operation.requestBody} context={context}/>) : null}
|
|
54
|
+
{operation.responses ? (<OpenAPIResponses responses={operation.responses} context={context}/>) : null}
|
|
55
55
|
</>);
|
|
56
56
|
}
|
|
57
57
|
function groupParameters(parameters) {
|
package/dist/OpenAPITabs.d.ts
CHANGED
package/dist/OpenAPITabs.jsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createContext, useContext, useMemo, useState } from 'react';
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { Tab, TabList, TabPanel, Tabs } from 'react-aria-components';
|
|
4
4
|
import { Markdown } from './Markdown';
|
|
5
|
+
import { useSyncedTabsGlobalState } from './useSyncedTabsGlobalState';
|
|
6
|
+
import { useIntersectionObserver } from 'usehooks-ts';
|
|
5
7
|
var OpenAPITabsContext = createContext(null);
|
|
6
8
|
function useOpenAPITabsContext() {
|
|
7
9
|
var context = useContext(OpenAPITabsContext);
|
|
@@ -14,17 +16,52 @@ function useOpenAPITabsContext() {
|
|
|
14
16
|
* The OpenAPI Tabs wrapper component.
|
|
15
17
|
*/
|
|
16
18
|
export function OpenAPITabs(props) {
|
|
17
|
-
var children = props.children, items = props.items;
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
var children = props.children, items = props.items, stateKey = props.stateKey;
|
|
20
|
+
var isVisible = stateKey
|
|
21
|
+
? useIntersectionObserver({
|
|
22
|
+
threshold: 0.1,
|
|
23
|
+
rootMargin: '200px',
|
|
24
|
+
})
|
|
25
|
+
: true;
|
|
26
|
+
var defaultTab = items[0];
|
|
27
|
+
var _a = useSyncedTabsGlobalState(), syncedTabs = _a[0], setSyncedTabs = _a[1];
|
|
28
|
+
var _b = useState(function () {
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
if (isVisible && stateKey && syncedTabs && syncedTabs.has(stateKey)) {
|
|
31
|
+
var tabFromState = syncedTabs.get(stateKey);
|
|
32
|
+
return (_a = tabFromState === null || tabFromState === void 0 ? void 0 : tabFromState.key) !== null && _a !== void 0 ? _a : (_b = items[0]) === null || _b === void 0 ? void 0 : _b.key;
|
|
22
33
|
}
|
|
23
|
-
return
|
|
24
|
-
}),
|
|
25
|
-
var
|
|
34
|
+
return (_c = items[0]) === null || _c === void 0 ? void 0 : _c.key;
|
|
35
|
+
}), selectedTabKey = _b[0], setSelectedTabKey = _b[1];
|
|
36
|
+
var _c = useState(defaultTab), selectedTab = _c[0], setSelectedTab = _c[1];
|
|
37
|
+
var handleSelectionChange = function (key) {
|
|
38
|
+
setSelectedTabKey(key);
|
|
39
|
+
if (stateKey) {
|
|
40
|
+
var tab_1 = items.find(function (item) { return item.key === key; });
|
|
41
|
+
if (!tab_1) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setSyncedTabs(function (state) {
|
|
45
|
+
var newState = new Map(state);
|
|
46
|
+
newState.set(stateKey, tab_1);
|
|
47
|
+
return newState;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
if (isVisible && stateKey && syncedTabs && syncedTabs.has(stateKey)) {
|
|
53
|
+
var tabFromState_1 = syncedTabs.get(stateKey);
|
|
54
|
+
if (!items.some(function (item) { return item.key === (tabFromState_1 === null || tabFromState_1 === void 0 ? void 0 : tabFromState_1.key); })) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (tabFromState_1 && (tabFromState_1 === null || tabFromState_1 === void 0 ? void 0 : tabFromState_1.key) !== (selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.key)) {
|
|
58
|
+
setSelectedTab(tabFromState_1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}, [isVisible, stateKey, syncedTabs, selectedTabKey]);
|
|
62
|
+
var contextValue = useMemo(function () { return ({ items: items, selectedTab: selectedTab }); }, [items, selectedTab]);
|
|
26
63
|
return (<OpenAPITabsContext.Provider value={contextValue}>
|
|
27
|
-
<Tabs className="openapi-tabs" onSelectionChange={
|
|
64
|
+
<Tabs className="openapi-tabs" onSelectionChange={handleSelectionChange} selectedKey={selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.key}>
|
|
28
65
|
{children}
|
|
29
66
|
</Tabs>
|
|
30
67
|
</OpenAPITabsContext.Provider>);
|
|
@@ -55,13 +92,12 @@ export function OpenAPITabsList() {
|
|
|
55
92
|
* It renders the content of the selected tab.
|
|
56
93
|
*/
|
|
57
94
|
export function OpenAPITabsPanels() {
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
if (!tab) {
|
|
95
|
+
var selectedTab = useOpenAPITabsContext().selectedTab;
|
|
96
|
+
if (!selectedTab) {
|
|
61
97
|
return null;
|
|
62
98
|
}
|
|
63
|
-
return (<TabPanel key={"TabPanel-".concat(
|
|
64
|
-
{
|
|
65
|
-
{
|
|
99
|
+
return (<TabPanel key={"TabPanel-".concat(selectedTab.key)} id={selectedTab.key.toString()} className="openapi-tabs-panel">
|
|
100
|
+
{selectedTab.body}
|
|
101
|
+
{selectedTab.description ? (<Markdown source={selectedTab.description} className="openapi-tabs-footer"/>) : null}
|
|
66
102
|
</TabPanel>);
|
|
67
103
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { noReference } from './utils';
|
|
2
1
|
import { getExampleFromSchema } from '@scalar/oas-utils/spec-getters';
|
|
3
2
|
/**
|
|
4
3
|
* Generate a JSON example from a schema
|
|
@@ -36,12 +35,12 @@ export function generateMediaTypeExample(mediaType, options) {
|
|
|
36
35
|
if (key) {
|
|
37
36
|
var example = mediaType.examples[key];
|
|
38
37
|
if (example) {
|
|
39
|
-
return
|
|
38
|
+
return example.value;
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
if (mediaType.schema) {
|
|
44
|
-
return generateSchemaExample(
|
|
43
|
+
return generateSchemaExample(mediaType.schema, options);
|
|
45
44
|
}
|
|
46
45
|
return undefined;
|
|
47
46
|
}
|
|
@@ -56,7 +56,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
56
56
|
};
|
|
57
57
|
import { toJSON, fromJSON } from 'flatted';
|
|
58
58
|
import { dereference, } from '@gitbook/openapi-parser';
|
|
59
|
-
import {
|
|
59
|
+
import { checkIsReference } from './utils';
|
|
60
60
|
export { toJSON, fromJSON };
|
|
61
61
|
/**
|
|
62
62
|
* Resolve an OpenAPI operation in a file and compile it to a more usable format.
|
|
@@ -88,8 +88,8 @@ export function resolveOpenAPIOperation(filesystem, operationDescriptor) {
|
|
|
88
88
|
securityKey = Object.keys(entry)[0];
|
|
89
89
|
if (securityKey) {
|
|
90
90
|
securityScheme = (_f = (_e = schema.components) === null || _e === void 0 ? void 0 : _e.securitySchemes) === null || _f === void 0 ? void 0 : _f[securityKey];
|
|
91
|
-
if (securityScheme) {
|
|
92
|
-
securities.push([securityKey,
|
|
91
|
+
if (securityScheme && !checkIsReference(securityScheme)) {
|
|
92
|
+
securities.push([securityKey, securityScheme]);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -155,7 +155,7 @@ function getPathObject(schema, path) {
|
|
|
155
155
|
function getPathObjectParameter(schema, path) {
|
|
156
156
|
var pathObject = getPathObject(schema, path);
|
|
157
157
|
if (pathObject === null || pathObject === void 0 ? void 0 : pathObject.parameters) {
|
|
158
|
-
return pathObject.parameters
|
|
158
|
+
return pathObject.parameters;
|
|
159
159
|
}
|
|
160
160
|
return null;
|
|
161
161
|
}
|