@gitbook/react-openapi 1.4.2 → 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.
Files changed (225) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/index.d.ts +663 -10
  3. package/dist/index.js +3873 -8
  4. package/package.json +11 -7
  5. package/dist/InteractiveSection.d.ts +0 -33
  6. package/dist/InteractiveSection.jsx +0 -61
  7. package/dist/Markdown.d.ts +0 -4
  8. package/dist/Markdown.jsx +0 -5
  9. package/dist/OpenAPICodeSample.d.ts +0 -19
  10. package/dist/OpenAPICodeSample.jsx +0 -230
  11. package/dist/OpenAPICodeSampleInteractive.d.ts +0 -14
  12. package/dist/OpenAPICodeSampleInteractive.jsx +0 -73
  13. package/dist/OpenAPICodeSampleSelector.d.ts +0 -14
  14. package/dist/OpenAPICodeSampleSelector.jsx +0 -44
  15. package/dist/OpenAPICopyButton.d.ts +0 -13
  16. package/dist/OpenAPICopyButton.jsx +0 -35
  17. package/dist/OpenAPIDisclosure.d.ts +0 -11
  18. package/dist/OpenAPIDisclosure.jsx +0 -30
  19. package/dist/OpenAPIDisclosureGroup.d.ts +0 -23
  20. package/dist/OpenAPIDisclosureGroup.jsx +0 -83
  21. package/dist/OpenAPIExample.d.ts +0 -16
  22. package/dist/OpenAPIExample.jsx +0 -36
  23. package/dist/OpenAPIMediaType.d.ts +0 -21
  24. package/dist/OpenAPIMediaType.jsx +0 -61
  25. package/dist/OpenAPIOperation.d.ts +0 -10
  26. package/dist/OpenAPIOperation.jsx +0 -25
  27. package/dist/OpenAPIOperationContext.d.ts +0 -16
  28. package/dist/OpenAPIOperationContext.jsx +0 -26
  29. package/dist/OpenAPIOperationDescription.d.ts +0 -9
  30. package/dist/OpenAPIOperationDescription.jsx +0 -22
  31. package/dist/OpenAPIOperationStability.d.ts +0 -9
  32. package/dist/OpenAPIOperationStability.jsx +0 -27
  33. package/dist/OpenAPIPath.d.ts +0 -18
  34. package/dist/OpenAPIPath.jsx +0 -55
  35. package/dist/OpenAPIPrefillContextProvider.d.ts +0 -22
  36. package/dist/OpenAPIPrefillContextProvider.jsx +0 -19
  37. package/dist/OpenAPIRequestBody.d.ts +0 -11
  38. package/dist/OpenAPIRequestBody.jsx +0 -28
  39. package/dist/OpenAPIRequestBodyHeaderType.d.ts +0 -8
  40. package/dist/OpenAPIRequestBodyHeaderType.jsx +0 -25
  41. package/dist/OpenAPIResponse.d.ts +0 -10
  42. package/dist/OpenAPIResponse.jsx +0 -57
  43. package/dist/OpenAPIResponseExample.d.ts +0 -9
  44. package/dist/OpenAPIResponseExample.jsx +0 -105
  45. package/dist/OpenAPIResponseExampleContent.d.ts +0 -22
  46. package/dist/OpenAPIResponseExampleContent.jsx +0 -60
  47. package/dist/OpenAPIResponses.d.ts +0 -9
  48. package/dist/OpenAPIResponses.jsx +0 -77
  49. package/dist/OpenAPISchema.d.ts +0 -27
  50. package/dist/OpenAPISchema.jsx +0 -400
  51. package/dist/OpenAPISchemaName.d.ts +0 -16
  52. package/dist/OpenAPISchemaName.jsx +0 -43
  53. package/dist/OpenAPISchemaServer.d.ts +0 -12
  54. package/dist/OpenAPISchemaServer.jsx +0 -8
  55. package/dist/OpenAPISecurities.d.ts +0 -9
  56. package/dist/OpenAPISecurities.jsx +0 -114
  57. package/dist/OpenAPISelect.d.ts +0 -22
  58. package/dist/OpenAPISelect.jsx +0 -44
  59. package/dist/OpenAPISpec.d.ts +0 -6
  60. package/dist/OpenAPISpec.jsx +0 -80
  61. package/dist/OpenAPITabs.d.ts +0 -26
  62. package/dist/OpenAPITabs.jsx +0 -109
  63. package/dist/OpenAPIWebhook.d.ts +0 -10
  64. package/dist/OpenAPIWebhook.jsx +0 -23
  65. package/dist/OpenAPIWebhookExample.d.ts +0 -6
  66. package/dist/OpenAPIWebhookExample.jsx +0 -41
  67. package/dist/ScalarApiButton.d.ts +0 -14
  68. package/dist/ScalarApiButton.jsx +0 -81
  69. package/dist/StaticSection.d.ts +0 -13
  70. package/dist/StaticSection.jsx +0 -32
  71. package/dist/code-samples.d.ts +0 -17
  72. package/dist/code-samples.js +0 -427
  73. package/dist/common/OpenAPIColumnSpec.d.ts +0 -6
  74. package/dist/common/OpenAPIColumnSpec.jsx +0 -20
  75. package/dist/common/OpenAPIOperationDescription.d.ts +0 -6
  76. package/dist/common/OpenAPIOperationDescription.jsx +0 -19
  77. package/dist/common/OpenAPIStability.d.ts +0 -4
  78. package/dist/common/OpenAPIStability.jsx +0 -15
  79. package/dist/common/OpenAPISummary.d.ts +0 -6
  80. package/dist/common/OpenAPISummary.jsx +0 -30
  81. package/dist/contentTypeChecks.d.ts +0 -10
  82. package/dist/contentTypeChecks.js +0 -30
  83. package/dist/context.d.ts +0 -75
  84. package/dist/context.js +0 -43
  85. package/dist/decycle.d.ts +0 -2
  86. package/dist/decycle.js +0 -70
  87. package/dist/dereference.d.ts +0 -5
  88. package/dist/dereference.js +0 -68
  89. package/dist/generateSchemaExample.d.ts +0 -45
  90. package/dist/generateSchemaExample.js +0 -342
  91. package/dist/getDisclosureLabel.d.ts +0 -7
  92. package/dist/getDisclosureLabel.js +0 -18
  93. package/dist/getOrCreateStoreByKey.d.ts +0 -10
  94. package/dist/getOrCreateStoreByKey.js +0 -19
  95. package/dist/json2xml.d.ts +0 -4
  96. package/dist/json2xml.js +0 -7
  97. package/dist/resolveOpenAPIOperation.d.ts +0 -11
  98. package/dist/resolveOpenAPIOperation.js +0 -173
  99. package/dist/resolveOpenAPIWebhook.d.ts +0 -11
  100. package/dist/resolveOpenAPIWebhook.js +0 -127
  101. package/dist/schemas/OpenAPISchemaItem.d.ts +0 -7
  102. package/dist/schemas/OpenAPISchemaItem.jsx +0 -16
  103. package/dist/schemas/OpenAPISchemas.d.ts +0 -14
  104. package/dist/schemas/OpenAPISchemas.jsx +0 -59
  105. package/dist/schemas/index.d.ts +0 -2
  106. package/dist/schemas/index.js +0 -2
  107. package/dist/schemas/resolveOpenAPISchemas.d.ts +0 -10
  108. package/dist/schemas/resolveOpenAPISchemas.js +0 -61
  109. package/dist/stringifyOpenAPI.d.ts +0 -4
  110. package/dist/stringifyOpenAPI.js +0 -15
  111. package/dist/translate.d.ts +0 -10
  112. package/dist/translate.jsx +0 -75
  113. package/dist/translations/de.d.ts +0 -43
  114. package/dist/translations/de.js +0 -43
  115. package/dist/translations/en.d.ts +0 -43
  116. package/dist/translations/en.js +0 -43
  117. package/dist/translations/es.d.ts +0 -43
  118. package/dist/translations/es.js +0 -43
  119. package/dist/translations/fr.d.ts +0 -43
  120. package/dist/translations/fr.js +0 -43
  121. package/dist/translations/index.d.ts +0 -395
  122. package/dist/translations/index.js +0 -27
  123. package/dist/translations/ja.d.ts +0 -43
  124. package/dist/translations/ja.js +0 -43
  125. package/dist/translations/nl.d.ts +0 -43
  126. package/dist/translations/nl.js +0 -43
  127. package/dist/translations/no.d.ts +0 -43
  128. package/dist/translations/no.js +0 -43
  129. package/dist/translations/pt-br.d.ts +0 -43
  130. package/dist/translations/pt-br.js +0 -43
  131. package/dist/translations/types.d.ts +0 -5
  132. package/dist/translations/types.js +0 -1
  133. package/dist/translations/zh.d.ts +0 -43
  134. package/dist/translations/zh.js +0 -43
  135. package/dist/tsconfig.build.tsbuildinfo +0 -1
  136. package/dist/types.d.ts +0 -31
  137. package/dist/types.js +0 -1
  138. package/dist/util/example.d.ts +0 -35
  139. package/dist/util/example.jsx +0 -103
  140. package/dist/util/server.d.ts +0 -9
  141. package/dist/util/server.js +0 -44
  142. package/dist/util/tryit-prefill.d.ts +0 -20
  143. package/dist/util/tryit-prefill.js +0 -129
  144. package/dist/utils.d.ts +0 -50
  145. package/dist/utils.js +0 -224
  146. package/src/InteractiveSection.tsx +0 -147
  147. package/src/Markdown.tsx +0 -12
  148. package/src/OpenAPICodeSample.tsx +0 -330
  149. package/src/OpenAPICodeSampleInteractive.tsx +0 -136
  150. package/src/OpenAPICodeSampleSelector.tsx +0 -94
  151. package/src/OpenAPICopyButton.tsx +0 -72
  152. package/src/OpenAPIDisclosure.tsx +0 -46
  153. package/src/OpenAPIDisclosureGroup.tsx +0 -158
  154. package/src/OpenAPIExample.tsx +0 -55
  155. package/src/OpenAPIMediaType.tsx +0 -139
  156. package/src/OpenAPIOperation.tsx +0 -35
  157. package/src/OpenAPIOperationContext.tsx +0 -45
  158. package/src/OpenAPIOperationDescription.tsx +0 -34
  159. package/src/OpenAPIOperationStability.tsx +0 -39
  160. package/src/OpenAPIPath.tsx +0 -90
  161. package/src/OpenAPIPrefillContextProvider.tsx +0 -40
  162. package/src/OpenAPIRequestBody.tsx +0 -54
  163. package/src/OpenAPIRequestBodyHeaderType.tsx +0 -36
  164. package/src/OpenAPIResponse.tsx +0 -82
  165. package/src/OpenAPIResponseExample.tsx +0 -151
  166. package/src/OpenAPIResponseExampleContent.tsx +0 -125
  167. package/src/OpenAPIResponses.tsx +0 -125
  168. package/src/OpenAPISchema.test.ts +0 -172
  169. package/src/OpenAPISchema.tsx +0 -654
  170. package/src/OpenAPISchemaName.tsx +0 -80
  171. package/src/OpenAPISchemaServer.tsx +0 -34
  172. package/src/OpenAPISecurities.tsx +0 -231
  173. package/src/OpenAPISelect.tsx +0 -96
  174. package/src/OpenAPISpec.tsx +0 -138
  175. package/src/OpenAPITabs.tsx +0 -147
  176. package/src/OpenAPIWebhook.tsx +0 -33
  177. package/src/OpenAPIWebhookExample.tsx +0 -60
  178. package/src/ScalarApiButton.tsx +0 -132
  179. package/src/StaticSection.tsx +0 -91
  180. package/src/__snapshots__/json2xml.test.ts.snap +0 -18
  181. package/src/code-samples.test.ts +0 -714
  182. package/src/code-samples.ts +0 -448
  183. package/src/common/OpenAPIColumnSpec.tsx +0 -31
  184. package/src/common/OpenAPIOperationDescription.tsx +0 -31
  185. package/src/common/OpenAPIStability.tsx +0 -23
  186. package/src/common/OpenAPISummary.tsx +0 -45
  187. package/src/contentTypeChecks.ts +0 -39
  188. package/src/context.ts +0 -99
  189. package/src/decycle.ts +0 -68
  190. package/src/dereference.ts +0 -29
  191. package/src/generateSchemaExample.test.ts +0 -1040
  192. package/src/generateSchemaExample.ts +0 -530
  193. package/src/getDisclosureLabel.ts +0 -25
  194. package/src/getOrCreateStoreByKey.ts +0 -33
  195. package/src/index.ts +0 -10
  196. package/src/json2xml.test.ts +0 -46
  197. package/src/json2xml.ts +0 -8
  198. package/src/resolveOpenAPIOperation.test.ts +0 -177
  199. package/src/resolveOpenAPIOperation.ts +0 -151
  200. package/src/resolveOpenAPIWebhook.ts +0 -99
  201. package/src/schemas/OpenAPISchemaItem.tsx +0 -34
  202. package/src/schemas/OpenAPISchemas.tsx +0 -98
  203. package/src/schemas/index.ts +0 -2
  204. package/src/schemas/resolveOpenAPISchemas.test.ts +0 -174
  205. package/src/schemas/resolveOpenAPISchemas.ts +0 -28
  206. package/src/stringifyOpenAPI.ts +0 -25
  207. package/src/translate.tsx +0 -80
  208. package/src/translations/de.ts +0 -43
  209. package/src/translations/en.ts +0 -43
  210. package/src/translations/es.ts +0 -43
  211. package/src/translations/fr.ts +0 -43
  212. package/src/translations/index.ts +0 -33
  213. package/src/translations/ja.ts +0 -43
  214. package/src/translations/nl.ts +0 -43
  215. package/src/translations/no.ts +0 -43
  216. package/src/translations/pt-br.ts +0 -43
  217. package/src/translations/types.ts +0 -7
  218. package/src/translations/zh.ts +0 -43
  219. package/src/types.ts +0 -46
  220. package/src/util/example.tsx +0 -129
  221. package/src/util/server.test.ts +0 -58
  222. package/src/util/server.ts +0 -47
  223. package/src/util/tryit-prefill.test.ts +0 -311
  224. package/src/util/tryit-prefill.ts +0 -160
  225. package/src/utils.ts +0 -255
