@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,23 +0,0 @@
1
- import { type DisclosureGroupProps } from 'react-stately';
2
- interface Props {
3
- groups: TDisclosureGroup[];
4
- icon?: React.ReactNode;
5
- /** State key to use with a store */
6
- selectStateKey?: string;
7
- /** Icon to display for the select */
8
- selectIcon?: React.ReactNode;
9
- }
10
- type TDisclosureGroup = {
11
- key: string;
12
- label: string | React.ReactNode;
13
- tabs?: {
14
- key: string;
15
- label: string | React.ReactNode;
16
- body?: React.ReactNode;
17
- }[];
18
- };
19
- /**
20
- * Display an interactive OpenAPI disclosure group.
21
- */
22
- export declare function OpenAPIDisclosureGroup(props: DisclosureGroupProps & Props): import("react").JSX.Element;
23
- export {};
@@ -1,83 +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 { createContext, useContext, useRef } from 'react';
14
- import { mergeProps, useButton, useDisclosure, useFocusRing, useId } from 'react-aria';
15
- import { useDisclosureGroupState, useDisclosureState, } from 'react-stately';
16
- import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
17
- var DisclosureGroupStateContext = createContext(null);
18
- /**
19
- * Display an interactive OpenAPI disclosure group.
20
- */
21
- export function OpenAPIDisclosureGroup(props) {
22
- var icon = props.icon, groups = props.groups, selectStateKey = props.selectStateKey, selectIcon = props.selectIcon;
23
- var state = useDisclosureGroupState(props);
24
- return (<DisclosureGroupStateContext.Provider value={state}>
25
- {groups.map(function (group) { return (<DisclosureItem selectStateKey={selectStateKey} selectIcon={selectIcon} icon={icon} key={group.key} group={group}/>); })}
26
- </DisclosureGroupStateContext.Provider>);
27
- }
28
- function DisclosureItem(props) {
29
- var _a, _b, _c, _d, _e, _f, _g;
30
- var icon = props.icon, group = props.group, selectStateKey = props.selectStateKey, selectIcon = props.selectIcon;
31
- var defaultId = useId();
32
- var id = group.key || defaultId;
33
- var groupState = useContext(DisclosureGroupStateContext);
34
- var isExpanded = (groupState === null || groupState === void 0 ? void 0 : groupState.expandedKeys.has(id)) || false;
35
- var state = useDisclosureState({
36
- isExpanded: isExpanded,
37
- onExpandedChange: function () {
38
- if (groupState) {
39
- groupState.toggleKey(id);
40
- }
41
- },
42
- });
43
- var panelRef = useRef(null);
44
- var triggerRef = useRef(null);
45
- var isDisabled = (groupState === null || groupState === void 0 ? void 0 : groupState.isDisabled) || !((_a = group.tabs) === null || _a === void 0 ? void 0 : _a.length) || false;
46
- var _h = useDisclosure(__assign(__assign({}, props), { isExpanded: isExpanded, isDisabled: isDisabled }), state, panelRef), triggerProps = _h.buttonProps, panelProps = _h.panelProps;
47
- var buttonProps = useButton(triggerProps, triggerRef).buttonProps;
48
- var _j = useFocusRing(), isFocusVisible = _j.isFocusVisible, focusProps = _j.focusProps;
49
- var defaultTab = ((_c = (_b = group.tabs) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.key) || '';
50
- var store = useSelectState(selectStateKey, defaultTab);
51
- var selectedTab = ((_d = group.tabs) === null || _d === void 0 ? void 0 : _d.find(function (tab) { return tab.key === store.key; })) || ((_e = group.tabs) === null || _e === void 0 ? void 0 : _e[0]);
52
- return (<div className="openapi-disclosure-group" aria-expanded={state.isExpanded}>
53
- <div slot="trigger" ref={triggerRef} {...mergeProps(buttonProps, focusProps)} aria-disabled={isDisabled} style={{
54
- outline: isFocusVisible
55
- ? '2px solid rgb(var(--primary-color-500)/0.4)'
56
- : 'none',
57
- }} className="openapi-disclosure-group-trigger">
58
- <div className="openapi-disclosure-group-icon">
59
- {icon || (<svg viewBox="0 0 24 24" className="openapi-disclosure-group-icon">
60
- <path d="m8.25 4.5 7.5 7.5-7.5 7.5"/>
61
- </svg>)}
62
- </div>
63
-
64
- <div className="openapi-disclosure-group-label">
65
- {group.label}
66
-
67
- {group.tabs ? (<div className="openapi-disclosure-group-mediatype" onClick={function (e) { return e.stopPropagation(); }}>
68
- {((_f = group.tabs) === null || _f === void 0 ? void 0 : _f.length) > 1 ? (<OpenAPISelect icon={selectIcon} stateKey={selectStateKey} onSelectionChange={function () {
69
- state.expand();
70
- }} items={group.tabs} placement="bottom end">
71
- {group.tabs.map(function (tab) { return (<OpenAPISelectItem key={tab.key} id={tab.key} value={tab}>
72
- {tab.label}
73
- </OpenAPISelectItem>); })}
74
- </OpenAPISelect>) : ((_g = group.tabs[0]) === null || _g === void 0 ? void 0 : _g.label) ? (<span>{group.tabs[0].label}</span>) : null}
75
- </div>) : null}
76
- </div>
77
- </div>
78
-
79
- {state.isExpanded && selectedTab && (<div className="openapi-disclosure-group-panel" ref={panelRef} {...panelProps}>
80
- {selectedTab.body}
81
- </div>)}
82
- </div>);
83
- }
@@ -1,16 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIContext, OpenAPIUniversalContext } from './context';
3
- /**
4
- * Display an example.
5
- */
6
- export declare function OpenAPIExample(props: {
7
- example: OpenAPIV3.ExampleObject;
8
- context: OpenAPIContext;
9
- syntax: string;
10
- }): string | number | boolean | Iterable<import("react").ReactNode> | import("react").JSX.Element | null | undefined;
11
- /**
12
- * Empty response example.
13
- */
14
- export declare function OpenAPIEmptyExample(props: {
15
- context: OpenAPIUniversalContext;
16
- }): import("react").JSX.Element;
@@ -1,36 +0,0 @@
1
- import { json2xml } from './json2xml';
2
- import { stringifyOpenAPI } from './stringifyOpenAPI';
3
- import { t } from './translate';
4
- /**
5
- * Display an example.
6
- */
7
- export function OpenAPIExample(props) {
8
- var example = props.example, context = props.context, syntax = props.syntax;
9
- var code = stringifyExample({ example: example, xml: syntax === 'xml' });
10
- if (code === null) {
11
- return <OpenAPIEmptyExample context={context}/>;
12
- }
13
- return context.renderCodeBlock({ code: code, syntax: syntax });
14
- }
15
- function stringifyExample(args) {
16
- var example = args.example, xml = args.xml;
17
- if (!example.value) {
18
- return null;
19
- }
20
- if (typeof example.value === 'string') {
21
- return example.value;
22
- }
23
- if (xml) {
24
- return json2xml(example.value);
25
- }
26
- return stringifyOpenAPI(example.value, null, 2);
27
- }
28
- /**
29
- * Empty response example.
30
- */
31
- export function OpenAPIEmptyExample(props) {
32
- var context = props.context;
33
- return (<pre className="openapi-example-empty">
34
- <p>{t(context.translation, 'no_content')}</p>
35
- </pre>);
36
- }
@@ -1,21 +0,0 @@
1
- import type { Key } from 'react-aria';
2
- import { OpenAPISelectItem } from './OpenAPISelect';
3
- import type { OpenAPIClientContext } from './context';
4
- type OpenAPIMediaTypeItem = OpenAPISelectItem & {
5
- body: React.ReactNode;
6
- examples?: OpenAPIMediaTypeItem[];
7
- };
8
- /**
9
- * Get the state of the response examples select.
10
- */
11
- export declare function useMediaTypesState(stateKey: string | undefined, initialKey?: Key): {
12
- key: (string | number) | null;
13
- setKey: (key: Key | null) => void;
14
- };
15
- export declare function OpenAPIMediaTypeContent(props: {
16
- items: OpenAPIMediaTypeItem[];
17
- selectIcon?: React.ReactNode;
18
- stateKey: string;
19
- context: OpenAPIClientContext;
20
- }): import("react").JSX.Element | null;
21
- export {};
@@ -1,61 +0,0 @@
1
- 'use client';
2
- import { OpenAPIEmptyExample } from './OpenAPIExample';
3
- import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
4
- import { StaticSection } from './StaticSection';
5
- /**
6
- * Get the state of the response examples select.
7
- */
8
- export function useMediaTypesState(stateKey, initialKey) {
9
- if (initialKey === void 0) { initialKey = 'default'; }
10
- return useSelectState(stateKey, initialKey);
11
- }
12
- function useMediaTypeExamplesState(stateKey, initialKey) {
13
- if (initialKey === void 0) { initialKey = 'default'; }
14
- return useSelectState(stateKey, initialKey);
15
- }
16
- export function OpenAPIMediaTypeContent(props) {
17
- var _a, _b, _c;
18
- var stateKey = props.stateKey, items = props.items, selectIcon = props.selectIcon, context = props.context;
19
- var state = useMediaTypesState(stateKey, (_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
20
- var examples = (_c = (_b = items.find(function (item) { return item.key === state.key; })) === null || _b === void 0 ? void 0 : _b.examples) !== null && _c !== void 0 ? _c : [];
21
- if (!items.length && !examples.length) {
22
- return null;
23
- }
24
- return (<StaticSection footer={items.length > 1 || examples.length > 1 ? (<OpenAPIMediaTypeFooter items={items} examples={examples} selectIcon={selectIcon} stateKey={stateKey}/>) : null} className="openapi-response-media-types-examples">
25
- <OpenAPIMediaTypeBody context={context} stateKey={stateKey} items={items} examples={examples}/>
26
- </StaticSection>);
27
- }
28
- function OpenAPIMediaTypeFooter(props) {
29
- var items = props.items, examples = props.examples, stateKey = props.stateKey, selectIcon = props.selectIcon;
30
- return (<>
31
- {items.length > 1 && (<OpenAPISelect icon={selectIcon} items={items} stateKey={stateKey} placement="bottom start">
32
- {items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
33
- <span>{item.label}</span>
34
- </OpenAPISelectItem>); })}
35
- </OpenAPISelect>)}
36
-
37
- {examples && examples.length > 1 ? (<OpenAPISelect icon={selectIcon} items={examples} stateKey={"".concat(stateKey, "-examples")} placement="bottom start">
38
- {examples.map(function (example) { return (<OpenAPISelectItem key={example.key} id={example.key} value={example}>
39
- <span>{example.label}</span>
40
- </OpenAPISelectItem>); })}
41
- </OpenAPISelect>) : null}
42
- </>);
43
- }
44
- function OpenAPIMediaTypeBody(props) {
45
- var _a, _b, _c, _d, _e;
46
- var stateKey = props.stateKey, items = props.items, examples = props.examples, context = props.context;
47
- var state = useMediaTypesState(stateKey, (_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
48
- var selectedItem = (_b = items.find(function (item) { return item.key === state.key; })) !== null && _b !== void 0 ? _b : items[0];
49
- var exampleState = useMediaTypeExamplesState("".concat(stateKey, "-examples"), (_d = (_c = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.examples) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.key);
50
- if (!selectedItem) {
51
- return null;
52
- }
53
- if (examples) {
54
- var selectedExample = (_e = examples.find(function (example) { return example.key === exampleState.key; })) !== null && _e !== void 0 ? _e : examples[0];
55
- if (!selectedExample) {
56
- return <OpenAPIEmptyExample context={context}/>;
57
- }
58
- return selectedExample.body;
59
- }
60
- return selectedItem.body;
61
- }
@@ -1,10 +0,0 @@
1
- import { type OpenAPIContextInput } from './context';
2
- import type { OpenAPIOperationData } from './types';
3
- /**
4
- * Display an interactive OpenAPI operation.
5
- */
6
- export declare function OpenAPIOperation(props: {
7
- className?: string;
8
- data: OpenAPIOperationData;
9
- context: OpenAPIContextInput;
10
- }): import("react").JSX.Element;
@@ -1,25 +0,0 @@
1
- import clsx from 'clsx';
2
- import { OpenAPICodeSample } from './OpenAPICodeSample';
3
- import { OpenAPIResponseExample } from './OpenAPIResponseExample';
4
- import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec';
5
- import { OpenAPISummary } from './common/OpenAPISummary';
6
- import { resolveOpenAPIContext } from './context';
7
- /**
8
- * Display an interactive OpenAPI operation.
9
- */
10
- export function OpenAPIOperation(props) {
11
- var className = props.className, data = props.data, contextInput = props.context;
12
- var context = resolveOpenAPIContext(contextInput);
13
- return (<div className={clsx('openapi-operation', className)}>
14
- <OpenAPISummary data={data} context={context}/>
15
- <div className="openapi-columns">
16
- <OpenAPIColumnSpec data={data} context={context}/>
17
- <div className="openapi-column-preview">
18
- <div className="openapi-column-preview-body">
19
- <OpenAPICodeSample data={data} context={context}/>
20
- <OpenAPIResponseExample data={data} context={context}/>
21
- </div>
22
- </div>
23
- </div>
24
- </div>);
25
- }
@@ -1,16 +0,0 @@
1
- interface OpenAPIOperationPointer {
2
- path: string;
3
- method: string;
4
- }
5
- interface OpenAPIOperationContextValue {
6
- onOpenClient: (pointer: OpenAPIOperationPointer) => void;
7
- }
8
- /**
9
- * Provider for the OpenAPIOperationContext.
10
- */
11
- export declare function OpenAPIOperationContextProvider(props: React.PropsWithChildren<Partial<OpenAPIOperationContextValue>>): import("react").JSX.Element;
12
- /**
13
- * Hook to access the OpenAPIOperationContext.
14
- */
15
- export declare function useOpenAPIOperationContext(): OpenAPIOperationContextValue;
16
- export {};
@@ -1,26 +0,0 @@
1
- 'use client';
2
- import { createContext, useContext, useMemo } from 'react';
3
- import { useEventCallback } from 'usehooks-ts';
4
- var OpenAPIOperationContext = createContext({
5
- onOpenClient: function () { },
6
- });
7
- /**
8
- * Provider for the OpenAPIOperationContext.
9
- */
10
- export function OpenAPIOperationContextProvider(props) {
11
- var children = props.children;
12
- var onOpenClient = useEventCallback(function (pointer) {
13
- var _a;
14
- (_a = props.onOpenClient) === null || _a === void 0 ? void 0 : _a.call(props, pointer);
15
- });
16
- var value = useMemo(function () { return ({ onOpenClient: onOpenClient }); }, [onOpenClient]);
17
- return (<OpenAPIOperationContext.Provider value={value}>
18
- {children}
19
- </OpenAPIOperationContext.Provider>);
20
- }
21
- /**
22
- * Hook to access the OpenAPIOperationContext.
23
- */
24
- export function useOpenAPIOperationContext() {
25
- return useContext(OpenAPIOperationContext);
26
- }
@@ -1,9 +0,0 @@
1
- import type { OpenAPICustomOperationProperties, OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIContext } from './context';
3
- /**
4
- * Display the description of an OpenAPI operation.
5
- */
6
- export declare function OpenAPIOperationDescription(props: {
7
- operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
8
- context: OpenAPIContext;
9
- }): import("react").JSX.Element | null;
@@ -1,22 +0,0 @@
1
- import { Markdown } from './Markdown';
2
- import { resolveDescription } from './utils';
3
- /**
4
- * Display the description of an OpenAPI operation.
5
- */
6
- export function OpenAPIOperationDescription(props) {
7
- var operation = props.operation;
8
- if (operation['x-gitbook-description-document']) {
9
- return (<div className="openapi-intro">
10
- {props.context.renderDocument({
11
- document: operation['x-gitbook-description-document'],
12
- })}
13
- </div>);
14
- }
15
- var description = resolveDescription(operation);
16
- if (!description) {
17
- return null;
18
- }
19
- return (<div className="openapi-intro">
20
- <Markdown className="openapi-description" source={description}/>
21
- </div>);
22
- }
@@ -1,9 +0,0 @@
1
- import type { OpenAPIStability } from '@gitbook/openapi-parser';
2
- import type { OpenAPIContext } from './context';
3
- /**
4
- * Display the stability of an OpenAPI operation.
5
- */
6
- export declare function OpenAPIOperationStability(props: {
7
- stability: OpenAPIStability;
8
- context: OpenAPIContext;
9
- }): import("react").JSX.Element | null;
@@ -1,27 +0,0 @@
1
- import { t } from './translate';
2
- /**
3
- * Display the stability of an OpenAPI operation.
4
- */
5
- export function OpenAPIOperationStability(props) {
6
- var stability = props.stability, context = props.context;
7
- var stabilityLabel = getStabilityLabel(stability, context);
8
- if (!stabilityLabel) {
9
- return null;
10
- }
11
- return (<div className={"openapi-stability openapi-stability-".concat(stability)}>{stabilityLabel}</div>);
12
- }
13
- /**
14
- * Get the stability label for the given stability level.
15
- */
16
- function getStabilityLabel(stability, context) {
17
- switch (stability) {
18
- case 'experimental':
19
- return t(context.translation, 'stability_experimental');
20
- case 'alpha':
21
- return t(context.translation, 'stability_alpha');
22
- case 'beta':
23
- return t(context.translation, 'stability_beta');
24
- default:
25
- return null;
26
- }
27
- }
@@ -1,18 +0,0 @@
1
- import { type OpenAPIUniversalContext } from './context';
2
- import type { OpenAPIOperationData } from './types';
3
- /**
4
- * Display the path of an operation.
5
- */
6
- export declare function OpenAPIPath(props: {
7
- data: OpenAPIOperationData;
8
- context: OpenAPIUniversalContext;
9
- /** Whether to show the server URL.
10
- * @default true
11
- */
12
- withServer?: boolean;
13
- /**
14
- * Whether the path is copyable.
15
- * @default true
16
- */
17
- canCopy?: boolean;
18
- }): import("react").JSX.Element;
@@ -1,55 +0,0 @@
1
- import { OpenAPICopyButton } from './OpenAPICopyButton';
2
- import { getOpenAPIClientContext } from './context';
3
- import { getDefaultServerURL } from './util/server';
4
- /**
5
- * Display the path of an operation.
6
- */
7
- export function OpenAPIPath(props) {
8
- var data = props.data, context = props.context, _a = props.withServer, withServer = _a === void 0 ? true : _a, _b = props.canCopy, canCopy = _b === void 0 ? true : _b;
9
- var method = data.method, path = data.path, operation = data.operation;
10
- var server = getDefaultServerURL(data.servers);
11
- var formattedPath = formatPath(path);
12
- var element = (function () {
13
- return (<>
14
- {withServer ? <span className="openapi-path-server">{server}</span> : null}
15
- {formattedPath}
16
- </>);
17
- })();
18
- return (<div className="openapi-path">
19
- <div className={"openapi-method openapi-method-".concat(method)}>{method}</div>
20
-
21
- <OpenAPICopyButton value={"".concat(withServer ? server : '').concat(path)} className="openapi-path-title" data-deprecated={operation.deprecated} isDisabled={!canCopy} context={getOpenAPIClientContext(context)}>
22
- {element}
23
- </OpenAPICopyButton>
24
- </div>);
25
- }
26
- /**
27
- * Format the path by wrapping placeholders in <span> tags.
28
- */
29
- function formatPath(path) {
30
- // Matches placeholders like {id}, {userId}, etc.
31
- var regex = /\{\s*(\w+)\s*\}|:\w+/g;
32
- var parts = [];
33
- var lastIndex = 0;
34
- //Wrap the variables in <span> tags and maintain either {variable} or :variable
35
- path.replace(regex, function (match, _, offset) {
36
- if (offset > lastIndex) {
37
- parts.push(path.slice(lastIndex, offset));
38
- }
39
- parts.push(<span key={"offset-".concat(offset)} className="openapi-path-variable">
40
- {match}
41
- </span>);
42
- lastIndex = offset + match.length;
43
- return match;
44
- });
45
- if (lastIndex < path.length) {
46
- parts.push(path.slice(lastIndex));
47
- }
48
- var formattedPath = parts.map(function (part, index) {
49
- if (typeof part === 'string') {
50
- return <span key={"part-".concat(index)}>{part}</span>;
51
- }
52
- return part;
53
- });
54
- return formattedPath;
55
- }
@@ -1,22 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Prefill data that can be used to dynamically inject info into OpenAPI operation blocks.
4
- *
5
- * This is typically dynamic input context, such as visitor data or environment info.
6
- */
7
- export type PrefillInputContextData = Record<string, unknown>;
8
- /**
9
- * Context value is function that returns prefill data.
10
- */
11
- type PrefillContextValue = () => PrefillInputContextData | null;
12
- /**
13
- * Provide context to help prefill dynamic info like visitor data in OpenAPI blocks.
14
- */
15
- export declare function OpenAPIPrefillContextProvider(props: React.PropsWithChildren<{
16
- getPrefillInputContextData: () => PrefillInputContextData | null;
17
- }>): React.JSX.Element;
18
- /**
19
- * Hook to access the prefill context function.
20
- */
21
- export declare function useOpenAPIPrefillContext(): PrefillContextValue;
22
- export {};
@@ -1,19 +0,0 @@
1
- 'use client';
2
- import * as React from 'react';
3
- var OpenAPIPrefillContext = React.createContext(null);
4
- /**
5
- * Provide context to help prefill dynamic info like visitor data in OpenAPI blocks.
6
- */
7
- export function OpenAPIPrefillContextProvider(props) {
8
- var getPrefillInputContextData = props.getPrefillInputContextData, children = props.children;
9
- return (<OpenAPIPrefillContext.Provider value={getPrefillInputContextData}>
10
- {children}
11
- </OpenAPIPrefillContext.Provider>);
12
- }
13
- /**
14
- * Hook to access the prefill context function.
15
- */
16
- export function useOpenAPIPrefillContext() {
17
- var _a;
18
- return (_a = React.useContext(OpenAPIPrefillContext)) !== null && _a !== void 0 ? _a : (function () { return null; });
19
- }
@@ -1,11 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIClientContext } from './context';
3
- import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
4
- /**
5
- * Display an interactive request body.
6
- */
7
- export declare function OpenAPIRequestBody(props: {
8
- requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
9
- context: OpenAPIClientContext;
10
- data: OpenAPIOperationData | OpenAPIWebhookData;
11
- }): import("react").JSX.Element | null;
@@ -1,28 +0,0 @@
1
- import { InteractiveSection } from './InteractiveSection';
2
- import { OpenAPIRequestBodyHeaderType } from './OpenAPIRequestBodyHeaderType';
3
- import { OpenAPIRootSchema } from './OpenAPISchemaServer';
4
- import { t } from './translate';
5
- import { checkIsReference, createStateKey } from './utils';
6
- /**
7
- * Display an interactive request body.
8
- */
9
- export function OpenAPIRequestBody(props) {
10
- var _a;
11
- var requestBody = props.requestBody, context = props.context, data = props.data;
12
- if (checkIsReference(requestBody)) {
13
- return null;
14
- }
15
- var stateKey = createStateKey('request-body-media-type', context.blockKey);
16
- return (<InteractiveSection header={<>
17
- <span>{t(context.translation, 'name' in data ? 'payload' : 'body')}</span>
18
- <OpenAPIRequestBodyHeaderType requestBody={requestBody} stateKey={stateKey}/>
19
- </>} className="openapi-requestbody" stateKey={stateKey} selectIcon={context.icons.chevronDown} tabs={Object.entries((_a = requestBody.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
20
- var _b;
21
- var contentType = _a[0], mediaTypeObject = _a[1];
22
- return {
23
- key: contentType,
24
- label: contentType,
25
- body: (<OpenAPIRootSchema schema={(_b = mediaTypeObject.schema) !== null && _b !== void 0 ? _b : {}} context={context} key={contentType}/>),
26
- };
27
- })}/>);
28
- }
@@ -1,8 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- /**
3
- * Display the type of a request body. It only displays the type if the selected content is an array.
4
- */
5
- export declare function OpenAPIRequestBodyHeaderType(props: {
6
- requestBody: OpenAPIV3.RequestBodyObject;
7
- stateKey: string;
8
- }): import("react").JSX.Element | null;
@@ -1,25 +0,0 @@
1
- 'use client';
2
- import { useSelectState } from './OpenAPISelect';
3
- import { getSchemaTitle } from './utils';
4
- /**
5
- * Display the type of a request body. It only displays the type if the selected content is an array.
6
- */
7
- export function OpenAPIRequestBodyHeaderType(props) {
8
- var _a, _b, _c;
9
- var requestBody = props.requestBody, stateKey = props.stateKey;
10
- var content = (_a = requestBody.content) !== null && _a !== void 0 ? _a : {};
11
- var state = useSelectState(stateKey, Object.keys(content)[0]);
12
- var selectedContentMediaType = (_b = Object.entries(content).find(function (_a) {
13
- var contentType = _a[0];
14
- return contentType === state.key;
15
- })) === null || _b === void 0 ? void 0 : _b[1];
16
- // If the selected content is not an array, we don't display the type
17
- if (!selectedContentMediaType ||
18
- !((_c = selectedContentMediaType.schema) === null || _c === void 0 ? void 0 : _c.type) ||
19
- selectedContentMediaType.schema.type !== 'array') {
20
- return null;
21
- }
22
- return (<span className="openapi-requestbody-header-type">
23
- {"".concat(getSchemaTitle(selectedContentMediaType.schema))}
24
- </span>);
25
- }
@@ -1,10 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIClientContext } from './context';
3
- /**
4
- * Display an interactive response body.
5
- */
6
- export declare function OpenAPIResponse(props: {
7
- response: OpenAPIV3.ResponseObject;
8
- mediaType: OpenAPIV3.MediaTypeObject | null;
9
- context: OpenAPIClientContext;
10
- }): import("react").JSX.Element | null;