@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/src/OpenAPITabs.tsx
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import { type Key, Tab, TabList, TabPanel, Tabs, type TabsProps } from 'react-aria-components';
|
|
5
|
-
import { useEventCallback } from 'usehooks-ts';
|
|
6
|
-
import { getOrCreateStoreByKey } from './getOrCreateStoreByKey';
|
|
7
|
-
|
|
8
|
-
export type TabItem = {
|
|
9
|
-
key: Key;
|
|
10
|
-
label: string;
|
|
11
|
-
body: React.ReactNode;
|
|
12
|
-
footer?: React.ReactNode;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type OpenAPITabsContextData = {
|
|
16
|
-
items: TabItem[];
|
|
17
|
-
selectedTab: TabItem | null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const OpenAPITabsContext = createContext<OpenAPITabsContextData | null>(null);
|
|
21
|
-
|
|
22
|
-
function useOpenAPITabsContext() {
|
|
23
|
-
const context = useContext(OpenAPITabsContext);
|
|
24
|
-
if (!context) {
|
|
25
|
-
throw new Error('OpenAPITabsContext is missing');
|
|
26
|
-
}
|
|
27
|
-
return context;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The OpenAPI Tabs wrapper component.
|
|
32
|
-
*/
|
|
33
|
-
export function OpenAPITabs(
|
|
34
|
-
props: React.PropsWithChildren<TabsProps & { items: TabItem[]; stateKey?: string }>
|
|
35
|
-
) {
|
|
36
|
-
const { children, items, stateKey } = props;
|
|
37
|
-
const [tabKey, setTabKey] = useState<Key | null>(() => {
|
|
38
|
-
if (stateKey && typeof window !== 'undefined') {
|
|
39
|
-
const store = getOrCreateStoreByKey(stateKey);
|
|
40
|
-
const tabKey = store.getState().key;
|
|
41
|
-
if (tabKey) {
|
|
42
|
-
return tabKey;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return items[0]?.key ?? null;
|
|
46
|
-
});
|
|
47
|
-
const selectTab = useEventCallback((key: Key | null) => {
|
|
48
|
-
if (!key || key === tabKey) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const tab = items.find((item) => item.key === key);
|
|
52
|
-
if (!tab) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
setTabKey(key);
|
|
56
|
-
});
|
|
57
|
-
const selectedTab = items.find((item) => item.key === tabKey) ?? items[0] ?? null;
|
|
58
|
-
const cancelDeferRef = useRef<(() => void) | null>(null);
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (!stateKey) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
const store = getOrCreateStoreByKey(stateKey);
|
|
64
|
-
return store.subscribe((state) => {
|
|
65
|
-
cancelDeferRef.current?.();
|
|
66
|
-
cancelDeferRef.current = defer(() => selectTab(state.key));
|
|
67
|
-
});
|
|
68
|
-
}, [stateKey, selectTab]);
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
return () => cancelDeferRef.current?.();
|
|
71
|
-
}, []);
|
|
72
|
-
const contextValue = useMemo(() => ({ items, selectedTab }), [items, selectedTab]);
|
|
73
|
-
return (
|
|
74
|
-
<OpenAPITabsContext.Provider value={contextValue}>
|
|
75
|
-
<Tabs
|
|
76
|
-
className="openapi-tabs"
|
|
77
|
-
onSelectionChange={(tabKey) => {
|
|
78
|
-
selectTab(tabKey);
|
|
79
|
-
if (stateKey) {
|
|
80
|
-
const store = getOrCreateStoreByKey(stateKey);
|
|
81
|
-
store.setState({ key: tabKey });
|
|
82
|
-
}
|
|
83
|
-
}}
|
|
84
|
-
selectedKey={tabKey}
|
|
85
|
-
>
|
|
86
|
-
{children}
|
|
87
|
-
</Tabs>
|
|
88
|
-
</OpenAPITabsContext.Provider>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const defer = (fn: () => void) => {
|
|
93
|
-
const id = setTimeout(fn, 0);
|
|
94
|
-
return () => clearTimeout(id);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The OpenAPI Tabs list component.
|
|
99
|
-
* This component should be used as a child of the OpenAPITabs component.
|
|
100
|
-
* It renders the list of tabs.
|
|
101
|
-
*/
|
|
102
|
-
export function OpenAPITabsList() {
|
|
103
|
-
const { items } = useOpenAPITabsContext();
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<TabList className="openapi-tabs-list">
|
|
107
|
-
{items.map((tab) => (
|
|
108
|
-
<Tab
|
|
109
|
-
key={tab.key}
|
|
110
|
-
id={tab.key}
|
|
111
|
-
style={({ isFocusVisible }) => ({
|
|
112
|
-
outline: isFocusVisible
|
|
113
|
-
? '2px solid rgb(var(--primary-color-500)/0.4)'
|
|
114
|
-
: 'none',
|
|
115
|
-
})}
|
|
116
|
-
className="openapi-tabs-tab"
|
|
117
|
-
>
|
|
118
|
-
{tab.label}
|
|
119
|
-
</Tab>
|
|
120
|
-
))}
|
|
121
|
-
</TabList>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* The OpenAPI Tabs panels component.
|
|
127
|
-
* This component should be used as a child of the OpenAPITabs component.
|
|
128
|
-
* It renders the content of the selected tab.
|
|
129
|
-
*/
|
|
130
|
-
export function OpenAPITabsPanels() {
|
|
131
|
-
const { selectedTab } = useOpenAPITabsContext();
|
|
132
|
-
|
|
133
|
-
if (!selectedTab) {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const key = selectedTab.key.toString();
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
<TabPanel id={key} className="openapi-tabs-panel">
|
|
141
|
-
<div className="openapi-panel-body">{selectedTab.body}</div>
|
|
142
|
-
{selectedTab.footer ? (
|
|
143
|
-
<div className="openapi-panel-footer">{selectedTab.footer}</div>
|
|
144
|
-
) : null}
|
|
145
|
-
</TabPanel>
|
|
146
|
-
);
|
|
147
|
-
}
|
package/src/OpenAPIWebhook.tsx
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
|
-
import { OpenAPIWebhookExample } from './OpenAPIWebhookExample';
|
|
3
|
-
import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec';
|
|
4
|
-
import { OpenAPISummary } from './common/OpenAPISummary';
|
|
5
|
-
import { type OpenAPIContextInput, resolveOpenAPIContext } from './context';
|
|
6
|
-
import type { OpenAPIWebhookData } from './types';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Display an interactive OpenAPI webhook.
|
|
10
|
-
*/
|
|
11
|
-
export function OpenAPIWebhook(props: {
|
|
12
|
-
className?: string;
|
|
13
|
-
data: OpenAPIWebhookData;
|
|
14
|
-
context: OpenAPIContextInput;
|
|
15
|
-
}) {
|
|
16
|
-
const { className, data, context: contextInput } = props;
|
|
17
|
-
|
|
18
|
-
const context = resolveOpenAPIContext(contextInput);
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<div className={clsx('openapi-webhook', className)}>
|
|
22
|
-
<OpenAPISummary data={data} context={context} />
|
|
23
|
-
<div className="openapi-columns">
|
|
24
|
-
<OpenAPIColumnSpec data={data} context={context} />
|
|
25
|
-
<div className="openapi-column-preview">
|
|
26
|
-
<div className="openapi-column-preview-body">
|
|
27
|
-
<OpenAPIWebhookExample data={data} context={context} />
|
|
28
|
-
</div>
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import { OpenAPIEmptyExample } from './OpenAPIExample';
|
|
3
|
-
import { OpenAPIMediaTypeContent } from './OpenAPIMediaType';
|
|
4
|
-
import { type OpenAPIContext, getOpenAPIClientContext } from './context';
|
|
5
|
-
import type { OpenAPIWebhookData } from './types';
|
|
6
|
-
import { getExamples } from './util/example';
|
|
7
|
-
import { createStateKey } from './utils';
|
|
8
|
-
|
|
9
|
-
export function OpenAPIWebhookExample(props: {
|
|
10
|
-
data: OpenAPIWebhookData;
|
|
11
|
-
context: OpenAPIContext;
|
|
12
|
-
}) {
|
|
13
|
-
const { data, context } = props;
|
|
14
|
-
const { operation } = data;
|
|
15
|
-
|
|
16
|
-
const items = (() => {
|
|
17
|
-
if (!operation.requestBody) {
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return Object.entries(
|
|
22
|
-
operation.requestBody.content as Record<string, OpenAPIV3.MediaTypeObject | null>
|
|
23
|
-
).map(([key, value]) => {
|
|
24
|
-
const schema = value?.schema;
|
|
25
|
-
|
|
26
|
-
if (!schema) {
|
|
27
|
-
return {
|
|
28
|
-
key,
|
|
29
|
-
label: key,
|
|
30
|
-
body: <OpenAPIEmptyExample context={context} />,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
key,
|
|
36
|
-
label: key,
|
|
37
|
-
body: <></>,
|
|
38
|
-
examples: getExamples({
|
|
39
|
-
mediaTypeObject: value,
|
|
40
|
-
mediaType: key,
|
|
41
|
-
context,
|
|
42
|
-
}),
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
})();
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<div className="openapi-panel">
|
|
49
|
-
<h4 className="openapi-panel-heading">Payload</h4>
|
|
50
|
-
<div className="openapi-panel-body">
|
|
51
|
-
<OpenAPIMediaTypeContent
|
|
52
|
-
selectIcon={context.icons.chevronDown}
|
|
53
|
-
stateKey={createStateKey('request-body-media-type', context.blockKey)}
|
|
54
|
-
items={items}
|
|
55
|
-
context={getOpenAPIClientContext(context)}
|
|
56
|
-
/>
|
|
57
|
-
</div>
|
|
58
|
-
</div>
|
|
59
|
-
);
|
|
60
|
-
}
|
package/src/ScalarApiButton.tsx
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { ApiClientModalProvider, useApiClientModal } from '@scalar/api-client-react';
|
|
4
|
-
import { Suspense, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
5
|
-
import { createPortal } from 'react-dom';
|
|
6
|
-
|
|
7
|
-
import type { OpenAPIV3_1 } from '@gitbook/openapi-parser';
|
|
8
|
-
import { useOpenAPIOperationContext } from './OpenAPIOperationContext';
|
|
9
|
-
import { useOpenAPIPrefillContext } from './OpenAPIPrefillContextProvider';
|
|
10
|
-
import type { OpenAPIClientContext } from './context';
|
|
11
|
-
import { t } from './translate';
|
|
12
|
-
import type { OpenAPIOperationData } from './types';
|
|
13
|
-
import { resolveTryItPrefillForOperation } from './util/tryit-prefill';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Button which launches the Scalar API Client
|
|
17
|
-
*/
|
|
18
|
-
export function ScalarApiButton(props: {
|
|
19
|
-
method: OpenAPIV3_1.HttpMethods;
|
|
20
|
-
path: string;
|
|
21
|
-
securities: OpenAPIOperationData['securities'];
|
|
22
|
-
servers: OpenAPIOperationData['servers'];
|
|
23
|
-
specUrl: string;
|
|
24
|
-
context: OpenAPIClientContext;
|
|
25
|
-
}) {
|
|
26
|
-
const { method, path, securities, servers, specUrl, context } = props;
|
|
27
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
28
|
-
const controllerRef = useRef<ScalarModalControllerRef>(null);
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<div className="scalar scalar-activate">
|
|
32
|
-
<button
|
|
33
|
-
className="scalar-activate-button button"
|
|
34
|
-
onClick={() => {
|
|
35
|
-
controllerRef.current?.openClient?.();
|
|
36
|
-
setIsOpen(true);
|
|
37
|
-
}}
|
|
38
|
-
>
|
|
39
|
-
{t(context.translation, 'test_it')}
|
|
40
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 12" fill="currentColor">
|
|
41
|
-
<path
|
|
42
|
-
stroke="currentColor"
|
|
43
|
-
strokeWidth="1.5"
|
|
44
|
-
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"
|
|
45
|
-
/>
|
|
46
|
-
</svg>
|
|
47
|
-
</button>
|
|
48
|
-
|
|
49
|
-
{isOpen &&
|
|
50
|
-
createPortal(
|
|
51
|
-
<Suspense fallback={null}>
|
|
52
|
-
<ScalarModal
|
|
53
|
-
controllerRef={controllerRef}
|
|
54
|
-
method={method}
|
|
55
|
-
path={path}
|
|
56
|
-
securities={securities}
|
|
57
|
-
servers={servers}
|
|
58
|
-
specUrl={specUrl}
|
|
59
|
-
/>
|
|
60
|
-
</Suspense>,
|
|
61
|
-
document.body
|
|
62
|
-
)}
|
|
63
|
-
</div>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function ScalarModal(props: {
|
|
68
|
-
method: OpenAPIV3_1.HttpMethods;
|
|
69
|
-
path: string;
|
|
70
|
-
securities: OpenAPIOperationData['securities'];
|
|
71
|
-
servers: OpenAPIOperationData['servers'];
|
|
72
|
-
specUrl: string;
|
|
73
|
-
controllerRef: React.Ref<ScalarModalControllerRef>;
|
|
74
|
-
}) {
|
|
75
|
-
const { method, path, securities, servers, specUrl, controllerRef } = props;
|
|
76
|
-
|
|
77
|
-
const getPrefillInputContextData = useOpenAPIPrefillContext();
|
|
78
|
-
const prefillInputContext = getPrefillInputContextData();
|
|
79
|
-
|
|
80
|
-
const prefillConfig = resolveTryItPrefillForOperation({
|
|
81
|
-
operation: { securities, servers },
|
|
82
|
-
prefillInputContext,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<ApiClientModalProvider
|
|
87
|
-
configuration={{ url: specUrl, ...prefillConfig }}
|
|
88
|
-
initialRequest={{ method, path }}
|
|
89
|
-
>
|
|
90
|
-
<ScalarModalController method={method} path={path} controllerRef={controllerRef} />
|
|
91
|
-
</ApiClientModalProvider>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
type ScalarModalControllerRef = {
|
|
96
|
-
openClient: (() => void) | undefined;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
function ScalarModalController(props: {
|
|
100
|
-
method: OpenAPIV3_1.HttpMethods;
|
|
101
|
-
path: string;
|
|
102
|
-
controllerRef: React.Ref<ScalarModalControllerRef>;
|
|
103
|
-
}) {
|
|
104
|
-
const { method, path, controllerRef } = props;
|
|
105
|
-
const client = useApiClientModal();
|
|
106
|
-
const openScalarClient = client?.open;
|
|
107
|
-
const { onOpenClient: trackClientOpening } = useOpenAPIOperationContext();
|
|
108
|
-
const openClient = useMemo(() => {
|
|
109
|
-
if (openScalarClient) {
|
|
110
|
-
return () => {
|
|
111
|
-
openScalarClient({
|
|
112
|
-
method,
|
|
113
|
-
path,
|
|
114
|
-
_source: 'gitbook',
|
|
115
|
-
});
|
|
116
|
-
trackClientOpening({ method, path });
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
}, [openScalarClient, method, path, trackClientOpening]);
|
|
121
|
-
useImperativeHandle(
|
|
122
|
-
controllerRef,
|
|
123
|
-
() => ({ openClient: openClient ? () => openClient() : undefined }),
|
|
124
|
-
[openClient]
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
// Open at mount
|
|
128
|
-
useEffect(() => {
|
|
129
|
-
openClient?.();
|
|
130
|
-
}, [openClient]);
|
|
131
|
-
return null;
|
|
132
|
-
}
|
package/src/StaticSection.tsx
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
|
-
import { type ComponentPropsWithoutRef, forwardRef } from 'react';
|
|
3
|
-
|
|
4
|
-
export function Section(props: ComponentPropsWithoutRef<'div'>) {
|
|
5
|
-
return <div {...props} className={clsx('openapi-section', props.className)} />;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function SectionHeader(props: ComponentPropsWithoutRef<'div'>) {
|
|
9
|
-
return (
|
|
10
|
-
<div
|
|
11
|
-
{...props}
|
|
12
|
-
className={clsx(
|
|
13
|
-
'openapi-section-header',
|
|
14
|
-
props.className ? `${props.className}-header` : undefined
|
|
15
|
-
)}
|
|
16
|
-
/>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function SectionHeaderContent(props: ComponentPropsWithoutRef<'div'>) {
|
|
21
|
-
return (
|
|
22
|
-
<div
|
|
23
|
-
{...props}
|
|
24
|
-
className={clsx(
|
|
25
|
-
'openapi-section-header-content',
|
|
26
|
-
props.className && `${props.className}-header-content`
|
|
27
|
-
)}
|
|
28
|
-
/>
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const SectionBody = forwardRef(function SectionBody(
|
|
33
|
-
props: ComponentPropsWithoutRef<'div'>,
|
|
34
|
-
ref: React.ForwardedRef<HTMLDivElement>
|
|
35
|
-
) {
|
|
36
|
-
return (
|
|
37
|
-
<div
|
|
38
|
-
ref={ref}
|
|
39
|
-
{...props}
|
|
40
|
-
className={clsx('openapi-section-body', props.className && `${props.className}-body`)}
|
|
41
|
-
/>
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
export function SectionFooter(props: ComponentPropsWithoutRef<'div'>) {
|
|
46
|
-
return (
|
|
47
|
-
<div
|
|
48
|
-
{...props}
|
|
49
|
-
className={clsx(
|
|
50
|
-
'openapi-section-footer',
|
|
51
|
-
props.className && `${props.className}-footer`
|
|
52
|
-
)}
|
|
53
|
-
/>
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function SectionFooterContent(props: ComponentPropsWithoutRef<'div'>) {
|
|
58
|
-
return (
|
|
59
|
-
<div
|
|
60
|
-
{...props}
|
|
61
|
-
className={clsx(
|
|
62
|
-
'openapi-section-footer-content',
|
|
63
|
-
props.className && `${props.className}-footer-content`
|
|
64
|
-
)}
|
|
65
|
-
/>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function StaticSection(props: {
|
|
70
|
-
className: string;
|
|
71
|
-
header?: React.ReactNode;
|
|
72
|
-
children: React.ReactNode;
|
|
73
|
-
footer?: React.ReactNode;
|
|
74
|
-
}) {
|
|
75
|
-
const { className, header, children, footer } = props;
|
|
76
|
-
return (
|
|
77
|
-
<Section className={className}>
|
|
78
|
-
{header ? (
|
|
79
|
-
<SectionHeader className={className}>
|
|
80
|
-
<SectionHeaderContent className={className}>{header}</SectionHeaderContent>
|
|
81
|
-
</SectionHeader>
|
|
82
|
-
) : null}
|
|
83
|
-
<SectionBody className={className}>{children}</SectionBody>
|
|
84
|
-
{footer ? (
|
|
85
|
-
<SectionFooter className={className}>
|
|
86
|
-
<SectionFooterContent className={className}>{footer}</SectionFooterContent>
|
|
87
|
-
</SectionFooter>
|
|
88
|
-
) : null}
|
|
89
|
-
</Section>
|
|
90
|
-
);
|
|
91
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Bun Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`getUrlFromServerState indents correctly 1`] = `
|
|
4
|
-
"<?xml version="1.0"?>
|
|
5
|
-
<id>10</id>
|
|
6
|
-
<name>doggie</name>
|
|
7
|
-
<category>
|
|
8
|
-
<id>1</id>
|
|
9
|
-
<name>Dogs</name>
|
|
10
|
-
</category>
|
|
11
|
-
<photoUrls>string</photoUrls>
|
|
12
|
-
<tags>
|
|
13
|
-
<id>0</id>
|
|
14
|
-
<name>string</name>
|
|
15
|
-
</tags>
|
|
16
|
-
<status>available</status>
|
|
17
|
-
"
|
|
18
|
-
`;
|