@@ -1,44 +0,0 @@
1
- 'use client';
2
- import clsx from 'clsx';
3
- import { useCallback } from 'react';
4
- import { Button, ListBox, ListBoxItem, Popover, Select, SelectValue, } from 'react-aria-components';
5
- import { useStore } from 'zustand';
6
- import { getOrCreateStoreByKey } from './getOrCreateStoreByKey';
7
- export function useSelectState(stateKey, initialKey) {
8
- if (stateKey === void 0) { stateKey = 'select-state'; }
9
- if (initialKey === void 0) { initialKey = 'default'; }
10
- var store = useStore(getOrCreateStoreByKey(stateKey, initialKey));
11
- return {
12
- key: store.key,
13
- setKey: useCallback(function (key) { return store.setKey(key); }, [store.setKey]),
14
- };
15
- }
16
- export function OpenAPISelect(props) {
17
- var _a;
18
- var _b = props.icon, icon = _b === void 0 ? '▼' : _b, items = props.items, children = props.children, className = props.className, placement = props.placement, stateKey = props.stateKey, selectedKey = props.selectedKey, onSelectionChange = props.onSelectionChange;
19
- var state = useSelectState(stateKey, (_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
20
- var selected = items.find(function (item) { return item.key === state.key; }) || items[0];
21
- return (<Select aria-label="OpenAPI Select" {...props} selectedKey={selectedKey || (selected === null || selected === void 0 ? void 0 : selected.key)} onSelectionChange={function (key) {
22
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(key);
23
- state.setKey(key);
24
- }} className={clsx('openapi-select', className)}>
25
- <Button>
26
- <SelectValue />
27
- {icon}
28
- </Button>
29
- <Popover placement={placement} className="openapi-select-popover">
30
- <ListBox className="openapi-select-listbox" items={items}>
31
- {children}
32
- </ListBox>
33
- </Popover>
34
- </Select>);
35
- }
36
- export function OpenAPISelectItem(props) {
37
- return (<ListBoxItem {...props} className={function (_a) {
38
- var isFocused = _a.isFocused, isSelected = _a.isSelected;
39
- return clsx('openapi-select-item', {
40
- 'openapi-select-item-focused': isFocused,
41
- 'openapi-select-item-selected': isSelected,
42
- });
43
- }}/>);
44
- }
@@ -1,6 +0,0 @@
1
- import type { OpenAPIClientContext } from './context';
2
- import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
3
- export declare function OpenAPISpec(props: {
4
- data: OpenAPIOperationData | OpenAPIWebhookData;
5
- context: OpenAPIClientContext;
6
- }): import("react").JSX.Element;
@@ -1,80 +0,0 @@
1
- import { OpenAPIRequestBody } from './OpenAPIRequestBody';
2
- import { OpenAPIResponses } from './OpenAPIResponses';
3
- import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
4
- import { OpenAPISecurities } from './OpenAPISecurities';
5
- import { StaticSection } from './StaticSection';
6
- import { tString } from './translate';
7
- import { parameterToProperty } from './utils';
8
- export function OpenAPISpec(props) {
9
- var _a;
10
- var data = props.data, context = props.context;
11
- var operation = data.operation;
12
- var parameters = deduplicateParameters((_a = operation.parameters) !== null && _a !== void 0 ? _a : []);
13
- var parameterGroups = groupParameters(parameters, context);
14
- var securities = 'securities' in data ? data.securities : [];
15
- return (<>
16
- {securities.length > 0 ? (<OpenAPISecurities key="securities" securities={securities} context={context}/>) : null}
17
-
18
- {parameterGroups.map(function (group) {
19
- return (<StaticSection key={"parameter-".concat(group.key)} className="openapi-parameters" header={group.label}>
20
- <OpenAPISchemaProperties properties={group.parameters.map(parameterToProperty)} context={context}/>
21
- </StaticSection>);
22
- })}
23
-
24
- {operation.requestBody ? (<OpenAPIRequestBody key="body" requestBody={operation.requestBody} context={context} data={data}/>) : null}
25
- {operation.responses ? (<OpenAPIResponses key="responses" responses={operation.responses} context={context}/>) : null}
26
- </>);
27
- }
28
- function groupParameters(parameters, context) {
29
- var sorted = ['path', 'query', 'header'];
30
- var groups = [];
31
- parameters
32
- .filter(function (parameter) { return parameter.in; })
33
- .forEach(function (parameter) {
34
- var key = parameter.in;
35
- var label = getParameterGroupName(parameter.in, context);
36
- var group = groups.find(function (group) { return group.key === key; });
37
- if (group) {
38
- group.parameters.push(parameter);
39
- }
40
- else {
41
- groups.push({
42
- key: key,
43
- label: label,
44
- parameters: [parameter],
45
- });
46
- }
47
- });
48
- groups.sort(function (a, b) { return sorted.indexOf(a.key) - sorted.indexOf(b.key); });
49
- return groups;
50
- }
51
- function getParameterGroupName(paramIn, context) {
52
- switch (paramIn) {
53
- case 'path':
54
- return tString(context.translation, 'path_parameters');
55
- case 'query':
56
- return tString(context.translation, 'query_parameters');
57
- case 'header':
58
- return tString(context.translation, 'header_parameters');
59
- default:
60
- return paramIn;
61
- }
62
- }
63
- /** Deduplicate parameters by name and in.
64
- * Some specs have both parameters define at path and operation level.
65
- * We only want to display one of them.
66
- * Parameters can have the wrong type (object instead of array) sometimes, we just return an empty array in that case.
67
- */
68
- function deduplicateParameters(parameters) {
69
- var seen = new Set();
70
- return Array.isArray(parameters)
71
- ? parameters.filter(function (param) {
72
- var key = "".concat(param.name, ":").concat(param.in);
73
- if (seen.has(key)) {
74
- return false;
75
- }
76
- seen.add(key);
77
- return true;
78
- })
79
- : [];
80
- }
@@ -1,26 +0,0 @@
1
- import { type Key, type TabsProps } from 'react-aria-components';
2
- export type TabItem = {
3
- key: Key;
4
- label: string;
5
- body: React.ReactNode;
6
- footer?: React.ReactNode;
7
- };
8
- /**
9
- * The OpenAPI Tabs wrapper component.
10
- */
11
- export declare function OpenAPITabs(props: React.PropsWithChildren<TabsProps & {
12
- items: TabItem[];
13
- stateKey?: string;
14
- }>): import("react").JSX.Element;
15
- /**
16
- * The OpenAPI Tabs list component.
17
- * This component should be used as a child of the OpenAPITabs component.
18
- * It renders the list of tabs.
19
- */
20
- export declare function OpenAPITabsList(): import("react").JSX.Element;
21
- /**
22
- * The OpenAPI Tabs panels component.
23
- * This component should be used as a child of the OpenAPITabs component.
24
- * It renders the content of the selected tab.
25
- */
26
- export declare function OpenAPITabsPanels(): import("react").JSX.Element | null;
@@ -1,109 +0,0 @@
1
- 'use client';
2
- import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
3
- import { Tab, TabList, TabPanel, Tabs } from 'react-aria-components';
4
- import { useEventCallback } from 'usehooks-ts';
5
- import { getOrCreateStoreByKey } from './getOrCreateStoreByKey';
6
- var OpenAPITabsContext = createContext(null);
7
- function useOpenAPITabsContext() {
8
- var context = useContext(OpenAPITabsContext);
9
- if (!context) {
10
- throw new Error('OpenAPITabsContext is missing');
11
- }
12
- return context;
13
- }
14
- /**
15
- * The OpenAPI Tabs wrapper component.
16
- */
17
- export function OpenAPITabs(props) {
18
- var _a, _b;
19
- var children = props.children, items = props.items, stateKey = props.stateKey;
20
- var _c = useState(function () {
21
- var _a, _b;
22
- if (stateKey && typeof window !== 'undefined') {
23
- var store = getOrCreateStoreByKey(stateKey);
24
- var tabKey_1 = store.getState().key;
25
- if (tabKey_1) {
26
- return tabKey_1;
27
- }
28
- }
29
- return (_b = (_a = items[0]) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : null;
30
- }), tabKey = _c[0], setTabKey = _c[1];
31
- var selectTab = useEventCallback(function (key) {
32
- if (!key || key === tabKey) {
33
- return;
34
- }
35
- var tab = items.find(function (item) { return item.key === key; });
36
- if (!tab) {
37
- return;
38
- }
39
- setTabKey(key);
40
- });
41
- var selectedTab = (_b = (_a = items.find(function (item) { return item.key === tabKey; })) !== null && _a !== void 0 ? _a : items[0]) !== null && _b !== void 0 ? _b : null;
42
- var cancelDeferRef = useRef(null);
43
- useEffect(function () {
44
- if (!stateKey) {
45
- return undefined;
46
- }
47
- var store = getOrCreateStoreByKey(stateKey);
48
- return store.subscribe(function (state) {
49
- var _a;
50
- (_a = cancelDeferRef.current) === null || _a === void 0 ? void 0 : _a.call(cancelDeferRef);
51
- cancelDeferRef.current = defer(function () { return selectTab(state.key); });
52
- });
53
- }, [stateKey, selectTab]);
54
- useEffect(function () {
55
- return function () { var _a; return (_a = cancelDeferRef.current) === null || _a === void 0 ? void 0 : _a.call(cancelDeferRef); };
56
- }, []);
57
- var contextValue = useMemo(function () { return ({ items: items, selectedTab: selectedTab }); }, [items, selectedTab]);
58
- return (<OpenAPITabsContext.Provider value={contextValue}>
59
- <Tabs className="openapi-tabs" onSelectionChange={function (tabKey) {
60
- selectTab(tabKey);
61
- if (stateKey) {
62
- var store = getOrCreateStoreByKey(stateKey);
63
- store.setState({ key: tabKey });
64
- }
65
- }} selectedKey={tabKey}>
66
- {children}
67
- </Tabs>
68
- </OpenAPITabsContext.Provider>);
69
- }
70
- var defer = function (fn) {
71
- var id = setTimeout(fn, 0);
72
- return function () { return clearTimeout(id); };
73
- };
74
- /**
75
- * The OpenAPI Tabs list component.
76
- * This component should be used as a child of the OpenAPITabs component.
77
- * It renders the list of tabs.
78
- */
79
- export function OpenAPITabsList() {
80
- var items = useOpenAPITabsContext().items;
81
- return (<TabList className="openapi-tabs-list">
82
- {items.map(function (tab) { return (<Tab key={tab.key} id={tab.key} style={function (_a) {
83
- var isFocusVisible = _a.isFocusVisible;
84
- return ({
85
- outline: isFocusVisible
86
- ? '2px solid rgb(var(--primary-color-500)/0.4)'
87
- : 'none',
88
- });
89
- }} className="openapi-tabs-tab">
90
- {tab.label}
91
- </Tab>); })}
92
- </TabList>);
93
- }
94
- /**
95
- * The OpenAPI Tabs panels component.
96
- * This component should be used as a child of the OpenAPITabs component.
97
- * It renders the content of the selected tab.
98
- */
99
- export function OpenAPITabsPanels() {
100
- var selectedTab = useOpenAPITabsContext().selectedTab;
101
- if (!selectedTab) {
102
- return null;
103
- }
104
- var key = selectedTab.key.toString();
105
- return (<TabPanel id={key} className="openapi-tabs-panel">
106
- <div className="openapi-panel-body">{selectedTab.body}</div>
107
- {selectedTab.footer ? (<div className="openapi-panel-footer">{selectedTab.footer}</div>) : null}
108
- </TabPanel>);
109
- }
@@ -1,10 +0,0 @@
1
- import { type OpenAPIContextInput } from './context';
2
- import type { OpenAPIWebhookData } from './types';
3
- /**
4
- * Display an interactive OpenAPI webhook.
5
- */
6
- export declare function OpenAPIWebhook(props: {
7
- className?: string;
8
- data: OpenAPIWebhookData;
9
- context: OpenAPIContextInput;
10
- }): import("react").JSX.Element;
@@ -1,23 +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 { resolveOpenAPIContext } from './context';
6
- /**
7
- * Display an interactive OpenAPI webhook.
8
- */
9
- export function OpenAPIWebhook(props) {
10
- var className = props.className, data = props.data, contextInput = props.context;
11
- var context = resolveOpenAPIContext(contextInput);
12
- return (<div className={clsx('openapi-webhook', className)}>
13
- <OpenAPISummary data={data} context={context}/>
14
- <div className="openapi-columns">
15
- <OpenAPIColumnSpec data={data} context={context}/>
16
- <div className="openapi-column-preview">
17
- <div className="openapi-column-preview-body">
18
- <OpenAPIWebhookExample data={data} context={context}/>
19
- </div>
20
- </div>
21
- </div>
22
- </div>);
23
- }
@@ -1,6 +0,0 @@
1
- import { type OpenAPIContext } from './context';
2
- import type { OpenAPIWebhookData } from './types';
3
- export declare function OpenAPIWebhookExample(props: {
4
- data: OpenAPIWebhookData;
5
- context: OpenAPIContext;
6
- }): import("react").JSX.Element;
@@ -1,41 +0,0 @@
1
- import { OpenAPIEmptyExample } from './OpenAPIExample';
2
- import { OpenAPIMediaTypeContent } from './OpenAPIMediaType';
3
- import { getOpenAPIClientContext } from './context';
4
- import { getExamples } from './util/example';
5
- import { createStateKey } from './utils';
6
- export function OpenAPIWebhookExample(props) {
7
- var data = props.data, context = props.context;
8
- var operation = data.operation;
9
- var items = (function () {
10
- if (!operation.requestBody) {
11
- return [];
12
- }
13
- return Object.entries(operation.requestBody.content).map(function (_a) {
14
- var key = _a[0], value = _a[1];
15
- var schema = value === null || value === void 0 ? void 0 : value.schema;
16
- if (!schema) {
17
- return {
18
- key: key,
19
- label: key,
20
- body: <OpenAPIEmptyExample context={context}/>,
21
- };
22
- }
23
- return {
24
- key: key,
25
- label: key,
26
- body: <></>,
27
- examples: getExamples({
28
- mediaTypeObject: value,
29
- mediaType: key,
30
- context: context,
31
- }),
32
- };
33
- });
34
- })();
35
- return (<div className="openapi-panel">
36
- <h4 className="openapi-panel-heading">Payload</h4>
37
- <div className="openapi-panel-body">
38
- <OpenAPIMediaTypeContent selectIcon={context.icons.chevronDown} stateKey={createStateKey('request-body-media-type', context.blockKey)} items={items} context={getOpenAPIClientContext(context)}/>
39
- </div>
40
- </div>);
41
- }
@@ -1,14 +0,0 @@
1
- import type { OpenAPIV3_1 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIClientContext } from './context';
3
- import type { OpenAPIOperationData } from './types';
4
- /**
5
- * Button which launches the Scalar API Client
6
- */
7
- export declare function ScalarApiButton(props: {
8
- method: OpenAPIV3_1.HttpMethods;
9
- path: string;
10
- securities: OpenAPIOperationData['securities'];
11
- servers: OpenAPIOperationData['servers'];
12
- specUrl: string;
13
- context: OpenAPIClientContext;
14
- }): import("react").JSX.Element;
@@ -1,81 +0,0 @@
1
- 'use client';
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- import { ApiClientModalProvider, useApiClientModal } from '@scalar/api-client-react';
14
- import { Suspense, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
15
- import { createPortal } from 'react-dom';
16
- import { useOpenAPIOperationContext } from './OpenAPIOperationContext';
17
- import { useOpenAPIPrefillContext } from './OpenAPIPrefillContextProvider';
18
- import { t } from './translate';
19
- import { resolveTryItPrefillForOperation } from './util/tryit-prefill';
20
- /**
21
- * Button which launches the Scalar API Client
22
- */
23
- export function ScalarApiButton(props) {
24
- var method = props.method, path = props.path, securities = props.securities, servers = props.servers, specUrl = props.specUrl, context = props.context;
25
- var _a = useState(false), isOpen = _a[0], setIsOpen = _a[1];
26
- var controllerRef = useRef(null);
27
- return (<div className="scalar scalar-activate">
28
- <button className="scalar-activate-button button" onClick={function () {
29
- var _a, _b;
30
- (_b = (_a = controllerRef.current) === null || _a === void 0 ? void 0 : _a.openClient) === null || _b === void 0 ? void 0 : _b.call(_a);
31
- setIsOpen(true);
32
- }}>
33
- {t(context.translation, 'test_it')}
34
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 12" fill="currentColor">
35
- <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"/>
36
- </svg>
37
- </button>
38
-
39
- {isOpen &&
40
- createPortal(<Suspense fallback={null}>
41
- <ScalarModal controllerRef={controllerRef} method={method} path={path} securities={securities} servers={servers} specUrl={specUrl}/>
42
- </Suspense>, document.body)}
43
- </div>);
44
- }
45
- function ScalarModal(props) {
46
- var method = props.method, path = props.path, securities = props.securities, servers = props.servers, specUrl = props.specUrl, controllerRef = props.controllerRef;
47
- var getPrefillInputContextData = useOpenAPIPrefillContext();
48
- var prefillInputContext = getPrefillInputContextData();
49
- var prefillConfig = resolveTryItPrefillForOperation({
50
- operation: { securities: securities, servers: servers },
51
- prefillInputContext: prefillInputContext,
52
- });
53
- return (<ApiClientModalProvider configuration={__assign({ url: specUrl }, prefillConfig)} initialRequest={{ method: method, path: path }}>
54
- <ScalarModalController method={method} path={path} controllerRef={controllerRef}/>
55
- </ApiClientModalProvider>);
56
- }
57
- function ScalarModalController(props) {
58
- var method = props.method, path = props.path, controllerRef = props.controllerRef;
59
- var client = useApiClientModal();
60
- var openScalarClient = client === null || client === void 0 ? void 0 : client.open;
61
- var trackClientOpening = useOpenAPIOperationContext().onOpenClient;
62
- var openClient = useMemo(function () {
63
- if (openScalarClient) {
64
- return function () {
65
- openScalarClient({
66
- method: method,
67
- path: path,
68
- _source: 'gitbook',
69
- });
70
- trackClientOpening({ method: method, path: path });
71
- };
72
- }
73
- return null;
74
- }, [openScalarClient, method, path, trackClientOpening]);
75
- useImperativeHandle(controllerRef, function () { return ({ openClient: openClient ? function () { return openClient(); } : undefined }); }, [openClient]);
76
- // Open at mount
77
- useEffect(function () {
78
- openClient === null || openClient === void 0 ? void 0 : openClient();
79
- }, [openClient]);
80
- return null;
81
- }
@@ -1,13 +0,0 @@
1
- import { type ComponentPropsWithoutRef } from 'react';
2
- export declare function Section(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
3
- export declare function SectionHeader(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
4
- export declare function SectionHeaderContent(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
5
- export declare const SectionBody: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
6
- export declare function SectionFooter(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
7
- export declare function SectionFooterContent(props: ComponentPropsWithoutRef<'div'>): import("react").JSX.Element;
8
- export declare function StaticSection(props: {
9
- className: string;
10
- header?: React.ReactNode;
11
- children: React.ReactNode;
12
- footer?: React.ReactNode;
13
- }): import("react").JSX.Element;
@@ -1,32 +0,0 @@
1
- import clsx from 'clsx';
2
- import { forwardRef } from 'react';
3
- export function Section(props) {
4
- return <div {...props} className={clsx('openapi-section', props.className)}/>;
5
- }
6
- export function SectionHeader(props) {
7
- return (<div {...props} className={clsx('openapi-section-header', props.className ? "".concat(props.className, "-header") : undefined)}/>);
8
- }
9
- export function SectionHeaderContent(props) {
10
- return (<div {...props} className={clsx('openapi-section-header-content', props.className && "".concat(props.className, "-header-content"))}/>);
11
- }
12
- export var SectionBody = forwardRef(function SectionBody(props, ref) {
13
- return (<div ref={ref} {...props} className={clsx('openapi-section-body', props.className && "".concat(props.className, "-body"))}/>);
14
- });
15
- export function SectionFooter(props) {
16
- return (<div {...props} className={clsx('openapi-section-footer', props.className && "".concat(props.className, "-footer"))}/>);
17
- }
18
- export function SectionFooterContent(props) {
19
- return (<div {...props} className={clsx('openapi-section-footer-content', props.className && "".concat(props.className, "-footer-content"))}/>);
20
- }
21
- export function StaticSection(props) {
22
- var className = props.className, header = props.header, children = props.children, footer = props.footer;
23
- return (<Section className={className}>
24
- {header ? (<SectionHeader className={className}>
25
- <SectionHeaderContent className={className}>{header}</SectionHeaderContent>
26
- </SectionHeader>) : null}
27
- <SectionBody className={className}>{children}</SectionBody>
28
- {footer ? (<SectionFooter className={className}>
29
- <SectionFooterContent className={className}>{footer}</SectionFooterContent>
30
- </SectionFooter>) : null}
31
- </Section>);
32
- }
@@ -1,17 +0,0 @@
1
- export interface CodeSampleInput {
2
- method: string;
3
- url: string;
4
- headers?: Record<string, string>;
5
- body?: any;
6
- }
7
- export interface CodeSampleGenerator {
8
- id: string;
9
- label: string;
10
- syntax: string;
11
- generate: (operation: CodeSampleInput) => string;
12
- }
13
- export declare const codeSampleGenerators: CodeSampleGenerator[];
14
- export declare function parseHostAndPath(url: string): {
15
- host: string | undefined;
16
- path: string;
17
- };