@gitbook/react-openapi 1.1.8 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/InteractiveSection.jsx +7 -6
- package/dist/OpenAPICodeSample.d.ts +2 -2
- package/dist/OpenAPICodeSample.jsx +3 -8
- package/dist/OpenAPICodeSampleInteractive.jsx +31 -19
- package/dist/OpenAPICodeSampleSelector.d.ts +15 -0
- package/dist/OpenAPICodeSampleSelector.jsx +49 -0
- package/dist/OpenAPIExample.d.ts +34 -0
- package/dist/OpenAPIExample.jsx +103 -0
- package/dist/OpenAPIOperation.d.ts +2 -2
- package/dist/OpenAPIOperation.jsx +3 -7
- package/dist/OpenAPIPath.d.ts +10 -2
- package/dist/OpenAPIPath.jsx +9 -4
- package/dist/OpenAPIResponse.jsx +3 -3
- package/dist/OpenAPIResponseExample.d.ts +2 -2
- package/dist/OpenAPIResponseExample.jsx +4 -90
- package/dist/OpenAPIResponses.jsx +23 -10
- package/dist/OpenAPISchema.jsx +26 -15
- package/dist/OpenAPISchemaName.jsx +2 -7
- package/dist/OpenAPISecurities.jsx +6 -6
- package/dist/OpenAPISelect.d.ts +15 -0
- package/dist/OpenAPISelect.jsx +32 -0
- package/dist/OpenAPITabs.jsx +9 -9
- package/dist/context.d.ts +54 -0
- package/dist/context.js +11 -0
- package/dist/generateSchemaExample.d.ts +1 -1
- package/dist/generateSchemaExample.js +28 -26
- package/dist/getOrCreateStoreByKey.d.ts +10 -0
- package/dist/getOrCreateStoreByKey.js +20 -0
- package/dist/index.d.ts +1 -1
- package/dist/resolveOpenAPIOperation.js +10 -5
- package/dist/schemas/OpenAPISchemas.d.ts +5 -6
- package/dist/schemas/OpenAPISchemas.jsx +45 -38
- package/dist/schemas/resolveOpenAPISchemas.d.ts +4 -3
- package/dist/schemas/resolveOpenAPISchemas.js +0 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types.d.ts +32 -26
- package/package.json +1 -1
- package/src/InteractiveSection.tsx +10 -8
- package/src/OpenAPICodeSample.tsx +8 -15
- package/src/OpenAPICodeSampleInteractive.tsx +43 -26
- package/src/OpenAPICodeSampleSelector.tsx +87 -0
- package/src/OpenAPIExample.tsx +129 -0
- package/src/OpenAPIOperation.tsx +6 -10
- package/src/OpenAPIPath.tsx +23 -6
- package/src/OpenAPIResponse.tsx +9 -7
- package/src/OpenAPIResponseExample.tsx +13 -113
- package/src/OpenAPIResponses.tsx +37 -12
- package/src/OpenAPISchema.tsx +40 -25
- package/src/OpenAPISchemaName.tsx +2 -8
- package/src/OpenAPISecurities.tsx +22 -9
- package/src/OpenAPISelect.tsx +70 -0
- package/src/OpenAPITabs.tsx +9 -9
- package/src/context.ts +64 -0
- package/src/generateSchemaExample.test.ts +1020 -0
- package/src/generateSchemaExample.ts +103 -36
- package/src/getOrCreateStoreByKey.ts +35 -0
- package/src/index.ts +1 -1
- package/src/resolveOpenAPIOperation.ts +14 -3
- package/src/schemas/OpenAPISchemas.tsx +75 -70
- package/src/schemas/resolveOpenAPISchemas.ts +4 -5
- package/src/types.ts +36 -29
- package/dist/useSyncedTabsGlobalState.d.ts +0 -10
- package/dist/useSyncedTabsGlobalState.js +0 -20
- package/src/useSyncedTabsGlobalState.ts +0 -35
|
@@ -9,9 +9,29 @@ export function OpenAPIResponses(props) {
|
|
|
9
9
|
var responses = props.responses, context = props.context;
|
|
10
10
|
return (<StaticSection header="Responses" className="openapi-responses">
|
|
11
11
|
<OpenAPIDisclosureGroup allowsMultipleExpanded icon={context.icons.chevronRight} groups={Object.entries(responses).map(function (_a) {
|
|
12
|
-
var _b;
|
|
13
12
|
var statusCode = _a[0], response = _a[1];
|
|
14
|
-
var
|
|
13
|
+
var tabs = (function () {
|
|
14
|
+
var _a;
|
|
15
|
+
// If there is no content, but there are headers, we need to show the headers
|
|
16
|
+
if ((!response.content || !Object.keys(response.content).length) &&
|
|
17
|
+
response.headers &&
|
|
18
|
+
Object.keys(response.headers).length) {
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
id: 'default',
|
|
22
|
+
body: (<OpenAPIResponse response={response} mediaType={{}} context={context}/>),
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
return Object.entries((_a = response.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
27
|
+
var contentType = _a[0], mediaType = _a[1];
|
|
28
|
+
return ({
|
|
29
|
+
id: contentType,
|
|
30
|
+
label: contentType,
|
|
31
|
+
body: (<OpenAPIResponse response={response} mediaType={mediaType} context={context}/>),
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
})();
|
|
15
35
|
var description = response.description;
|
|
16
36
|
return {
|
|
17
37
|
id: statusCode,
|
|
@@ -21,14 +41,7 @@ export function OpenAPIResponses(props) {
|
|
|
21
41
|
</span>
|
|
22
42
|
{description ? (<Markdown source={description} className="openapi-response-description"/>) : null}
|
|
23
43
|
</div>),
|
|
24
|
-
tabs:
|
|
25
|
-
var contentType = _a[0], mediaType = _a[1];
|
|
26
|
-
return ({
|
|
27
|
-
id: contentType,
|
|
28
|
-
label: contentType,
|
|
29
|
-
body: (<OpenAPIResponse response={response} mediaType={mediaType} context={context}/>),
|
|
30
|
-
});
|
|
31
|
-
}),
|
|
44
|
+
tabs: tabs,
|
|
32
45
|
};
|
|
33
46
|
})}/>
|
|
34
47
|
</StaticSection>);
|
package/dist/OpenAPISchema.jsx
CHANGED
|
@@ -6,6 +6,7 @@ import { OpenAPICopyButton } from './OpenAPICopyButton';
|
|
|
6
6
|
import { OpenAPIDisclosure } from './OpenAPIDisclosure';
|
|
7
7
|
import { OpenAPISchemaName } from './OpenAPISchemaName';
|
|
8
8
|
import { retrocycle } from './decycle';
|
|
9
|
+
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
9
10
|
import { checkIsReference, resolveDescription, resolveFirstExample } from './utils';
|
|
10
11
|
/**
|
|
11
12
|
* Render a property of an OpenAPI schema.
|
|
@@ -60,10 +61,14 @@ function OpenAPIRootSchema(props) {
|
|
|
60
61
|
var schema = props.schema, context = props.context, _a = props.circularRefs, parentCircularRefs = _a === void 0 ? new Map() : _a;
|
|
61
62
|
var id = useId();
|
|
62
63
|
var properties = getSchemaProperties(schema);
|
|
64
|
+
var description = resolveDescription(schema);
|
|
63
65
|
if (properties === null || properties === void 0 ? void 0 : properties.length) {
|
|
64
66
|
var circularRefs = new Map(parentCircularRefs);
|
|
65
67
|
circularRefs.set(schema, id);
|
|
66
|
-
return (
|
|
68
|
+
return (<>
|
|
69
|
+
{description ? (<Markdown source={description} className="openapi-schema-root-description"/>) : null}
|
|
70
|
+
<OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>
|
|
71
|
+
</>);
|
|
67
72
|
}
|
|
68
73
|
return (<OpenAPISchemaProperty className="openapi-schema-root" property={{ schema: schema }} context={context} circularRefs={parentCircularRefs}/>);
|
|
69
74
|
}
|
|
@@ -132,16 +137,14 @@ function OpenAPISchemaEnum(props) {
|
|
|
132
137
|
if (!(enumValues === null || enumValues === void 0 ? void 0 : enumValues.length)) {
|
|
133
138
|
return null;
|
|
134
139
|
}
|
|
135
|
-
return (<
|
|
136
|
-
|
|
137
|
-
<
|
|
138
|
-
|
|
139
|
-
<
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
</div>
|
|
144
|
-
</div>);
|
|
140
|
+
return (<span className="openapi-schema-enum">
|
|
141
|
+
Available options:{' '}
|
|
142
|
+
{enumValues.map(function (item, index) { return (<span key={index} className="openapi-schema-enum-value">
|
|
143
|
+
<OpenAPICopyButton value={item.value} label={item.description} withTooltip={!!item.description}>
|
|
144
|
+
<code>{"".concat(item.value)}</code>
|
|
145
|
+
</OpenAPICopyButton>
|
|
146
|
+
</span>); })}
|
|
147
|
+
</span>);
|
|
145
148
|
}
|
|
146
149
|
/**
|
|
147
150
|
* Render the top row of a schema. e.g: name, type, and required status.
|
|
@@ -159,12 +162,20 @@ function OpenAPISchemaPresentation(props) {
|
|
|
159
162
|
</span>
|
|
160
163
|
</div>) : null}
|
|
161
164
|
{description ? (<Markdown source={description} className="openapi-schema-description"/>) : null}
|
|
162
|
-
{
|
|
165
|
+
{schema.default !== undefined ? (<span className="openapi-schema-default">
|
|
166
|
+
Default:{' '}
|
|
167
|
+
<code>
|
|
168
|
+
{typeof schema.default === 'string' && schema.default
|
|
169
|
+
? schema.default
|
|
170
|
+
: stringifyOpenAPI(schema.default)}
|
|
171
|
+
</code>
|
|
172
|
+
</span>) : null}
|
|
173
|
+
{typeof example === 'string' ? (<span className="openapi-schema-example">
|
|
163
174
|
Example: <code>{example}</code>
|
|
164
|
-
</
|
|
165
|
-
{schema.pattern ? (<
|
|
175
|
+
</span>) : null}
|
|
176
|
+
{schema.pattern ? (<span className="openapi-schema-pattern">
|
|
166
177
|
Pattern: <code>{schema.pattern}</code>
|
|
167
|
-
</
|
|
178
|
+
</span>) : null}
|
|
168
179
|
<OpenAPISchemaEnum schema={schema}/>
|
|
169
180
|
</div>);
|
|
170
181
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
2
1
|
/**
|
|
3
2
|
* Display the schema name row.
|
|
4
3
|
* It includes the property name, type, required and deprecated status.
|
|
@@ -6,7 +5,7 @@ import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
|
6
5
|
export function OpenAPISchemaName(props) {
|
|
7
6
|
var schema = props.schema, type = props.type, propertyName = props.propertyName, required = props.required;
|
|
8
7
|
var additionalItems = schema && getAdditionalItems(schema);
|
|
9
|
-
return (<
|
|
8
|
+
return (<span className="openapi-schema-name">
|
|
10
9
|
{propertyName ? (<span data-deprecated={schema === null || schema === void 0 ? void 0 : schema.deprecated} className="openapi-schema-propertyname">
|
|
11
10
|
{propertyName}
|
|
12
11
|
</span>) : null}
|
|
@@ -18,7 +17,7 @@ export function OpenAPISchemaName(props) {
|
|
|
18
17
|
{(schema === null || schema === void 0 ? void 0 : schema.writeOnly) ? (<span className="openapi-schema-writeonly">write-only</span>) : null}
|
|
19
18
|
{required ? (<span className="openapi-schema-required">required</span>) : (<span className="openapi-schema-optional">optional</span>)}
|
|
20
19
|
{(schema === null || schema === void 0 ? void 0 : schema.deprecated) ? <span className="openapi-deprecated">Deprecated</span> : null}
|
|
21
|
-
</
|
|
20
|
+
</span>);
|
|
22
21
|
}
|
|
23
22
|
function getAdditionalItems(schema) {
|
|
24
23
|
var additionalItems = '';
|
|
@@ -28,10 +27,6 @@ function getAdditionalItems(schema) {
|
|
|
28
27
|
if (schema.maximum || schema.maxLength || schema.maxItems) {
|
|
29
28
|
additionalItems += " \u00B7 max: ".concat(schema.maximum || schema.maxLength || schema.maxItems);
|
|
30
29
|
}
|
|
31
|
-
// If the schema has a default value, we display it
|
|
32
|
-
if (typeof schema.default !== 'undefined') {
|
|
33
|
-
additionalItems += " \u00B7 default: ".concat(stringifyOpenAPI(schema.default));
|
|
34
|
-
}
|
|
35
30
|
if (schema.nullable) {
|
|
36
31
|
additionalItems = ' | nullable';
|
|
37
32
|
}
|
|
@@ -30,24 +30,24 @@ function getLabelForType(security) {
|
|
|
30
30
|
var _a;
|
|
31
31
|
switch (security.type) {
|
|
32
32
|
case 'apiKey':
|
|
33
|
-
return (<OpenAPISchemaName propertyName={(_a = security.name) !== null && _a !== void 0 ? _a : 'apiKey'} type="string" required/>);
|
|
33
|
+
return (<OpenAPISchemaName propertyName={(_a = security.name) !== null && _a !== void 0 ? _a : 'apiKey'} type="string" required={security.required}/>);
|
|
34
34
|
case 'http':
|
|
35
35
|
if (security.scheme === 'basic') {
|
|
36
|
-
return <OpenAPISchemaName propertyName="Authorization" type="string" required
|
|
36
|
+
return (<OpenAPISchemaName propertyName="Authorization" type="string" required={security.required}/>);
|
|
37
37
|
}
|
|
38
38
|
if (security.scheme === 'bearer') {
|
|
39
39
|
var description = resolveDescription(security);
|
|
40
40
|
return (<>
|
|
41
|
-
<OpenAPISchemaName propertyName="Authorization" type="string" required/>
|
|
41
|
+
<OpenAPISchemaName propertyName="Authorization" type="string" required={security.required}/>
|
|
42
42
|
{/** Show a default description if none is provided */}
|
|
43
43
|
{!description ? (<Markdown source={"Bearer authentication header of the form Bearer ".concat('<token>', ".")} className="openapi-securities-description"/>) : null}
|
|
44
44
|
</>);
|
|
45
45
|
}
|
|
46
|
-
return <OpenAPISchemaName propertyName="HTTP" required/>;
|
|
46
|
+
return <OpenAPISchemaName propertyName="HTTP" required={security.required}/>;
|
|
47
47
|
case 'oauth2':
|
|
48
|
-
return <OpenAPISchemaName propertyName="OAuth2" required/>;
|
|
48
|
+
return <OpenAPISchemaName propertyName="OAuth2" required={security.required}/>;
|
|
49
49
|
case 'openIdConnect':
|
|
50
|
-
return <OpenAPISchemaName propertyName="OpenID Connect" required/>;
|
|
50
|
+
return <OpenAPISchemaName propertyName="OpenID Connect" required={security.required}/>;
|
|
51
51
|
default:
|
|
52
52
|
// @ts-ignore
|
|
53
53
|
return security.type;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Key, type ListBoxItemProps, type PopoverProps, type SelectProps } from 'react-aria-components';
|
|
2
|
+
export type OpenAPISelectItem = {
|
|
3
|
+
key: Key;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
interface OpenAPISelectProps<T extends OpenAPISelectItem> extends Omit<SelectProps<T>, 'children'> {
|
|
7
|
+
items: T[];
|
|
8
|
+
children: React.ReactNode | ((item: T) => React.ReactNode);
|
|
9
|
+
selectedKey?: Key;
|
|
10
|
+
onChange?: (key: string | number) => void;
|
|
11
|
+
placement?: PopoverProps['placement'];
|
|
12
|
+
}
|
|
13
|
+
export declare function OpenAPISelect<T extends OpenAPISelectItem>(props: OpenAPISelectProps<T>): import("react").JSX.Element;
|
|
14
|
+
export declare function OpenAPISelectItem(props: ListBoxItemProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { Button, ListBox, ListBoxItem, Popover, Select, SelectValue, } from 'react-aria-components';
|
|
4
|
+
export function OpenAPISelect(props) {
|
|
5
|
+
var items = props.items, children = props.children, className = props.className, placement = props.placement;
|
|
6
|
+
return (<Select {...props} className={clsx('openapi-select', className)}>
|
|
7
|
+
<Button>
|
|
8
|
+
<SelectValue />
|
|
9
|
+
<span aria-hidden="true">
|
|
10
|
+
<svg className="gb-icon" style={{
|
|
11
|
+
maskImage: "url('https://ka-p.fontawesome.com/releases/v6.6.0/svgs/regular/chevron-down.svg?v=2&token=a463935e93')",
|
|
12
|
+
maskRepeat: 'no-repeat',
|
|
13
|
+
maskPosition: 'center center',
|
|
14
|
+
}}/>
|
|
15
|
+
</span>
|
|
16
|
+
</Button>
|
|
17
|
+
<Popover placement={placement} className="openapi-select-popover">
|
|
18
|
+
<ListBox className="openapi-select-listbox" items={items}>
|
|
19
|
+
{children}
|
|
20
|
+
</ListBox>
|
|
21
|
+
</Popover>
|
|
22
|
+
</Select>);
|
|
23
|
+
}
|
|
24
|
+
export function OpenAPISelectItem(props) {
|
|
25
|
+
return (<ListBoxItem {...props} className={function (_a) {
|
|
26
|
+
var isFocused = _a.isFocused, isSelected = _a.isSelected;
|
|
27
|
+
return clsx('openapi-select-item', {
|
|
28
|
+
'openapi-select-item-focused': isFocused,
|
|
29
|
+
'openapi-select-item-selected': isSelected,
|
|
30
|
+
});
|
|
31
|
+
}}/>);
|
|
32
|
+
}
|
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,54 @@
|
|
|
1
|
+
export interface OpenAPIClientContext {
|
|
2
|
+
/**
|
|
3
|
+
* Icons used in the block.
|
|
4
|
+
*/
|
|
5
|
+
icons: {
|
|
6
|
+
chevronDown: React.ReactNode;
|
|
7
|
+
chevronRight: React.ReactNode;
|
|
8
|
+
plus: React.ReactNode;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Force all sections to be opened by default.
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
defaultInteractiveOpened?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The key of the block
|
|
17
|
+
*/
|
|
18
|
+
blockKey?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional id attached to the heading and used as an anchor.
|
|
21
|
+
*/
|
|
22
|
+
id?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface OpenAPIContext extends OpenAPIClientContext {
|
|
25
|
+
/**
|
|
26
|
+
* Render a code block.
|
|
27
|
+
*/
|
|
28
|
+
renderCodeBlock: (props: {
|
|
29
|
+
code: string;
|
|
30
|
+
syntax: string;
|
|
31
|
+
}) => React.ReactNode;
|
|
32
|
+
/**
|
|
33
|
+
* Render the heading of the operation.
|
|
34
|
+
*/
|
|
35
|
+
renderHeading: (props: {
|
|
36
|
+
deprecated: boolean;
|
|
37
|
+
title: string;
|
|
38
|
+
stability?: string;
|
|
39
|
+
}) => React.ReactNode;
|
|
40
|
+
/**
|
|
41
|
+
* Render the document of the operation.
|
|
42
|
+
*/
|
|
43
|
+
renderDocument: (props: {
|
|
44
|
+
document: object;
|
|
45
|
+
}) => React.ReactNode;
|
|
46
|
+
/**
|
|
47
|
+
* Specification URL.
|
|
48
|
+
*/
|
|
49
|
+
specUrl: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the client context from the OpenAPI context.
|
|
53
|
+
*/
|
|
54
|
+
export declare function getOpenAPIClientContext(context: OpenAPIContext): OpenAPIClientContext;
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the client context from the OpenAPI context.
|
|
3
|
+
*/
|
|
4
|
+
export function getOpenAPIClientContext(context) {
|
|
5
|
+
return {
|
|
6
|
+
icons: context.icons,
|
|
7
|
+
defaultInteractiveOpened: context.defaultInteractiveOpened,
|
|
8
|
+
blockKey: context.blockKey,
|
|
9
|
+
id: context.id,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -41,5 +41,5 @@ declare const getExampleFromSchema: (schema: Record<string, any>, options?: {
|
|
|
41
41
|
* @default false
|
|
42
42
|
*/
|
|
43
43
|
omitEmptyAndOptionalProperties?: boolean;
|
|
44
|
-
}, level?: number, parentSchema?: Record<string, any>, name?: string) => any;
|
|
44
|
+
}, level?: number, parentSchema?: Record<string, any>, name?: string, resultCache?: WeakMap<Record<string, any>, any>) => any;
|
|
45
45
|
export {};
|
|
@@ -24,8 +24,7 @@ import { checkIsReference } from './utils';
|
|
|
24
24
|
* Generate a JSON example from a schema
|
|
25
25
|
*/
|
|
26
26
|
export function generateSchemaExample(schema, options) {
|
|
27
|
-
return getExampleFromSchema(schema, __assign({ emptyString: 'text' }, options)
|
|
28
|
-
);
|
|
27
|
+
return getExampleFromSchema(schema, __assign({ emptyString: 'text' }, options));
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
31
30
|
* Generate an example for a media type.
|
|
@@ -96,25 +95,24 @@ function guessFromFormat(schema, fallback) {
|
|
|
96
95
|
if (fallback === void 0) { fallback = ''; }
|
|
97
96
|
return (_a = genericExampleValues[schema.format]) !== null && _a !== void 0 ? _a : fallback;
|
|
98
97
|
}
|
|
99
|
-
/** Map of all the results */
|
|
100
|
-
var resultCache = new WeakMap();
|
|
101
|
-
/** Store result in the cache, and return the result */
|
|
102
|
-
function cache(schema, result) {
|
|
103
|
-
// Avoid unnecessary WeakMap operations for primitive values
|
|
104
|
-
if (typeof result !== 'object' || result === null) {
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
resultCache.set(schema, result);
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
98
|
/**
|
|
111
99
|
* This function takes an OpenAPI schema and generates an example from it
|
|
112
100
|
* Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts
|
|
113
101
|
*/
|
|
114
|
-
var getExampleFromSchema = function (schema, options, level, parentSchema, name) {
|
|
102
|
+
var getExampleFromSchema = function (schema, options, level, parentSchema, name, resultCache) {
|
|
115
103
|
var _a, _b, _c, _d;
|
|
116
104
|
var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
117
105
|
if (level === void 0) { level = 0; }
|
|
106
|
+
if (resultCache === void 0) { resultCache = new WeakMap(); }
|
|
107
|
+
// Store result in the cache, and return the result
|
|
108
|
+
function cache(schema, result) {
|
|
109
|
+
// Avoid unnecessary WeakMap operations for primitive values
|
|
110
|
+
if (typeof result !== 'object' || result === null) {
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
resultCache.set(schema, result);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
118
116
|
// Check if the result is already cached
|
|
119
117
|
if (resultCache.has(schema)) {
|
|
120
118
|
return resultCache.get(schema);
|
|
@@ -132,6 +130,10 @@ var getExampleFromSchema = function (schema, options, level, parentSchema, name)
|
|
|
132
130
|
// Sometimes, we just want the structure and no values.
|
|
133
131
|
// But if `emptyString` is set, we do want to see some values.
|
|
134
132
|
var makeUpRandomData = !!(options === null || options === void 0 ? void 0 : options.emptyString);
|
|
133
|
+
// If the property is deprecated we don't show it in examples.
|
|
134
|
+
if (schema.deprecated) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
135
137
|
// Check if the property is read-only/write-only
|
|
136
138
|
if (((options === null || options === void 0 ? void 0 : options.mode) === 'write' && schema.readOnly) ||
|
|
137
139
|
((options === null || options === void 0 ? void 0 : options.mode) === 'read' && schema.writeOnly)) {
|
|
@@ -184,7 +186,7 @@ var getExampleFromSchema = function (schema, options, level, parentSchema, name)
|
|
|
184
186
|
if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
|
|
185
187
|
var property = schema.properties[propertyName];
|
|
186
188
|
var propertyXmlTagName = (options === null || options === void 0 ? void 0 : options.xml) ? (_o = property.xml) === null || _o === void 0 ? void 0 : _o.name : undefined;
|
|
187
|
-
response[propertyXmlTagName !== null && propertyXmlTagName !== void 0 ? propertyXmlTagName : propertyName] = getExampleFromSchema(property, options, level + 1, schema, propertyName);
|
|
189
|
+
response[propertyXmlTagName !== null && propertyXmlTagName !== void 0 ? propertyXmlTagName : propertyName] = getExampleFromSchema(property, options, level + 1, schema, propertyName, resultCache);
|
|
188
190
|
if (typeof response[propertyXmlTagName !== null && propertyXmlTagName !== void 0 ? propertyXmlTagName : propertyName] === 'undefined') {
|
|
189
191
|
delete response[propertyXmlTagName !== null && propertyXmlTagName !== void 0 ? propertyXmlTagName : propertyName];
|
|
190
192
|
}
|
|
@@ -198,7 +200,7 @@ var getExampleFromSchema = function (schema, options, level, parentSchema, name)
|
|
|
198
200
|
var property = schema.patternProperties[pattern];
|
|
199
201
|
// Use the regex pattern as an example key
|
|
200
202
|
var exampleKey = pattern;
|
|
201
|
-
response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey);
|
|
203
|
+
response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey, resultCache);
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
206
|
}
|
|
@@ -214,19 +216,19 @@ var getExampleFromSchema = function (schema, options, level, parentSchema, name)
|
|
|
214
216
|
response.ANY_ADDITIONAL_PROPERTY = 'anything';
|
|
215
217
|
}
|
|
216
218
|
else if (schema.additionalProperties !== false) {
|
|
217
|
-
response.ANY_ADDITIONAL_PROPERTY = getExampleFromSchema(schema.additionalProperties, options, level + 1);
|
|
219
|
+
response.ANY_ADDITIONAL_PROPERTY = getExampleFromSchema(schema.additionalProperties, options, level + 1, undefined, undefined, resultCache);
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
222
|
if (schema.anyOf !== undefined) {
|
|
221
|
-
Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1));
|
|
223
|
+
Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1, undefined, undefined, resultCache));
|
|
222
224
|
}
|
|
223
225
|
else if (schema.oneOf !== undefined) {
|
|
224
|
-
Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1));
|
|
226
|
+
Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1, undefined, undefined, resultCache));
|
|
225
227
|
}
|
|
226
228
|
else if (schema.allOf !== undefined) {
|
|
227
229
|
Object.assign.apply(Object, __spreadArray([response], schema.allOf
|
|
228
230
|
.map(function (item) {
|
|
229
|
-
return getExampleFromSchema(item, options, level + 1, schema);
|
|
231
|
+
return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
|
|
230
232
|
})
|
|
231
233
|
.filter(function (item) { return item !== undefined; }), false));
|
|
232
234
|
}
|
|
@@ -245,13 +247,13 @@ var getExampleFromSchema = function (schema, options, level, parentSchema, name)
|
|
|
245
247
|
if (schema.items.allOf) {
|
|
246
248
|
// If the first item is an object type, merge all schemas
|
|
247
249
|
if (schema.items.allOf[0].type === 'object') {
|
|
248
|
-
var mergedExample = getExampleFromSchema({ type: 'object', allOf: schema.items.allOf }, options, level + 1, schema);
|
|
250
|
+
var mergedExample = getExampleFromSchema({ type: 'object', allOf: schema.items.allOf }, options, level + 1, schema, undefined, resultCache);
|
|
249
251
|
return cache(schema, wrapItems ? [(_b = {}, _b[itemsXmlTagName_1] = mergedExample, _b)] : [mergedExample]);
|
|
250
252
|
}
|
|
251
253
|
// For non-objects (like strings), collect all examples
|
|
252
254
|
var examples = schema.items.allOf
|
|
253
255
|
.map(function (item) {
|
|
254
|
-
return getExampleFromSchema(item, options, level + 1, schema);
|
|
256
|
+
return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
|
|
255
257
|
})
|
|
256
258
|
.filter(function (item) { return item !== undefined; });
|
|
257
259
|
return cache(schema, wrapItems
|
|
@@ -271,14 +273,14 @@ var getExampleFromSchema = function (schema, options, level, parentSchema, name)
|
|
|
271
273
|
var schemas = schema.items[rule].slice(0, 1);
|
|
272
274
|
var exampleFromRule = schemas
|
|
273
275
|
.map(function (item) {
|
|
274
|
-
return getExampleFromSchema(item, options, level + 1, schema);
|
|
276
|
+
return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
|
|
275
277
|
})
|
|
276
278
|
.filter(function (item) { return item !== undefined; });
|
|
277
279
|
return cache(schema, wrapItems ? [(_c = {}, _c[itemsXmlTagName_1] = exampleFromRule, _c)] : exampleFromRule);
|
|
278
280
|
}
|
|
279
281
|
}
|
|
280
282
|
if ((_s = schema.items) === null || _s === void 0 ? void 0 : _s.type) {
|
|
281
|
-
var exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1);
|
|
283
|
+
var exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1, undefined, undefined, resultCache);
|
|
282
284
|
return wrapItems ? [(_d = {}, _d[itemsXmlTagName_1] = exampleFromSchema, _d)] : [exampleFromSchema];
|
|
283
285
|
}
|
|
284
286
|
return [];
|
|
@@ -299,7 +301,7 @@ var getExampleFromSchema = function (schema, options, level, parentSchema, name)
|
|
|
299
301
|
// Get the first item from the `oneOf` | `anyOf` array
|
|
300
302
|
var firstOneOfItem = discriminateSchema[0];
|
|
301
303
|
// Return an example for the first item
|
|
302
|
-
return getExampleFromSchema(firstOneOfItem, options, level + 1);
|
|
304
|
+
return getExampleFromSchema(firstOneOfItem, options, level + 1, undefined, undefined, resultCache);
|
|
303
305
|
}
|
|
304
306
|
// Check if schema has the `allOf` key
|
|
305
307
|
if (Array.isArray(schema.allOf)) {
|
|
@@ -307,7 +309,7 @@ var getExampleFromSchema = function (schema, options, level, parentSchema, name)
|
|
|
307
309
|
// Loop through all `allOf` schemas
|
|
308
310
|
schema.allOf.forEach(function (allOfItem) {
|
|
309
311
|
// Return an example from the schema
|
|
310
|
-
var newExample = getExampleFromSchema(allOfItem, options, level + 1);
|
|
312
|
+
var newExample = getExampleFromSchema(allOfItem, options, level + 1, undefined, undefined, resultCache);
|
|
311
313
|
// Merge or overwrite the example
|
|
312
314
|
example_1 =
|
|
313
315
|
typeof newExample === 'object' && typeof example_1 === 'object'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Key = string | number;
|
|
2
|
+
type State = {
|
|
3
|
+
key: Key | null;
|
|
4
|
+
};
|
|
5
|
+
type Actions = {
|
|
6
|
+
setKey: (key: Key | null) => void;
|
|
7
|
+
};
|
|
8
|
+
type Store = State & Actions;
|
|
9
|
+
export declare const getOrCreateStoreByKey: (storeKey: string, initialKey?: Key) => import("zustand").StoreApi<Store>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createStore } from 'zustand';
|
|
3
|
+
var createStateStore = function (initial) {
|
|
4
|
+
return createStore()(function (set) { return ({
|
|
5
|
+
key: initial !== null && initial !== void 0 ? initial : null,
|
|
6
|
+
setKey: function (key) {
|
|
7
|
+
set(function () { return ({ key: key }); });
|
|
8
|
+
},
|
|
9
|
+
}); });
|
|
10
|
+
};
|
|
11
|
+
var defaultStores = new Map();
|
|
12
|
+
var createStateStoreFactory = function (stores) {
|
|
13
|
+
return function (storeKey, initialKey) {
|
|
14
|
+
if (!stores.has(storeKey)) {
|
|
15
|
+
stores.set(storeKey, createStateStore(initialKey));
|
|
16
|
+
}
|
|
17
|
+
return stores.get(storeKey);
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export var getOrCreateStoreByKey = createStateStoreFactory(defaultStores);
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export * from './schemas';
|
|
|
2
2
|
export * from './OpenAPIOperation';
|
|
3
3
|
export * from './OpenAPIOperationContext';
|
|
4
4
|
export * from './resolveOpenAPIOperation';
|
|
5
|
-
export type {
|
|
5
|
+
export type { OpenAPIOperationData, OpenAPIContext } from './types';
|
|
@@ -63,7 +63,7 @@ export { fromJSON, toJSON };
|
|
|
63
63
|
*/
|
|
64
64
|
export function resolveOpenAPIOperation(filesystem, operationDescriptor) {
|
|
65
65
|
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
var path, method, schema, operation, commonParameters, servers, security, securities, _i,
|
|
66
|
+
var path, method, schema, operation, commonParameters, servers, security, isOptionalSecurity, flatSecurities, securities, _i, flatSecurities_1, entry, securityKey, securityScheme;
|
|
67
67
|
var _a, _b, _c, _d, _e, _f;
|
|
68
68
|
return __generator(this, function (_g) {
|
|
69
69
|
switch (_g.label) {
|
|
@@ -81,15 +81,20 @@ export function resolveOpenAPIOperation(filesystem, operationDescriptor) {
|
|
|
81
81
|
operation = __assign(__assign({}, operation), { parameters: __spreadArray(__spreadArray([], commonParameters, true), ((_a = operation.parameters) !== null && _a !== void 0 ? _a : []), true) });
|
|
82
82
|
}
|
|
83
83
|
servers = 'servers' in schema ? ((_b = schema.servers) !== null && _b !== void 0 ? _b : []) : [];
|
|
84
|
-
security =
|
|
84
|
+
security = (_d = (_c = operation.security) !== null && _c !== void 0 ? _c : schema.security) !== null && _d !== void 0 ? _d : [];
|
|
85
|
+
isOptionalSecurity = security.some(function (entry) { return Object.keys(entry).length === 0; });
|
|
86
|
+
flatSecurities = flattenSecurities(security);
|
|
85
87
|
securities = [];
|
|
86
|
-
for (_i = 0,
|
|
87
|
-
entry =
|
|
88
|
+
for (_i = 0, flatSecurities_1 = flatSecurities; _i < flatSecurities_1.length; _i++) {
|
|
89
|
+
entry = flatSecurities_1[_i];
|
|
88
90
|
securityKey = Object.keys(entry)[0];
|
|
89
91
|
if (securityKey) {
|
|
90
92
|
securityScheme = (_f = (_e = schema.components) === null || _e === void 0 ? void 0 : _e.securitySchemes) === null || _f === void 0 ? void 0 : _f[securityKey];
|
|
91
93
|
if (securityScheme && !checkIsReference(securityScheme)) {
|
|
92
|
-
securities.push([
|
|
94
|
+
securities.push([
|
|
95
|
+
securityKey,
|
|
96
|
+
__assign(__assign({}, securityScheme), { required: !isOptionalSecurity }),
|
|
97
|
+
]);
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
type
|
|
1
|
+
import type { OpenAPISchema } from '@gitbook/openapi-parser';
|
|
2
|
+
import type { OpenAPIContext } from '../types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* OpenAPI Schemas component.
|
|
5
5
|
*/
|
|
6
6
|
export declare function OpenAPISchemas(props: {
|
|
7
7
|
className?: string;
|
|
8
|
-
|
|
9
|
-
context:
|
|
8
|
+
schemas: OpenAPISchema[];
|
|
9
|
+
context: OpenAPIContext;
|
|
10
10
|
/**
|
|
11
11
|
* Whether to show the schema directly if there is only one.
|
|
12
12
|
*/
|
|
13
13
|
grouped?: boolean;
|
|
14
14
|
}): import("react").JSX.Element | null;
|
|
15
|
-
export {};
|