@gitbook/react-openapi 0.7.1 → 1.0.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 +41 -0
- package/dist/InteractiveSection.d.ts +4 -6
- package/dist/InteractiveSection.jsx +96 -0
- package/dist/Markdown.d.ts +1 -2
- package/dist/Markdown.jsx +5 -0
- package/dist/OpenAPICodeSample.d.ts +2 -4
- package/dist/OpenAPICodeSample.jsx +143 -0
- package/dist/OpenAPIDisclosure.d.ts +12 -0
- package/dist/OpenAPIDisclosure.jsx +32 -0
- package/dist/OpenAPIDisclosureGroup.d.ts +19 -0
- package/dist/OpenAPIDisclosureGroup.jsx +81 -0
- package/dist/OpenAPIOperation.d.ts +2 -4
- package/dist/OpenAPIOperation.jsx +51 -0
- package/dist/OpenAPIOperationContext.d.ts +16 -0
- package/dist/OpenAPIOperationContext.jsx +26 -0
- package/dist/OpenAPIPath.d.ts +8 -0
- package/dist/OpenAPIPath.jsx +54 -0
- package/dist/OpenAPIRequestBody.d.ts +3 -4
- package/dist/OpenAPIRequestBody.jsx +19 -0
- package/dist/OpenAPIResponse.d.ts +4 -4
- package/dist/OpenAPIResponse.jsx +49 -0
- package/dist/OpenAPIResponseExample.d.ts +2 -4
- package/dist/OpenAPIResponseExample.jsx +108 -0
- package/dist/OpenAPIResponses.d.ts +3 -4
- package/dist/OpenAPIResponses.jsx +36 -0
- package/dist/OpenAPISchema.d.ts +11 -8
- package/dist/OpenAPISchema.jsx +295 -0
- package/dist/OpenAPISchemaName.d.ts +12 -0
- package/dist/OpenAPISchemaName.jsx +15 -0
- package/dist/OpenAPISecurities.d.ts +2 -4
- package/dist/OpenAPISecurities.jsx +55 -0
- package/dist/OpenAPIServerURL.d.ts +2 -3
- package/dist/OpenAPIServerURL.jsx +67 -0
- package/dist/OpenAPIServerURLVariable.d.ts +2 -3
- package/dist/OpenAPIServerURLVariable.jsx +8 -0
- package/dist/OpenAPISpec.d.ts +3 -4
- package/dist/OpenAPISpec.jsx +91 -0
- package/dist/OpenAPITabs.d.ts +25 -0
- package/dist/OpenAPITabs.jsx +67 -0
- package/dist/ScalarApiButton.d.ts +3 -3
- package/dist/ScalarApiButton.jsx +51 -0
- package/dist/code-samples.d.ts +4 -0
- package/dist/code-samples.js +103 -38
- package/dist/fetchOpenAPIOperation.d.ts +9 -54
- package/dist/fetchOpenAPIOperation.js +178 -107
- package/dist/generateSchemaExample.d.ts +2 -2
- package/dist/generateSchemaExample.js +28 -100
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/resolveOpenAPIOperation.d.ts +11 -0
- package/dist/resolveOpenAPIOperation.js +194 -0
- package/dist/stringifyOpenAPI.d.ts +4 -0
- package/dist/stringifyOpenAPI.js +6 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +11 -12
- package/dist/utils.d.ts +6 -1
- package/dist/utils.js +15 -2
- package/package.json +11 -10
- package/src/InteractiveSection.tsx +119 -78
- package/src/Markdown.tsx +2 -3
- package/src/OpenAPICodeSample.tsx +35 -21
- package/src/OpenAPIDisclosure.tsx +50 -0
- package/src/OpenAPIDisclosureGroup.tsx +136 -0
- package/src/OpenAPIOperation.tsx +36 -42
- package/src/OpenAPIOperationContext.tsx +45 -0
- package/src/OpenAPIPath.tsx +65 -0
- package/src/OpenAPIRequestBody.tsx +3 -14
- package/src/OpenAPIResponse.tsx +39 -43
- package/src/OpenAPIResponseExample.tsx +89 -31
- package/src/OpenAPIResponses.tsx +51 -15
- package/src/OpenAPISchema.test.ts +1 -1
- package/src/OpenAPISchema.tsx +124 -92
- package/src/OpenAPISchemaName.tsx +27 -0
- package/src/OpenAPISecurities.tsx +45 -24
- package/src/OpenAPIServerURL.tsx +17 -10
- package/src/OpenAPIServerURLVariable.tsx +2 -4
- package/src/OpenAPISpec.tsx +56 -53
- package/src/OpenAPITabs.tsx +113 -0
- package/src/ScalarApiButton.tsx +84 -7
- package/src/code-samples.test.ts +51 -0
- package/src/code-samples.ts +95 -31
- package/src/generateSchemaExample.ts +25 -151
- package/src/index.ts +3 -2
- package/src/resolveOpenAPIOperation.test.ts +177 -0
- package/src/resolveOpenAPIOperation.ts +163 -0
- package/src/stringifyOpenAPI.ts +6 -0
- package/src/types.ts +17 -10
- package/src/utils.ts +17 -2
- package/dist/InteractiveSection.js +0 -47
- package/dist/Markdown.js +0 -6
- package/dist/OpenAPICodeSample.js +0 -110
- package/dist/OpenAPIOperation.js +0 -38
- package/dist/OpenAPIRequestBody.js +0 -18
- package/dist/OpenAPIResponse.js +0 -32
- package/dist/OpenAPIResponseExample.js +0 -54
- package/dist/OpenAPIResponses.js +0 -18
- package/dist/OpenAPISchema.js +0 -235
- package/dist/OpenAPISchema.test.d.ts +0 -1
- package/dist/OpenAPISchema.test.js +0 -91
- package/dist/OpenAPISecurities.js +0 -42
- package/dist/OpenAPIServerURL.js +0 -51
- package/dist/OpenAPIServerURLVariable.js +0 -10
- package/dist/OpenAPISpec.js +0 -70
- package/dist/ScalarApiButton.js +0 -14
- package/dist/fetchOpenAPIOperation.test.d.ts +0 -1
- package/dist/fetchOpenAPIOperation.test.js +0 -152
- package/dist/resolveOpenAPIPath.d.ts +0 -7
- package/dist/resolveOpenAPIPath.js +0 -112
- package/dist/resolveOpenAPIPath.test.d.ts +0 -1
- package/dist/resolveOpenAPIPath.test.js +0 -39
- package/src/fetchOpenAPIOperation.test.ts +0 -185
- package/src/fetchOpenAPIOperation.ts +0 -230
- package/src/resolveOpenAPIPath.test.ts +0 -60
- package/src/resolveOpenAPIPath.ts +0 -145
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createContext, useContext, useMemo, useState } from 'react';
|
|
3
|
+
import { Tab, TabList, TabPanel, Tabs } from 'react-aria-components';
|
|
4
|
+
import { Markdown } from './Markdown';
|
|
5
|
+
var OpenAPITabsContext = createContext(null);
|
|
6
|
+
function useOpenAPITabsContext() {
|
|
7
|
+
var context = useContext(OpenAPITabsContext);
|
|
8
|
+
if (!context) {
|
|
9
|
+
throw new Error('OpenAPITabsContext is missing');
|
|
10
|
+
}
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The OpenAPI Tabs wrapper component.
|
|
15
|
+
*/
|
|
16
|
+
export function OpenAPITabs(props) {
|
|
17
|
+
var children = props.children, items = props.items;
|
|
18
|
+
var _a = useState(function () {
|
|
19
|
+
var firstItem = items[0];
|
|
20
|
+
if (!firstItem) {
|
|
21
|
+
throw new Error('OpenAPITabs: at least one tab is required');
|
|
22
|
+
}
|
|
23
|
+
return firstItem.key;
|
|
24
|
+
}), selectedKey = _a[0], setSelectedKey = _a[1];
|
|
25
|
+
var contextValue = { items: items, selectedKey: selectedKey, setSelectedKey: setSelectedKey };
|
|
26
|
+
return (<OpenAPITabsContext.Provider value={contextValue}>
|
|
27
|
+
<Tabs className="openapi-tabs" onSelectionChange={setSelectedKey} selectedKey={selectedKey}>
|
|
28
|
+
{children}
|
|
29
|
+
</Tabs>
|
|
30
|
+
</OpenAPITabsContext.Provider>);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The OpenAPI Tabs list component.
|
|
34
|
+
* This component should be used as a child of the OpenAPITabs component.
|
|
35
|
+
* It renders the list of tabs.
|
|
36
|
+
*/
|
|
37
|
+
export function OpenAPITabsList() {
|
|
38
|
+
var items = useOpenAPITabsContext().items;
|
|
39
|
+
return (<TabList className="openapi-tabs-list">
|
|
40
|
+
{items.map(function (tab) { return (<Tab style={function (_a) {
|
|
41
|
+
var isFocusVisible = _a.isFocusVisible;
|
|
42
|
+
return ({
|
|
43
|
+
outline: isFocusVisible
|
|
44
|
+
? '2px solid rgb(var(--primary-color-500)/0.4)'
|
|
45
|
+
: 'none',
|
|
46
|
+
});
|
|
47
|
+
}} className="openapi-tabs-tab" key={"Tab-".concat(tab.key)} id={tab.key}>
|
|
48
|
+
{tab.label}
|
|
49
|
+
</Tab>); })}
|
|
50
|
+
</TabList>);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The OpenAPI Tabs panels component.
|
|
54
|
+
* This component should be used as a child of the OpenAPITabs component.
|
|
55
|
+
* It renders the content of the selected tab.
|
|
56
|
+
*/
|
|
57
|
+
export function OpenAPITabsPanels() {
|
|
58
|
+
var _a = useOpenAPITabsContext(), selectedKey = _a.selectedKey, items = _a.items;
|
|
59
|
+
var tab = useMemo(function () { return items.find(function (tab) { return tab.key === selectedKey; }); }, [items, selectedKey]);
|
|
60
|
+
if (!tab) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return (<TabPanel key={"TabPanel-".concat(tab.key)} id={tab.key.toString()} className="openapi-tabs-panel">
|
|
64
|
+
{tab.body}
|
|
65
|
+
{tab.description ? (<Markdown source={tab.description} className="openapi-tabs-footer"/>) : null}
|
|
66
|
+
</TabPanel>);
|
|
67
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
/**
|
|
3
2
|
* Button which launches the Scalar API Client
|
|
4
3
|
*/
|
|
5
|
-
export declare function ScalarApiButton({ method, path }: {
|
|
4
|
+
export declare function ScalarApiButton({ method, path, specUrl, }: {
|
|
6
5
|
method: string;
|
|
7
6
|
path: string;
|
|
8
|
-
|
|
7
|
+
specUrl: string;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { ApiClientModalProvider, useApiClientModal } from '@scalar/api-client-react';
|
|
3
|
+
import { useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { useOpenAPIOperationContext } from './OpenAPIOperationContext';
|
|
6
|
+
import { useEventCallback } from 'usehooks-ts';
|
|
7
|
+
/**
|
|
8
|
+
* Button which launches the Scalar API Client
|
|
9
|
+
*/
|
|
10
|
+
export function ScalarApiButton(_a) {
|
|
11
|
+
var method = _a.method, path = _a.path, specUrl = _a.specUrl;
|
|
12
|
+
var _b = useState(false), isOpen = _b[0], setIsOpen = _b[1];
|
|
13
|
+
var controllerRef = useRef(null);
|
|
14
|
+
return (<div className="scalar scalar-activate">
|
|
15
|
+
<button className="scalar-activate-button button" onClick={function () {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
(_b = (_a = controllerRef.current) === null || _a === void 0 ? void 0 : _a.openClient) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
18
|
+
setIsOpen(true);
|
|
19
|
+
}}>
|
|
20
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="12" fill="none">
|
|
21
|
+
<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
|
+
</svg>
|
|
23
|
+
Test it
|
|
24
|
+
</button>
|
|
25
|
+
|
|
26
|
+
{isOpen &&
|
|
27
|
+
createPortal(<ScalarModal controllerRef={controllerRef} method={method} path={path} specUrl={specUrl}/>, document.body)}
|
|
28
|
+
</div>);
|
|
29
|
+
}
|
|
30
|
+
function ScalarModal(props) {
|
|
31
|
+
return (<ApiClientModalProvider configuration={{ spec: { url: props.specUrl } }} initialRequest={{ path: props.path, method: props.method }}>
|
|
32
|
+
<ScalarModalController method={props.method} path={props.path} controllerRef={props.controllerRef}/>
|
|
33
|
+
</ApiClientModalProvider>);
|
|
34
|
+
}
|
|
35
|
+
function ScalarModalController(props) {
|
|
36
|
+
var client = useApiClientModal();
|
|
37
|
+
var openClient = client === null || client === void 0 ? void 0 : client.open;
|
|
38
|
+
useImperativeHandle(props.controllerRef, function () { return ({ openClient: openClient ? function () { return openClient(); } : undefined }); }, [openClient]);
|
|
39
|
+
// Open the client when the component is mounted.
|
|
40
|
+
var onOpenClient = useOpenAPIOperationContext().onOpenClient;
|
|
41
|
+
var trackOpening = useEventCallback(function () {
|
|
42
|
+
onOpenClient({ method: props.method, path: props.path });
|
|
43
|
+
});
|
|
44
|
+
useEffect(function () {
|
|
45
|
+
if (openClient) {
|
|
46
|
+
openClient();
|
|
47
|
+
trackOpening();
|
|
48
|
+
}
|
|
49
|
+
}, [openClient]);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
package/dist/code-samples.d.ts
CHANGED
|
@@ -11,4 +11,8 @@ interface CodeSampleGenerator {
|
|
|
11
11
|
generate: (operation: CodeSampleInput) => string;
|
|
12
12
|
}
|
|
13
13
|
export declare const codeSampleGenerators: CodeSampleGenerator[];
|
|
14
|
+
export declare function parseHostAndPath(url: string): {
|
|
15
|
+
host: string | undefined;
|
|
16
|
+
path: string;
|
|
17
|
+
};
|
|
14
18
|
export {};
|
package/dist/code-samples.js
CHANGED
|
@@ -1,69 +1,134 @@
|
|
|
1
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
13
|
+
export var codeSampleGenerators = [
|
|
2
14
|
{
|
|
3
|
-
id: '
|
|
4
|
-
label: '
|
|
5
|
-
syntax: '
|
|
6
|
-
generate: (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
id: 'curl',
|
|
16
|
+
label: 'cURL',
|
|
17
|
+
syntax: 'bash',
|
|
18
|
+
generate: function (_a) {
|
|
19
|
+
var method = _a.method, url = _a.url, headers = _a.headers, body = _a.body;
|
|
20
|
+
var separator = ' \\\n';
|
|
21
|
+
var lines = ['curl -L'];
|
|
22
|
+
if (method.toUpperCase() !== 'GET') {
|
|
23
|
+
lines.push("--request ".concat(method.toUpperCase()));
|
|
24
|
+
}
|
|
25
|
+
lines.push("--url '".concat(url, "'"));
|
|
10
26
|
if (headers) {
|
|
11
|
-
|
|
27
|
+
Object.entries(headers).forEach(function (_a) {
|
|
28
|
+
var key = _a[0], value = _a[1];
|
|
29
|
+
lines.push("--header '".concat(key, ": ").concat(value, "'"));
|
|
30
|
+
});
|
|
12
31
|
}
|
|
13
|
-
if (body) {
|
|
14
|
-
|
|
32
|
+
if (body && Object.keys(body).length > 0) {
|
|
33
|
+
lines.push("--data '".concat(stringifyOpenAPI(body), "'"));
|
|
15
34
|
}
|
|
16
|
-
|
|
17
|
-
code += `const data = await response.json();`;
|
|
18
|
-
return code;
|
|
35
|
+
return lines.map(function (line, index) { return (index > 0 ? indent(line, 2) : line); }).join(separator);
|
|
19
36
|
},
|
|
20
37
|
},
|
|
21
38
|
{
|
|
22
|
-
id: '
|
|
23
|
-
label: '
|
|
24
|
-
syntax: '
|
|
25
|
-
generate: (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
lines.push(`-X ${method.toUpperCase()}`);
|
|
30
|
-
}
|
|
39
|
+
id: 'javascript',
|
|
40
|
+
label: 'JavaScript',
|
|
41
|
+
syntax: 'javascript',
|
|
42
|
+
generate: function (_a) {
|
|
43
|
+
var method = _a.method, url = _a.url, headers = _a.headers, body = _a.body;
|
|
44
|
+
var code = '';
|
|
45
|
+
code += "const response = await fetch('".concat(url, "', {\n method: '").concat(method.toUpperCase(), "',\n");
|
|
31
46
|
if (headers) {
|
|
32
|
-
|
|
33
|
-
lines.push(`-H '${key}: ${value}'`);
|
|
34
|
-
});
|
|
47
|
+
code += indent("headers: ".concat(stringifyOpenAPI(headers, null, 2), ",\n"), 4);
|
|
35
48
|
}
|
|
36
|
-
lines.push(`'${url}'`);
|
|
37
49
|
if (body) {
|
|
38
|
-
|
|
50
|
+
code += indent("body: JSON.stringify(".concat(stringifyOpenAPI(body, null, 2), "),\n"), 4);
|
|
39
51
|
}
|
|
40
|
-
|
|
52
|
+
code += "});\n";
|
|
53
|
+
code += "const data = await response.json();";
|
|
54
|
+
return code;
|
|
41
55
|
},
|
|
42
56
|
},
|
|
43
57
|
{
|
|
44
58
|
id: 'python',
|
|
45
59
|
label: 'Python',
|
|
46
60
|
syntax: 'python',
|
|
47
|
-
generate: (
|
|
48
|
-
|
|
49
|
-
code
|
|
50
|
-
code +=
|
|
61
|
+
generate: function (_a) {
|
|
62
|
+
var method = _a.method, url = _a.url, headers = _a.headers, body = _a.body;
|
|
63
|
+
var code = 'import requests\n\n';
|
|
64
|
+
code += "response = requests.".concat(method.toLowerCase(), "(\n");
|
|
65
|
+
code += indent("\"".concat(url, "\",\n"), 4);
|
|
51
66
|
if (headers) {
|
|
52
|
-
code += indent(
|
|
67
|
+
code += indent("headers=".concat(stringifyOpenAPI(headers), ",\n"), 4);
|
|
53
68
|
}
|
|
54
69
|
if (body) {
|
|
55
|
-
code += indent(
|
|
70
|
+
code += indent("json=".concat(stringifyOpenAPI(body), "\n"), 4);
|
|
56
71
|
}
|
|
57
72
|
code += ')\n';
|
|
58
|
-
code +=
|
|
73
|
+
code += "data = response.json()";
|
|
59
74
|
return code;
|
|
60
75
|
},
|
|
61
76
|
},
|
|
77
|
+
{
|
|
78
|
+
id: 'http',
|
|
79
|
+
label: 'HTTP',
|
|
80
|
+
syntax: 'bash',
|
|
81
|
+
generate: function (_a) {
|
|
82
|
+
var method = _a.method, url = _a.url, _b = _a.headers, headers = _b === void 0 ? {} : _b, body = _a.body;
|
|
83
|
+
var _c = parseHostAndPath(url), host = _c.host, path = _c.path;
|
|
84
|
+
if (body) {
|
|
85
|
+
// if we had a body add a content length header
|
|
86
|
+
var bodyContent = body ? stringifyOpenAPI(body) : '';
|
|
87
|
+
// handle unicode chars with a text encoder
|
|
88
|
+
var encoder = new TextEncoder();
|
|
89
|
+
headers = __assign(__assign({}, headers), { 'Content-Length': encoder.encode(bodyContent).length.toString() });
|
|
90
|
+
}
|
|
91
|
+
if (!headers.hasOwnProperty('Accept')) {
|
|
92
|
+
headers.Accept = '*/*';
|
|
93
|
+
}
|
|
94
|
+
var headerString = headers
|
|
95
|
+
? Object.entries(headers)
|
|
96
|
+
.map(function (_a) {
|
|
97
|
+
var key = _a[0], value = _a[1];
|
|
98
|
+
return key.toLowerCase() !== 'host' ? "".concat(key, ": ").concat(value) : "";
|
|
99
|
+
})
|
|
100
|
+
.join('\n') + '\n'
|
|
101
|
+
: '';
|
|
102
|
+
var bodyString = body ? "\n".concat(stringifyOpenAPI(body, null, 2)) : '';
|
|
103
|
+
var httpRequest = "".concat(method.toUpperCase(), " ").concat(decodeURI(path), " HTTP/1.1\nHost: ").concat(host, "\n").concat(headerString).concat(bodyString);
|
|
104
|
+
return httpRequest;
|
|
105
|
+
},
|
|
106
|
+
},
|
|
62
107
|
];
|
|
63
108
|
function indent(code, spaces) {
|
|
64
|
-
|
|
109
|
+
var indent = ' '.repeat(spaces);
|
|
65
110
|
return code
|
|
66
111
|
.split('\n')
|
|
67
|
-
.map((line)
|
|
112
|
+
.map(function (line) { return (line ? indent + line : ''); })
|
|
68
113
|
.join('\n');
|
|
69
114
|
}
|
|
115
|
+
export function parseHostAndPath(url) {
|
|
116
|
+
try {
|
|
117
|
+
var urlObj = new URL(url);
|
|
118
|
+
var path = urlObj.pathname || '/';
|
|
119
|
+
return { host: urlObj.host, path: path };
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
// If the URL was invalid do our best to parse the URL.
|
|
123
|
+
// Check for the protocol part and pull it off to grab the host
|
|
124
|
+
var splitted = url.split('//');
|
|
125
|
+
var fullUrl = splitted[1] ? splitted[1] : url;
|
|
126
|
+
// separate paths from the first element (host)
|
|
127
|
+
var parts = fullUrl.split('/');
|
|
128
|
+
// pull off the host (mutates)
|
|
129
|
+
var host = parts.shift();
|
|
130
|
+
// add a leading slash and join the paths again
|
|
131
|
+
var path = '/' + parts.join('/');
|
|
132
|
+
return { host: host, path: path };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -1,55 +1,21 @@
|
|
|
1
1
|
import { toJSON, fromJSON } from 'flatted';
|
|
2
|
-
import { OpenAPIV3 } from 'openapi-
|
|
3
|
-
|
|
2
|
+
import { type OpenAPICustomOperationProperties, type OpenAPICustomSpecProperties, type OpenAPIV3xDocument, type Filesystem, type OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
3
|
+
export interface OpenAPIFetcher {
|
|
4
|
+
/**
|
|
5
|
+
* Fetch an OpenAPI file by its URL. It should return a fully parsed OpenAPI v3 document.
|
|
6
|
+
*/
|
|
7
|
+
fetch: (url: string) => Promise<Filesystem<OpenAPIV3xDocument>>;
|
|
8
|
+
}
|
|
4
9
|
export interface OpenAPIOperationData extends OpenAPICustomSpecProperties {
|
|
5
10
|
path: string;
|
|
6
11
|
method: string;
|
|
7
12
|
/** Servers to be used for this operation */
|
|
8
13
|
servers: OpenAPIV3.ServerObject[];
|
|
9
14
|
/** Spec of the operation */
|
|
10
|
-
operation: OpenAPIV3.OperationObject
|
|
15
|
+
operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
|
|
11
16
|
/** Securities that should be used for this operation */
|
|
12
17
|
securities: [string, OpenAPIV3.SecuritySchemeObject][];
|
|
13
18
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Custom properties that can be defined at the entire spec level.
|
|
16
|
-
*/
|
|
17
|
-
export interface OpenAPICustomSpecProperties {
|
|
18
|
-
/**
|
|
19
|
-
* If `true`, code samples will not be displayed.
|
|
20
|
-
* This option can be used to hide code samples for the entire spec.
|
|
21
|
-
*/
|
|
22
|
-
'x-codeSamples'?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* If `true`, the "Try it" button will not be displayed.
|
|
25
|
-
* This option can be used to hide code samples for the entire spec.
|
|
26
|
-
*/
|
|
27
|
-
'x-hideTryItPanel'?: boolean;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Custom properties that can be defined at the operation level.
|
|
31
|
-
* These properties are not part of the OpenAPI spec.
|
|
32
|
-
*/
|
|
33
|
-
export interface OpenAPICustomOperationProperties {
|
|
34
|
-
'x-code-samples'?: OpenAPICustomCodeSample[];
|
|
35
|
-
'x-codeSamples'?: OpenAPICustomCodeSample[] | false;
|
|
36
|
-
'x-custom-examples'?: OpenAPICustomCodeSample[];
|
|
37
|
-
/**
|
|
38
|
-
* If `true`, the "Try it" button will not be displayed.
|
|
39
|
-
* https://redocly.com/docs/api-reference-docs/specification-extensions/x-hidetryitpanel/
|
|
40
|
-
*/
|
|
41
|
-
'x-hideTryItPanel'?: boolean;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Custom code samples that can be defined at the operation level.
|
|
45
|
-
* It follows the spec defined by Redocly.
|
|
46
|
-
* https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples/
|
|
47
|
-
*/
|
|
48
|
-
export interface OpenAPICustomCodeSample {
|
|
49
|
-
lang: string;
|
|
50
|
-
label: string;
|
|
51
|
-
source: string;
|
|
52
|
-
}
|
|
53
19
|
export { toJSON, fromJSON };
|
|
54
20
|
/**
|
|
55
21
|
* Resolve an OpenAPI operation in a file and compile it to a more usable format.
|
|
@@ -58,15 +24,4 @@ export declare function fetchOpenAPIOperation(input: {
|
|
|
58
24
|
url: string;
|
|
59
25
|
path: string;
|
|
60
26
|
method: string;
|
|
61
|
-
},
|
|
62
|
-
/**
|
|
63
|
-
* Parse a raw string into an OpenAPI document.
|
|
64
|
-
* It will also convert Swagger 2.0 to OpenAPI 3.0.
|
|
65
|
-
* It can throw an `OpenAPIFetchError` if the document is invalid.
|
|
66
|
-
*/
|
|
67
|
-
export declare function parseOpenAPIV3(url: string, text: string): Promise<OpenAPIV3.Document>;
|
|
68
|
-
export declare class OpenAPIFetchError extends Error {
|
|
69
|
-
readonly url: string;
|
|
70
|
-
name: string;
|
|
71
|
-
constructor(message: string, url: string);
|
|
72
|
-
}
|
|
27
|
+
}, fetcher: OpenAPIFetcher): Promise<OpenAPIOperationData | null>;
|