@gitbook/react-openapi 1.4.3 → 1.5.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 +27 -0
- package/dist/index.d.ts +663 -10
- package/dist/index.js +3873 -8
- package/package.json +11 -7
- package/dist/InteractiveSection.d.ts +0 -33
- package/dist/InteractiveSection.jsx +0 -61
- package/dist/Markdown.d.ts +0 -4
- package/dist/Markdown.jsx +0 -5
- package/dist/OpenAPICodeSample.d.ts +0 -19
- package/dist/OpenAPICodeSample.jsx +0 -230
- package/dist/OpenAPICodeSampleInteractive.d.ts +0 -14
- package/dist/OpenAPICodeSampleInteractive.jsx +0 -73
- package/dist/OpenAPICodeSampleSelector.d.ts +0 -14
- package/dist/OpenAPICodeSampleSelector.jsx +0 -44
- package/dist/OpenAPICopyButton.d.ts +0 -13
- package/dist/OpenAPICopyButton.jsx +0 -35
- package/dist/OpenAPIDisclosure.d.ts +0 -11
- package/dist/OpenAPIDisclosure.jsx +0 -30
- package/dist/OpenAPIDisclosureGroup.d.ts +0 -23
- package/dist/OpenAPIDisclosureGroup.jsx +0 -83
- package/dist/OpenAPIExample.d.ts +0 -16
- package/dist/OpenAPIExample.jsx +0 -36
- package/dist/OpenAPIMediaType.d.ts +0 -21
- package/dist/OpenAPIMediaType.jsx +0 -61
- package/dist/OpenAPIOperation.d.ts +0 -10
- package/dist/OpenAPIOperation.jsx +0 -25
- package/dist/OpenAPIOperationContext.d.ts +0 -16
- package/dist/OpenAPIOperationContext.jsx +0 -26
- package/dist/OpenAPIOperationDescription.d.ts +0 -9
- package/dist/OpenAPIOperationDescription.jsx +0 -22
- package/dist/OpenAPIOperationStability.d.ts +0 -9
- package/dist/OpenAPIOperationStability.jsx +0 -27
- package/dist/OpenAPIPath.d.ts +0 -18
- package/dist/OpenAPIPath.jsx +0 -55
- package/dist/OpenAPIPrefillContextProvider.d.ts +0 -22
- package/dist/OpenAPIPrefillContextProvider.jsx +0 -19
- package/dist/OpenAPIRequestBody.d.ts +0 -11
- package/dist/OpenAPIRequestBody.jsx +0 -28
- package/dist/OpenAPIRequestBodyHeaderType.d.ts +0 -8
- package/dist/OpenAPIRequestBodyHeaderType.jsx +0 -25
- package/dist/OpenAPIResponse.d.ts +0 -10
- package/dist/OpenAPIResponse.jsx +0 -57
- package/dist/OpenAPIResponseExample.d.ts +0 -9
- package/dist/OpenAPIResponseExample.jsx +0 -105
- package/dist/OpenAPIResponseExampleContent.d.ts +0 -22
- package/dist/OpenAPIResponseExampleContent.jsx +0 -60
- package/dist/OpenAPIResponses.d.ts +0 -9
- package/dist/OpenAPIResponses.jsx +0 -77
- package/dist/OpenAPISchema.d.ts +0 -27
- package/dist/OpenAPISchema.jsx +0 -400
- package/dist/OpenAPISchemaName.d.ts +0 -16
- package/dist/OpenAPISchemaName.jsx +0 -43
- package/dist/OpenAPISchemaServer.d.ts +0 -12
- package/dist/OpenAPISchemaServer.jsx +0 -8
- package/dist/OpenAPISecurities.d.ts +0 -9
- package/dist/OpenAPISecurities.jsx +0 -114
- package/dist/OpenAPISelect.d.ts +0 -22
- package/dist/OpenAPISelect.jsx +0 -44
- package/dist/OpenAPISpec.d.ts +0 -6
- package/dist/OpenAPISpec.jsx +0 -80
- package/dist/OpenAPITabs.d.ts +0 -26
- package/dist/OpenAPITabs.jsx +0 -109
- package/dist/OpenAPIWebhook.d.ts +0 -10
- package/dist/OpenAPIWebhook.jsx +0 -23
- package/dist/OpenAPIWebhookExample.d.ts +0 -6
- package/dist/OpenAPIWebhookExample.jsx +0 -41
- package/dist/ScalarApiButton.d.ts +0 -14
- package/dist/ScalarApiButton.jsx +0 -81
- package/dist/StaticSection.d.ts +0 -13
- package/dist/StaticSection.jsx +0 -32
- package/dist/code-samples.d.ts +0 -17
- package/dist/code-samples.js +0 -427
- package/dist/common/OpenAPIColumnSpec.d.ts +0 -6
- package/dist/common/OpenAPIColumnSpec.jsx +0 -20
- package/dist/common/OpenAPIOperationDescription.d.ts +0 -6
- package/dist/common/OpenAPIOperationDescription.jsx +0 -19
- package/dist/common/OpenAPIStability.d.ts +0 -4
- package/dist/common/OpenAPIStability.jsx +0 -15
- package/dist/common/OpenAPISummary.d.ts +0 -6
- package/dist/common/OpenAPISummary.jsx +0 -30
- package/dist/contentTypeChecks.d.ts +0 -10
- package/dist/contentTypeChecks.js +0 -30
- package/dist/context.d.ts +0 -75
- package/dist/context.js +0 -43
- package/dist/decycle.d.ts +0 -2
- package/dist/decycle.js +0 -70
- package/dist/dereference.d.ts +0 -5
- package/dist/dereference.js +0 -68
- package/dist/generateSchemaExample.d.ts +0 -45
- package/dist/generateSchemaExample.js +0 -342
- package/dist/getDisclosureLabel.d.ts +0 -7
- package/dist/getDisclosureLabel.js +0 -18
- package/dist/getOrCreateStoreByKey.d.ts +0 -10
- package/dist/getOrCreateStoreByKey.js +0 -19
- package/dist/json2xml.d.ts +0 -4
- package/dist/json2xml.js +0 -7
- package/dist/resolveOpenAPIOperation.d.ts +0 -11
- package/dist/resolveOpenAPIOperation.js +0 -173
- package/dist/resolveOpenAPIWebhook.d.ts +0 -11
- package/dist/resolveOpenAPIWebhook.js +0 -127
- package/dist/schemas/OpenAPISchemaItem.d.ts +0 -7
- package/dist/schemas/OpenAPISchemaItem.jsx +0 -16
- package/dist/schemas/OpenAPISchemas.d.ts +0 -14
- package/dist/schemas/OpenAPISchemas.jsx +0 -59
- package/dist/schemas/index.d.ts +0 -2
- package/dist/schemas/index.js +0 -2
- package/dist/schemas/resolveOpenAPISchemas.d.ts +0 -10
- package/dist/schemas/resolveOpenAPISchemas.js +0 -61
- package/dist/stringifyOpenAPI.d.ts +0 -4
- package/dist/stringifyOpenAPI.js +0 -15
- package/dist/translate.d.ts +0 -10
- package/dist/translate.jsx +0 -75
- package/dist/translations/de.d.ts +0 -43
- package/dist/translations/de.js +0 -43
- package/dist/translations/en.d.ts +0 -43
- package/dist/translations/en.js +0 -43
- package/dist/translations/es.d.ts +0 -43
- package/dist/translations/es.js +0 -43
- package/dist/translations/fr.d.ts +0 -43
- package/dist/translations/fr.js +0 -43
- package/dist/translations/index.d.ts +0 -395
- package/dist/translations/index.js +0 -27
- package/dist/translations/ja.d.ts +0 -43
- package/dist/translations/ja.js +0 -43
- package/dist/translations/nl.d.ts +0 -43
- package/dist/translations/nl.js +0 -43
- package/dist/translations/no.d.ts +0 -43
- package/dist/translations/no.js +0 -43
- package/dist/translations/pt-br.d.ts +0 -43
- package/dist/translations/pt-br.js +0 -43
- package/dist/translations/types.d.ts +0 -5
- package/dist/translations/types.js +0 -1
- package/dist/translations/zh.d.ts +0 -43
- package/dist/translations/zh.js +0 -43
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types.d.ts +0 -31
- package/dist/types.js +0 -1
- package/dist/util/example.d.ts +0 -35
- package/dist/util/example.jsx +0 -103
- package/dist/util/server.d.ts +0 -9
- package/dist/util/server.js +0 -44
- package/dist/util/tryit-prefill.d.ts +0 -20
- package/dist/util/tryit-prefill.js +0 -129
- package/dist/utils.d.ts +0 -50
- package/dist/utils.js +0 -224
- package/src/InteractiveSection.tsx +0 -147
- package/src/Markdown.tsx +0 -12
- package/src/OpenAPICodeSample.tsx +0 -330
- package/src/OpenAPICodeSampleInteractive.tsx +0 -136
- package/src/OpenAPICodeSampleSelector.tsx +0 -94
- package/src/OpenAPICopyButton.tsx +0 -72
- package/src/OpenAPIDisclosure.tsx +0 -46
- package/src/OpenAPIDisclosureGroup.tsx +0 -158
- package/src/OpenAPIExample.tsx +0 -55
- package/src/OpenAPIMediaType.tsx +0 -139
- package/src/OpenAPIOperation.tsx +0 -35
- package/src/OpenAPIOperationContext.tsx +0 -45
- package/src/OpenAPIOperationDescription.tsx +0 -34
- package/src/OpenAPIOperationStability.tsx +0 -39
- package/src/OpenAPIPath.tsx +0 -90
- package/src/OpenAPIPrefillContextProvider.tsx +0 -40
- package/src/OpenAPIRequestBody.tsx +0 -54
- package/src/OpenAPIRequestBodyHeaderType.tsx +0 -36
- package/src/OpenAPIResponse.tsx +0 -82
- package/src/OpenAPIResponseExample.tsx +0 -151
- package/src/OpenAPIResponseExampleContent.tsx +0 -125
- package/src/OpenAPIResponses.tsx +0 -125
- package/src/OpenAPISchema.test.ts +0 -172
- package/src/OpenAPISchema.tsx +0 -654
- package/src/OpenAPISchemaName.tsx +0 -80
- package/src/OpenAPISchemaServer.tsx +0 -34
- package/src/OpenAPISecurities.tsx +0 -231
- package/src/OpenAPISelect.tsx +0 -96
- package/src/OpenAPISpec.tsx +0 -138
- package/src/OpenAPITabs.tsx +0 -147
- package/src/OpenAPIWebhook.tsx +0 -33
- package/src/OpenAPIWebhookExample.tsx +0 -60
- package/src/ScalarApiButton.tsx +0 -132
- package/src/StaticSection.tsx +0 -91
- package/src/__snapshots__/json2xml.test.ts.snap +0 -18
- package/src/code-samples.test.ts +0 -714
- package/src/code-samples.ts +0 -448
- package/src/common/OpenAPIColumnSpec.tsx +0 -31
- package/src/common/OpenAPIOperationDescription.tsx +0 -31
- package/src/common/OpenAPIStability.tsx +0 -23
- package/src/common/OpenAPISummary.tsx +0 -45
- package/src/contentTypeChecks.ts +0 -39
- package/src/context.ts +0 -99
- package/src/decycle.ts +0 -68
- package/src/dereference.ts +0 -29
- package/src/generateSchemaExample.test.ts +0 -1040
- package/src/generateSchemaExample.ts +0 -530
- package/src/getDisclosureLabel.ts +0 -25
- package/src/getOrCreateStoreByKey.ts +0 -33
- package/src/index.ts +0 -10
- package/src/json2xml.test.ts +0 -46
- package/src/json2xml.ts +0 -8
- package/src/resolveOpenAPIOperation.test.ts +0 -177
- package/src/resolveOpenAPIOperation.ts +0 -151
- package/src/resolveOpenAPIWebhook.ts +0 -99
- package/src/schemas/OpenAPISchemaItem.tsx +0 -34
- package/src/schemas/OpenAPISchemas.tsx +0 -98
- package/src/schemas/index.ts +0 -2
- package/src/schemas/resolveOpenAPISchemas.test.ts +0 -174
- package/src/schemas/resolveOpenAPISchemas.ts +0 -28
- package/src/stringifyOpenAPI.ts +0 -25
- package/src/translate.tsx +0 -80
- package/src/translations/de.ts +0 -43
- package/src/translations/en.ts +0 -43
- package/src/translations/es.ts +0 -43
- package/src/translations/fr.ts +0 -43
- package/src/translations/index.ts +0 -33
- package/src/translations/ja.ts +0 -43
- package/src/translations/nl.ts +0 -43
- package/src/translations/no.ts +0 -43
- package/src/translations/pt-br.ts +0 -43
- package/src/translations/types.ts +0 -7
- package/src/translations/zh.ts +0 -43
- package/src/types.ts +0 -46
- package/src/util/example.tsx +0 -129
- package/src/util/server.test.ts +0 -58
- package/src/util/server.ts +0 -47
- package/src/util/tryit-prefill.test.ts +0 -311
- package/src/util/tryit-prefill.ts +0 -160
- package/src/utils.ts +0 -255
package/package.json
CHANGED
|
@@ -4,15 +4,14 @@
|
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"development": "./src/index.ts",
|
|
8
7
|
"default": "./dist/index.js"
|
|
9
8
|
}
|
|
10
9
|
},
|
|
11
|
-
"version": "1.
|
|
10
|
+
"version": "1.5.1",
|
|
12
11
|
"sideEffects": false,
|
|
13
12
|
"dependencies": {
|
|
14
|
-
"@gitbook/expr": "
|
|
15
|
-
"@gitbook/openapi-parser": "
|
|
13
|
+
"@gitbook/expr": "1.2.2",
|
|
14
|
+
"@gitbook/openapi-parser": "3.0.3",
|
|
16
15
|
"@scalar/api-client-react": "^1.3.16",
|
|
17
16
|
"@scalar/oas-utils": "^0.2.130",
|
|
18
17
|
"@scalar/types": "^0.1.9",
|
|
@@ -28,17 +27,22 @@
|
|
|
28
27
|
"devDependencies": {
|
|
29
28
|
"@types/js-yaml": "^4.0.9",
|
|
30
29
|
"bun-types": "^1.1.20",
|
|
30
|
+
"tsdown": "^0.15.6",
|
|
31
31
|
"typescript": "^5.5.3"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"react": "*"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "
|
|
37
|
+
"build": "tsdown",
|
|
38
38
|
"typecheck": "tsc --noEmit",
|
|
39
39
|
"unit": "bun test",
|
|
40
|
-
"dev": "bun run build -- --watch",
|
|
40
|
+
"dev": "bun run build -- --watch ./src",
|
|
41
41
|
"clean": "rm -rf ./dist"
|
|
42
42
|
},
|
|
43
|
-
"files": ["dist", "
|
|
43
|
+
"files": ["dist", "README.md", "CHANGELOG.md"],
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"registry": "https://registry.npmjs.org/"
|
|
47
|
+
}
|
|
44
48
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
interface InteractiveSectionTab {
|
|
2
|
-
key: string;
|
|
3
|
-
label: string;
|
|
4
|
-
body: React.ReactNode;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* To optimize rendering, most of the components are server-components,
|
|
8
|
-
* and the interactiveness is mainly handled by a few key components like this one.
|
|
9
|
-
*/
|
|
10
|
-
export declare function InteractiveSection(props: {
|
|
11
|
-
id?: string;
|
|
12
|
-
/** Class name to be set on the section, sub-elements will use it as prefix */
|
|
13
|
-
className: string;
|
|
14
|
-
/** If true, the content can be toggeable */
|
|
15
|
-
toggeable?: boolean;
|
|
16
|
-
/** Default state of the toggle */
|
|
17
|
-
defaultOpened?: boolean;
|
|
18
|
-
/** Icon to display for the toggle */
|
|
19
|
-
toggleIcon?: React.ReactNode;
|
|
20
|
-
/** Tabs of content to display */
|
|
21
|
-
tabs?: Array<InteractiveSectionTab>;
|
|
22
|
-
/** Default tab to have opened */
|
|
23
|
-
defaultTab?: string;
|
|
24
|
-
/** Content of the header */
|
|
25
|
-
header?: React.ReactNode;
|
|
26
|
-
/** Children to display within the container */
|
|
27
|
-
overlay?: React.ReactNode;
|
|
28
|
-
/** State key to use with a store */
|
|
29
|
-
stateKey?: string;
|
|
30
|
-
/** Icon for the tabs select */
|
|
31
|
-
selectIcon?: React.ReactNode;
|
|
32
|
-
}): import("react").JSX.Element;
|
|
33
|
-
export {};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import { useRef } from 'react';
|
|
4
|
-
import { mergeProps, useButton, useDisclosure, useFocusRing } from 'react-aria';
|
|
5
|
-
import { useDisclosureState } from 'react-stately';
|
|
6
|
-
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
|
|
7
|
-
import { Section, SectionBody, SectionHeader, SectionHeaderContent } from './StaticSection';
|
|
8
|
-
/**
|
|
9
|
-
* To optimize rendering, most of the components are server-components,
|
|
10
|
-
* and the interactiveness is mainly handled by a few key components like this one.
|
|
11
|
-
*/
|
|
12
|
-
export function InteractiveSection(props) {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
var id = props.id, className = props.className, _c = props.toggeable, toggeable = _c === void 0 ? false : _c, _d = props.defaultOpened, defaultOpened = _d === void 0 ? true : _d, _e = props.tabs, tabs = _e === void 0 ? [] : _e, _f = props.defaultTab, defaultTab = _f === void 0 ? (_a = tabs[0]) === null || _a === void 0 ? void 0 : _a.key : _f, header = props.header, overlay = props.overlay, _g = props.toggleIcon, toggleIcon = _g === void 0 ? '▶' : _g, selectIcon = props.selectIcon, _h = props.stateKey, stateKey = _h === void 0 ? 'interactive-section' : _h;
|
|
15
|
-
var state = useDisclosureState({
|
|
16
|
-
defaultExpanded: defaultOpened,
|
|
17
|
-
});
|
|
18
|
-
var panelRef = useRef(null);
|
|
19
|
-
var triggerRef = useRef(null);
|
|
20
|
-
var _j = useDisclosure({}, state, panelRef), triggerProps = _j.buttonProps, panelProps = _j.panelProps;
|
|
21
|
-
var buttonProps = useButton(triggerProps, triggerRef).buttonProps;
|
|
22
|
-
var _k = useFocusRing(), isFocusVisible = _k.isFocusVisible, focusProps = _k.focusProps;
|
|
23
|
-
var store = useSelectState(stateKey, defaultTab);
|
|
24
|
-
var selectedTab = (_b = tabs.find(function (tab) { return tab.key === store.key; })) !== null && _b !== void 0 ? _b : tabs[0];
|
|
25
|
-
return (<Section id={id} className={clsx('openapi-section', toggeable ? 'openapi-section-toggeable' : null, className, toggeable ? "".concat(className, "-").concat(state.isExpanded ? 'opened' : 'closed') : null)}>
|
|
26
|
-
{header ? (<SectionHeader onClick={function () {
|
|
27
|
-
if (toggeable) {
|
|
28
|
-
state.toggle();
|
|
29
|
-
}
|
|
30
|
-
}} className={className}>
|
|
31
|
-
<SectionHeaderContent className={className}>
|
|
32
|
-
{(selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.body) && toggeable ? (<button {...mergeProps(buttonProps, focusProps)} ref={triggerRef} className={clsx('openapi-section-toggle', "".concat(className, "-toggle"))} style={{
|
|
33
|
-
outline: isFocusVisible
|
|
34
|
-
? '2px solid rgb(var(--primary-color-500) / 0.4)'
|
|
35
|
-
: 'none',
|
|
36
|
-
}}>
|
|
37
|
-
{toggleIcon}
|
|
38
|
-
</button>) : null}
|
|
39
|
-
{header}
|
|
40
|
-
</SectionHeaderContent>
|
|
41
|
-
{/* biome-ignore lint/a11y/useKeyWithClickEvents: we prevent default here */}
|
|
42
|
-
<div className={clsx('openapi-section-header-controls', "".concat(className, "-header-controls"))} onClick={function (event) {
|
|
43
|
-
event.stopPropagation();
|
|
44
|
-
}}>
|
|
45
|
-
{tabs.length > 0 ? (<OpenAPISelect stateKey={stateKey} items={tabs} onSelectionChange={function () {
|
|
46
|
-
state.expand();
|
|
47
|
-
}} icon={selectIcon} placement="bottom end">
|
|
48
|
-
{tabs.map(function (tab) { return (<OpenAPISelectItem key={tab.key} id={tab.key} value={tab}>
|
|
49
|
-
{tab.label}
|
|
50
|
-
</OpenAPISelectItem>); })}
|
|
51
|
-
</OpenAPISelect>) : null}
|
|
52
|
-
</div>
|
|
53
|
-
</SectionHeader>) : null}
|
|
54
|
-
{(!toggeable || state.isExpanded) && (selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.body) ? (<SectionBody ref={panelRef} {...panelProps} className={className}>
|
|
55
|
-
{selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.body}
|
|
56
|
-
</SectionBody>) : null}
|
|
57
|
-
{overlay ? (<div className={clsx('openapi-section-overlay', "".concat(className, "-overlay"))}>
|
|
58
|
-
{overlay}
|
|
59
|
-
</div>) : null}
|
|
60
|
-
</Section>);
|
|
61
|
-
}
|
package/dist/Markdown.d.ts
DELETED
package/dist/Markdown.jsx
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import { type OpenAPIContext } from './context';
|
|
3
|
-
import type { OpenAPIOperationData } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Display code samples to execute the operation.
|
|
6
|
-
* It supports the Redocly custom syntax as well (https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples/)
|
|
7
|
-
*/
|
|
8
|
-
export declare function OpenAPICodeSample(props: {
|
|
9
|
-
data: OpenAPIOperationData;
|
|
10
|
-
context: OpenAPIContext;
|
|
11
|
-
}): import("react").JSX.Element | null;
|
|
12
|
-
export interface MediaTypeRenderer {
|
|
13
|
-
mediaType: string;
|
|
14
|
-
element: React.ReactNode;
|
|
15
|
-
examples: Array<{
|
|
16
|
-
example: OpenAPIV3.ExampleObject;
|
|
17
|
-
element: React.ReactNode;
|
|
18
|
-
}>;
|
|
19
|
-
}
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { OpenAPIMediaTypeExamplesBody, OpenAPIMediaTypeExamplesSelector, } from './OpenAPICodeSampleInteractive';
|
|
13
|
-
import { OpenAPICodeSampleBody } from './OpenAPICodeSampleSelector';
|
|
14
|
-
import { ScalarApiButton } from './ScalarApiButton';
|
|
15
|
-
import { codeSampleGenerators } from './code-samples';
|
|
16
|
-
import { getOpenAPIClientContext } from './context';
|
|
17
|
-
import { generateMediaTypeExamples, generateSchemaExample } from './generateSchemaExample';
|
|
18
|
-
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
19
|
-
import { getDefaultServerURL } from './util/server';
|
|
20
|
-
import { checkIsReference } from './utils';
|
|
21
|
-
var CUSTOM_CODE_SAMPLES_KEYS = ['x-custom-examples', 'x-code-samples', 'x-codeSamples'];
|
|
22
|
-
/**
|
|
23
|
-
* Display code samples to execute the operation.
|
|
24
|
-
* It supports the Redocly custom syntax as well (https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples/)
|
|
25
|
-
*/
|
|
26
|
-
export function OpenAPICodeSample(props) {
|
|
27
|
-
var data = props.data, context = props.context;
|
|
28
|
-
// If code samples are disabled at operation level, we don't display the code samples.
|
|
29
|
-
if (data.operation['x-codeSamples'] === false) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
var customCodeSamples = getCustomCodeSamples(props);
|
|
33
|
-
// If code samples are disabled at the top-level and not custom code samples are defined,
|
|
34
|
-
// we don't display the code samples.
|
|
35
|
-
if (data['x-codeSamples'] === false && !customCodeSamples) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
var samples = customCodeSamples !== null && customCodeSamples !== void 0 ? customCodeSamples : generateCodeSamples(props);
|
|
39
|
-
if (samples.length === 0) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
return (<OpenAPICodeSampleBody context={getOpenAPIClientContext(context)} data={data} items={samples} selectIcon={context.icons.chevronDown}/>);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Generate code samples for the operation.
|
|
46
|
-
*/
|
|
47
|
-
function generateCodeSamples(props) {
|
|
48
|
-
var _a;
|
|
49
|
-
var data = props.data, context = props.context;
|
|
50
|
-
var searchParams = new URLSearchParams();
|
|
51
|
-
var headersObject = {};
|
|
52
|
-
// The parser can sometimes returns invalid parameters (an object instead of an array).
|
|
53
|
-
// It should get fixed in scalar, but in the meantime we just ignore the parameters in that case.
|
|
54
|
-
var params = Array.isArray(data.operation.parameters) ? data.operation.parameters : [];
|
|
55
|
-
params.forEach(function (param) {
|
|
56
|
-
if (!param) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (param.in === 'header' && param.required) {
|
|
60
|
-
var example = param.schema
|
|
61
|
-
? generateSchemaExample(param.schema, { mode: 'write' })
|
|
62
|
-
: undefined;
|
|
63
|
-
if (example !== undefined && param.name) {
|
|
64
|
-
headersObject[param.name] =
|
|
65
|
-
typeof example !== 'string' ? stringifyOpenAPI(example) : example;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else if (param.in === 'query' && param.required) {
|
|
69
|
-
var example = param.schema
|
|
70
|
-
? generateSchemaExample(param.schema, { mode: 'write' })
|
|
71
|
-
: undefined;
|
|
72
|
-
if (example !== undefined && param.name) {
|
|
73
|
-
searchParams.append(param.name, String(Array.isArray(example) ? example[0] : example));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
var requestBody = !checkIsReference(data.operation.requestBody)
|
|
78
|
-
? data.operation.requestBody
|
|
79
|
-
: undefined;
|
|
80
|
-
var url = getDefaultServerURL(data.servers) +
|
|
81
|
-
data.path +
|
|
82
|
-
(searchParams.size ? "?".concat(searchParams.toString()) : '');
|
|
83
|
-
var genericHeaders = __assign(__assign({}, getSecurityHeaders(data.securities)), headersObject);
|
|
84
|
-
var mediaTypeRendererFactories = Object.entries((_a = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
85
|
-
var mediaType = _a[0], mediaTypeObject = _a[1];
|
|
86
|
-
return function (generator) {
|
|
87
|
-
var mediaTypeHeaders = __assign(__assign({}, genericHeaders), { 'Content-Type': mediaType });
|
|
88
|
-
return {
|
|
89
|
-
mediaType: mediaType,
|
|
90
|
-
element: context.renderCodeBlock({
|
|
91
|
-
code: generator.generate({
|
|
92
|
-
url: url,
|
|
93
|
-
method: data.method,
|
|
94
|
-
body: undefined,
|
|
95
|
-
headers: mediaTypeHeaders,
|
|
96
|
-
}),
|
|
97
|
-
syntax: generator.syntax,
|
|
98
|
-
}),
|
|
99
|
-
examples: generateMediaTypeExamples(mediaTypeObject, {
|
|
100
|
-
mode: 'write',
|
|
101
|
-
}).map(function (example) { return ({
|
|
102
|
-
example: example,
|
|
103
|
-
element: context.renderCodeBlock({
|
|
104
|
-
code: generator.generate({
|
|
105
|
-
url: url,
|
|
106
|
-
method: data.method,
|
|
107
|
-
body: example.value,
|
|
108
|
-
headers: mediaTypeHeaders,
|
|
109
|
-
}),
|
|
110
|
-
syntax: generator.syntax,
|
|
111
|
-
}),
|
|
112
|
-
}); }),
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
});
|
|
116
|
-
return codeSampleGenerators.map(function (generator) {
|
|
117
|
-
if (mediaTypeRendererFactories.length > 0) {
|
|
118
|
-
var renderers = mediaTypeRendererFactories.map(function (generate) { return generate(generator); });
|
|
119
|
-
return {
|
|
120
|
-
key: "default-".concat(generator.id),
|
|
121
|
-
label: generator.label,
|
|
122
|
-
body: (<OpenAPIMediaTypeExamplesBody method={data.method} path={data.path} renderers={renderers} blockKey={context.blockKey}/>),
|
|
123
|
-
footer: (<OpenAPICodeSampleFooter renderers={renderers} data={data} context={context}/>),
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
key: "default-".concat(generator.id),
|
|
128
|
-
label: generator.label,
|
|
129
|
-
body: context.renderCodeBlock({
|
|
130
|
-
code: generator.generate({
|
|
131
|
-
url: url,
|
|
132
|
-
method: data.method,
|
|
133
|
-
body: undefined,
|
|
134
|
-
headers: genericHeaders,
|
|
135
|
-
}),
|
|
136
|
-
syntax: generator.syntax,
|
|
137
|
-
}),
|
|
138
|
-
footer: <OpenAPICodeSampleFooter data={data} renderers={[]} context={context}/>,
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
function OpenAPICodeSampleFooter(props) {
|
|
143
|
-
var data = props.data, context = props.context, renderers = props.renderers;
|
|
144
|
-
var method = data.method, path = data.path, securities = data.securities, servers = data.servers;
|
|
145
|
-
var specUrl = context.specUrl;
|
|
146
|
-
var hideTryItPanel = data['x-hideTryItPanel'] || data.operation['x-hideTryItPanel'];
|
|
147
|
-
var hasMultipleMediaTypes = renderers.length > 1 || renderers.some(function (renderer) { return renderer.examples.length > 0; });
|
|
148
|
-
if (hideTryItPanel && !hasMultipleMediaTypes) {
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
if (!validateHttpMethod(method)) {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
return (<div className="openapi-codesample-footer">
|
|
155
|
-
{hasMultipleMediaTypes ? (<OpenAPIMediaTypeExamplesSelector method={data.method} path={data.path} renderers={renderers} selectIcon={context.icons.chevronDown} blockKey={context.blockKey}/>) : (<span />)}
|
|
156
|
-
{!hideTryItPanel && (<ScalarApiButton context={getOpenAPIClientContext(context)} method={method} path={path} securities={securities} servers={servers} specUrl={specUrl}/>)}
|
|
157
|
-
</div>);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Get custom code samples for the operation.
|
|
161
|
-
*/
|
|
162
|
-
function getCustomCodeSamples(props) {
|
|
163
|
-
var data = props.data, context = props.context;
|
|
164
|
-
var customCodeSamples = null;
|
|
165
|
-
CUSTOM_CODE_SAMPLES_KEYS.forEach(function (key) {
|
|
166
|
-
var customSamples = data.operation[key];
|
|
167
|
-
if (customSamples && Array.isArray(customSamples)) {
|
|
168
|
-
customCodeSamples = customSamples
|
|
169
|
-
.filter(function (sample) {
|
|
170
|
-
return typeof sample.source === 'string' && typeof sample.lang === 'string';
|
|
171
|
-
})
|
|
172
|
-
.map(function (sample, index) { return ({
|
|
173
|
-
key: "custom-sample-".concat(sample.lang, "-").concat(index),
|
|
174
|
-
label: sample.label || sample.lang,
|
|
175
|
-
body: context.renderCodeBlock({
|
|
176
|
-
code: sample.source,
|
|
177
|
-
syntax: sample.lang,
|
|
178
|
-
}),
|
|
179
|
-
footer: (<OpenAPICodeSampleFooter renderers={[]} data={data} context={context}/>),
|
|
180
|
-
}); });
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
return customCodeSamples;
|
|
184
|
-
}
|
|
185
|
-
function getSecurityHeaders(securities) {
|
|
186
|
-
var _a;
|
|
187
|
-
var _b, _c;
|
|
188
|
-
var security = securities[0];
|
|
189
|
-
if (!security) {
|
|
190
|
-
return {};
|
|
191
|
-
}
|
|
192
|
-
switch (security[1].type) {
|
|
193
|
-
case 'http': {
|
|
194
|
-
var scheme = security[1].scheme;
|
|
195
|
-
var format = (_b = security[1].bearerFormat) !== null && _b !== void 0 ? _b : 'YOUR_SECRET_TOKEN';
|
|
196
|
-
if (scheme === null || scheme === void 0 ? void 0 : scheme.includes('bearer')) {
|
|
197
|
-
scheme = 'Bearer';
|
|
198
|
-
}
|
|
199
|
-
else if (scheme === null || scheme === void 0 ? void 0 : scheme.includes('basic')) {
|
|
200
|
-
scheme = 'Basic';
|
|
201
|
-
format = 'username:password';
|
|
202
|
-
}
|
|
203
|
-
else if (scheme === null || scheme === void 0 ? void 0 : scheme.includes('token')) {
|
|
204
|
-
scheme = 'Token';
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
Authorization: "".concat(scheme, " ").concat(format),
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
case 'apiKey': {
|
|
211
|
-
if (security[1].in !== 'header')
|
|
212
|
-
return {};
|
|
213
|
-
var name_1 = (_c = security[1].name) !== null && _c !== void 0 ? _c : 'Authorization';
|
|
214
|
-
return _a = {},
|
|
215
|
-
_a[name_1] = 'YOUR_API_KEY',
|
|
216
|
-
_a;
|
|
217
|
-
}
|
|
218
|
-
case 'oauth2': {
|
|
219
|
-
return {
|
|
220
|
-
Authorization: 'Bearer YOUR_OAUTH2_TOKEN',
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
default: {
|
|
224
|
-
return {};
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
function validateHttpMethod(method) {
|
|
229
|
-
return ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'].includes(method);
|
|
230
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { MediaTypeRenderer } from './OpenAPICodeSample';
|
|
2
|
-
export declare function OpenAPIMediaTypeExamplesSelector(props: {
|
|
3
|
-
method: string;
|
|
4
|
-
path: string;
|
|
5
|
-
renderers: MediaTypeRenderer[];
|
|
6
|
-
selectIcon?: React.ReactNode;
|
|
7
|
-
blockKey?: string;
|
|
8
|
-
}): import("react").JSX.Element;
|
|
9
|
-
export declare function OpenAPIMediaTypeExamplesBody(props: {
|
|
10
|
-
method: string;
|
|
11
|
-
path: string;
|
|
12
|
-
renderers: MediaTypeRenderer[];
|
|
13
|
-
blockKey?: string;
|
|
14
|
-
}): string | number | boolean | Iterable<import("react").ReactNode> | import("react").JSX.Element | null | undefined;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
|
|
4
|
-
import { createStateKey } from './utils';
|
|
5
|
-
export function OpenAPIMediaTypeExamplesSelector(props) {
|
|
6
|
-
var method = props.method, path = props.path, renderers = props.renderers, selectIcon = props.selectIcon, blockKey = props.blockKey;
|
|
7
|
-
if (!renderers[0]) {
|
|
8
|
-
throw new Error('No renderers provided');
|
|
9
|
-
}
|
|
10
|
-
var stateKey = createStateKey('request-body-media-type', blockKey);
|
|
11
|
-
var state = useSelectState(stateKey, renderers[0].mediaType);
|
|
12
|
-
var selected = renderers.find(function (r) { return r.mediaType === state.key; }) || renderers[0];
|
|
13
|
-
return (<div className="openapi-codesample-selectors">
|
|
14
|
-
<MediaTypeSelector selectIcon={selectIcon} stateKey={stateKey} renderers={renderers}/>
|
|
15
|
-
<ExamplesSelector selectIcon={selectIcon} method={method} path={path} renderer={selected}/>
|
|
16
|
-
</div>);
|
|
17
|
-
}
|
|
18
|
-
function MediaTypeSelector(props) {
|
|
19
|
-
var renderers = props.renderers, stateKey = props.stateKey, selectIcon = props.selectIcon;
|
|
20
|
-
if (renderers.length < 2) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
var items = renderers.map(function (renderer) { return ({
|
|
24
|
-
key: renderer.mediaType,
|
|
25
|
-
label: renderer.mediaType,
|
|
26
|
-
}); });
|
|
27
|
-
return (<OpenAPISelect className={clsx('openapi-select')} items={renderers.map(function (renderer) { return ({
|
|
28
|
-
key: renderer.mediaType,
|
|
29
|
-
label: renderer.mediaType,
|
|
30
|
-
}); })} icon={selectIcon} stateKey={stateKey} placement="bottom start">
|
|
31
|
-
{items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
|
|
32
|
-
{item.label}
|
|
33
|
-
</OpenAPISelectItem>); })}
|
|
34
|
-
</OpenAPISelect>);
|
|
35
|
-
}
|
|
36
|
-
function ExamplesSelector(props) {
|
|
37
|
-
var method = props.method, path = props.path, renderer = props.renderer, selectIcon = props.selectIcon;
|
|
38
|
-
if (renderer.examples.length < 2) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
var items = renderer.examples.map(function (example, index) { return ({
|
|
42
|
-
key: index,
|
|
43
|
-
label: example.example.summary || "Example ".concat(index + 1),
|
|
44
|
-
}); });
|
|
45
|
-
return (<OpenAPISelect items={items} icon={selectIcon} stateKey={"media-type-sample-".concat(renderer.mediaType, "-").concat(method, "-").concat(path)} placement="bottom start">
|
|
46
|
-
{items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
|
|
47
|
-
{item.label}
|
|
48
|
-
</OpenAPISelectItem>); })}
|
|
49
|
-
</OpenAPISelect>);
|
|
50
|
-
}
|
|
51
|
-
export function OpenAPIMediaTypeExamplesBody(props) {
|
|
52
|
-
var _a;
|
|
53
|
-
var renderers = props.renderers, method = props.method, path = props.path, blockKey = props.blockKey;
|
|
54
|
-
if (!renderers[0]) {
|
|
55
|
-
throw new Error('No renderers provided');
|
|
56
|
-
}
|
|
57
|
-
var mediaTypeState = useSelectState(createStateKey('request-body-media-type', blockKey), renderers[0].mediaType);
|
|
58
|
-
var selected = (_a = renderers.find(function (r) { return r.mediaType === mediaTypeState.key; })) !== null && _a !== void 0 ? _a : renderers[0];
|
|
59
|
-
if (selected.examples.length === 0) {
|
|
60
|
-
return selected.element;
|
|
61
|
-
}
|
|
62
|
-
return <ExamplesBody method={method} path={path} renderer={selected}/>;
|
|
63
|
-
}
|
|
64
|
-
function ExamplesBody(props) {
|
|
65
|
-
var _a;
|
|
66
|
-
var method = props.method, path = props.path, renderer = props.renderer;
|
|
67
|
-
var exampleState = useSelectState("media-type-sample-".concat(renderer.mediaType, "-").concat(method, "-").concat(path), renderer.mediaType);
|
|
68
|
-
var example = (_a = renderer.examples[Number(exampleState.key)]) !== null && _a !== void 0 ? _a : renderer.examples[0];
|
|
69
|
-
if (!example) {
|
|
70
|
-
throw new Error("No example found for key ".concat(exampleState.key));
|
|
71
|
-
}
|
|
72
|
-
return example.element;
|
|
73
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { OpenAPISelectItem } from './OpenAPISelect';
|
|
2
|
-
import type { OpenAPIClientContext } from './context';
|
|
3
|
-
import type { OpenAPIOperationData } from './types';
|
|
4
|
-
type CodeSampleItem = OpenAPISelectItem & {
|
|
5
|
-
body: React.ReactNode;
|
|
6
|
-
footer?: React.ReactNode;
|
|
7
|
-
};
|
|
8
|
-
export declare function OpenAPICodeSampleBody(props: {
|
|
9
|
-
items: CodeSampleItem[];
|
|
10
|
-
data: OpenAPIOperationData;
|
|
11
|
-
selectIcon?: React.ReactNode;
|
|
12
|
-
context: OpenAPIClientContext;
|
|
13
|
-
}): import("react").JSX.Element | null;
|
|
14
|
-
export {};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
import { useStore } from 'zustand';
|
|
4
|
-
import { OpenAPIPath } from './OpenAPIPath';
|
|
5
|
-
import { OpenAPISelect, OpenAPISelectItem } from './OpenAPISelect';
|
|
6
|
-
import { StaticSection } from './StaticSection';
|
|
7
|
-
import { getOrCreateStoreByKey } from './getOrCreateStoreByKey';
|
|
8
|
-
function useCodeSampleState(initialKey) {
|
|
9
|
-
if (initialKey === void 0) { initialKey = 'default'; }
|
|
10
|
-
var store = useStore(getOrCreateStoreByKey('codesample', initialKey));
|
|
11
|
-
return {
|
|
12
|
-
key: store.key,
|
|
13
|
-
setKey: useCallback(function (key) { return store.setKey(key); }, [store.setKey]),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function OpenAPICodeSampleHeader(props) {
|
|
17
|
-
var data = props.data, items = props.items, selectIcon = props.selectIcon, context = props.context;
|
|
18
|
-
return (<>
|
|
19
|
-
<OpenAPIPath context={context} canCopy={false} withServer={false} data={data}/>
|
|
20
|
-
{items.length > 1 ? (<OpenAPISelect icon={selectIcon} items={items} stateKey="codesample" placement="bottom end">
|
|
21
|
-
{items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
|
|
22
|
-
{item.label}
|
|
23
|
-
</OpenAPISelectItem>); })}
|
|
24
|
-
</OpenAPISelect>) : items[0] ? (<span className="openapi-codesample-label">{items[0].label}</span>) : null}
|
|
25
|
-
</>);
|
|
26
|
-
}
|
|
27
|
-
export function OpenAPICodeSampleBody(props) {
|
|
28
|
-
var _a;
|
|
29
|
-
var items = props.items, data = props.data, selectIcon = props.selectIcon, context = props.context;
|
|
30
|
-
if (!items[0]) {
|
|
31
|
-
throw new Error('No items provided');
|
|
32
|
-
}
|
|
33
|
-
var state = useCodeSampleState((_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
|
|
34
|
-
var selected = items.find(function (item) { return item.key === state.key; }) || items[0];
|
|
35
|
-
if (!selected) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return (<StaticSection header={<OpenAPICodeSampleHeader context={context} selectIcon={selectIcon} data={data} items={items}/>} className="openapi-codesample">
|
|
39
|
-
<div id={selected.key} className="openapi-codesample-panel">
|
|
40
|
-
{selected.body ? selected.body : null}
|
|
41
|
-
{selected.footer ? selected.footer : null}
|
|
42
|
-
</div>
|
|
43
|
-
</StaticSection>);
|
|
44
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type ButtonProps } from 'react-aria-components';
|
|
2
|
-
import type { OpenAPIClientContext } from './context';
|
|
3
|
-
export declare function OpenAPICopyButton(props: ButtonProps & {
|
|
4
|
-
value: string;
|
|
5
|
-
children: React.ReactNode;
|
|
6
|
-
context: OpenAPIClientContext;
|
|
7
|
-
label?: string;
|
|
8
|
-
/**
|
|
9
|
-
* Whether to show a tooltip.
|
|
10
|
-
* @default true
|
|
11
|
-
*/
|
|
12
|
-
withTooltip?: boolean;
|
|
13
|
-
}): import("react").JSX.Element;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { Button, Tooltip, TooltipTrigger } from 'react-aria-components';
|
|
4
|
-
import { t } from './translate';
|
|
5
|
-
export function OpenAPICopyButton(props) {
|
|
6
|
-
var value = props.value, label = props.label, children = props.children, onPress = props.onPress, className = props.className, context = props.context, _a = props.withTooltip, withTooltip = _a === void 0 ? true : _a;
|
|
7
|
-
var _b = useState(false), copied = _b[0], setCopied = _b[1];
|
|
8
|
-
var _c = useState(false), isOpen = _c[0], setIsOpen = _c[1];
|
|
9
|
-
var handleCopy = function () {
|
|
10
|
-
if (!value)
|
|
11
|
-
return;
|
|
12
|
-
navigator.clipboard.writeText(value).then(function () {
|
|
13
|
-
setIsOpen(true);
|
|
14
|
-
setCopied(true);
|
|
15
|
-
setTimeout(function () {
|
|
16
|
-
setCopied(false);
|
|
17
|
-
setIsOpen(false);
|
|
18
|
-
}, 2000);
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
return (<TooltipTrigger isOpen={isOpen} onOpenChange={setIsOpen} isDisabled={!withTooltip} closeDelay={200} delay={200}>
|
|
22
|
-
<Button type="button" preventFocusOnPress onPress={function (e) {
|
|
23
|
-
handleCopy();
|
|
24
|
-
onPress === null || onPress === void 0 ? void 0 : onPress(e);
|
|
25
|
-
}} className={"openapi-copy-button ".concat(className)} {...props}>
|
|
26
|
-
{children}
|
|
27
|
-
</Button>
|
|
28
|
-
|
|
29
|
-
<Tooltip isOpen={isOpen} onOpenChange={setIsOpen} placement="top" offset={4} className="openapi-tooltip">
|
|
30
|
-
{copied
|
|
31
|
-
? t(context.translation, 'copied')
|
|
32
|
-
: label || t(context.translation, 'copy_to_clipboard')}
|
|
33
|
-
</Tooltip>
|
|
34
|
-
</TooltipTrigger>);
|
|
35
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Display an interactive OpenAPI disclosure.
|
|
4
|
-
*/
|
|
5
|
-
export declare function OpenAPIDisclosure(props: {
|
|
6
|
-
icon: React.ReactNode;
|
|
7
|
-
header: React.ReactNode;
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
label: string | ((isExpanded: boolean) => string);
|
|
10
|
-
className?: string;
|
|
11
|
-
}): React.JSX.Element;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
import { Button, Disclosure, DisclosurePanel } from 'react-aria-components';
|
|
5
|
-
/**
|
|
6
|
-
* Display an interactive OpenAPI disclosure.
|
|
7
|
-
*/
|
|
8
|
-
export function OpenAPIDisclosure(props) {
|
|
9
|
-
var icon = props.icon, header = props.header, label = props.label, children = props.children, className = props.className;
|
|
10
|
-
var _a = useState(false), isExpanded = _a[0], setIsExpanded = _a[1];
|
|
11
|
-
return (<Disclosure className={clsx('openapi-disclosure', className)} isExpanded={isExpanded} onExpandedChange={setIsExpanded}>
|
|
12
|
-
<Button slot="trigger" className="openapi-disclosure-trigger" style={function (_a) {
|
|
13
|
-
var isFocusVisible = _a.isFocusVisible;
|
|
14
|
-
return ({
|
|
15
|
-
outline: isFocusVisible
|
|
16
|
-
? '2px solid rgb(var(--primary-color-500) / 0.4)'
|
|
17
|
-
: 'none',
|
|
18
|
-
});
|
|
19
|
-
}}>
|
|
20
|
-
{header}
|
|
21
|
-
<div className="openapi-disclosure-trigger-label">
|
|
22
|
-
<span>{typeof label === 'function' ? label(isExpanded) : label}</span>
|
|
23
|
-
{icon}
|
|
24
|
-
</div>
|
|
25
|
-
</Button>
|
|
26
|
-
<DisclosurePanel className="openapi-disclosure-panel">
|
|
27
|
-
{isExpanded ? children : null}
|
|
28
|
-
</DisclosurePanel>
|
|
29
|
-
</Disclosure>);
|
|
30
|
-
}
|