@gitbook/react-openapi 1.1.9 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/InteractiveSection.d.ts +4 -0
  3. package/dist/InteractiveSection.jsx +14 -13
  4. package/dist/OpenAPICodeSample.d.ts +3 -2
  5. package/dist/OpenAPICodeSample.jsx +8 -12
  6. package/dist/OpenAPICodeSampleInteractive.d.ts +3 -0
  7. package/dist/OpenAPICodeSampleInteractive.jsx +37 -49
  8. package/dist/OpenAPICodeSampleSelector.d.ts +14 -0
  9. package/dist/OpenAPICodeSampleSelector.jsx +44 -0
  10. package/dist/OpenAPICopyButton.d.ts +2 -0
  11. package/dist/OpenAPICopyButton.jsx +5 -2
  12. package/dist/OpenAPIDisclosure.d.ts +4 -3
  13. package/dist/OpenAPIDisclosure.jsx +8 -11
  14. package/dist/OpenAPIDisclosureGroup.d.ts +7 -3
  15. package/dist/OpenAPIDisclosureGroup.jsx +18 -18
  16. package/dist/OpenAPIExample.d.ts +16 -0
  17. package/dist/OpenAPIExample.jsx +36 -0
  18. package/dist/OpenAPIMediaType.d.ts +21 -0
  19. package/dist/OpenAPIMediaType.jsx +61 -0
  20. package/dist/OpenAPIOperation.d.ts +3 -2
  21. package/dist/OpenAPIOperation.jsx +9 -72
  22. package/dist/OpenAPIOperationDescription.d.ts +9 -0
  23. package/dist/OpenAPIOperationDescription.jsx +22 -0
  24. package/dist/OpenAPIOperationStability.d.ts +9 -0
  25. package/dist/OpenAPIOperationStability.jsx +27 -0
  26. package/dist/OpenAPIPath.d.ts +12 -2
  27. package/dist/OpenAPIPath.jsx +10 -4
  28. package/dist/OpenAPIRequestBody.d.ts +3 -1
  29. package/dist/OpenAPIRequestBody.jsx +4 -3
  30. package/dist/OpenAPIResponse.d.ts +1 -1
  31. package/dist/OpenAPIResponse.jsx +1 -1
  32. package/dist/OpenAPIResponseExample.d.ts +4 -3
  33. package/dist/OpenAPIResponseExample.jsx +24 -154
  34. package/dist/OpenAPIResponseExampleContent.d.ts +19 -0
  35. package/dist/OpenAPIResponseExampleContent.jsx +57 -0
  36. package/dist/OpenAPIResponses.d.ts +1 -1
  37. package/dist/OpenAPIResponses.jsx +49 -36
  38. package/dist/OpenAPISchema.d.ts +1 -1
  39. package/dist/OpenAPISchema.jsx +121 -20
  40. package/dist/OpenAPISchemaName.d.ts +2 -0
  41. package/dist/OpenAPISchemaName.jsx +21 -17
  42. package/dist/OpenAPISchemaServer.d.ts +1 -1
  43. package/dist/OpenAPISecurities.d.ts +2 -1
  44. package/dist/OpenAPISecurities.jsx +11 -10
  45. package/dist/OpenAPISelect.d.ts +22 -0
  46. package/dist/OpenAPISelect.jsx +43 -0
  47. package/dist/OpenAPISpec.d.ts +3 -2
  48. package/dist/OpenAPISpec.jsx +11 -9
  49. package/dist/OpenAPITabs.jsx +9 -9
  50. package/dist/OpenAPIWebhook.d.ts +10 -0
  51. package/dist/OpenAPIWebhook.jsx +23 -0
  52. package/dist/OpenAPIWebhookExample.d.ts +6 -0
  53. package/dist/OpenAPIWebhookExample.jsx +41 -0
  54. package/dist/ScalarApiButton.d.ts +2 -0
  55. package/dist/ScalarApiButton.jsx +4 -3
  56. package/dist/StaticSection.d.ts +4 -1
  57. package/dist/StaticSection.jsx +13 -4
  58. package/dist/code-samples.js +57 -39
  59. package/dist/common/OpenAPIColumnSpec.d.ts +6 -0
  60. package/dist/common/OpenAPIColumnSpec.jsx +20 -0
  61. package/dist/common/OpenAPIOperationDescription.d.ts +6 -0
  62. package/dist/common/OpenAPIOperationDescription.jsx +19 -0
  63. package/dist/common/OpenAPIStability.d.ts +4 -0
  64. package/dist/common/OpenAPIStability.jsx +15 -0
  65. package/dist/common/OpenAPISummary.d.ts +6 -0
  66. package/dist/common/OpenAPISummary.jsx +30 -0
  67. package/dist/context.d.ts +75 -0
  68. package/dist/context.js +43 -0
  69. package/dist/generateSchemaExample.js +4 -0
  70. package/dist/getOrCreateStoreByKey.d.ts +10 -0
  71. package/dist/getOrCreateStoreByKey.js +19 -0
  72. package/dist/index.d.ts +5 -1
  73. package/dist/index.js +3 -0
  74. package/dist/resolveOpenAPIOperation.js +10 -5
  75. package/dist/resolveOpenAPIWebhook.d.ts +11 -0
  76. package/dist/resolveOpenAPIWebhook.js +127 -0
  77. package/dist/schemas/OpenAPISchemas.d.ts +5 -6
  78. package/dist/schemas/OpenAPISchemas.jsx +52 -49
  79. package/dist/schemas/resolveOpenAPISchemas.d.ts +4 -3
  80. package/dist/schemas/resolveOpenAPISchemas.js +0 -1
  81. package/dist/stringifyOpenAPI.d.ts +1 -1
  82. package/dist/stringifyOpenAPI.js +6 -3
  83. package/dist/translate.d.ts +10 -0
  84. package/dist/translate.jsx +75 -0
  85. package/dist/translations/de.d.ts +37 -0
  86. package/dist/translations/de.js +37 -0
  87. package/dist/translations/en.d.ts +37 -0
  88. package/dist/translations/en.js +37 -0
  89. package/dist/translations/es.d.ts +37 -0
  90. package/dist/translations/es.js +37 -0
  91. package/dist/translations/fr.d.ts +37 -0
  92. package/dist/translations/fr.js +37 -0
  93. package/dist/translations/index.d.ts +341 -0
  94. package/dist/translations/index.js +27 -0
  95. package/dist/translations/ja.d.ts +37 -0
  96. package/dist/translations/ja.js +37 -0
  97. package/dist/translations/nl.d.ts +37 -0
  98. package/dist/translations/nl.js +37 -0
  99. package/dist/translations/no.d.ts +37 -0
  100. package/dist/translations/no.js +37 -0
  101. package/dist/translations/pt-br.d.ts +37 -0
  102. package/dist/translations/pt-br.js +37 -0
  103. package/dist/translations/types.d.ts +5 -0
  104. package/dist/translations/types.js +1 -0
  105. package/dist/translations/zh.d.ts +37 -0
  106. package/dist/translations/zh.js +37 -0
  107. package/dist/tsconfig.build.tsbuildinfo +1 -1
  108. package/dist/types.d.ts +12 -48
  109. package/dist/util/example.d.ts +35 -0
  110. package/dist/util/example.jsx +103 -0
  111. package/dist/utils.d.ts +18 -0
  112. package/dist/utils.js +57 -0
  113. package/package.json +3 -3
  114. package/src/InteractiveSection.tsx +22 -18
  115. package/src/OpenAPICodeSample.tsx +26 -15
  116. package/src/OpenAPICodeSampleInteractive.tsx +67 -70
  117. package/src/OpenAPICodeSampleSelector.tsx +94 -0
  118. package/src/OpenAPICopyButton.tsx +7 -2
  119. package/src/OpenAPIDisclosure.tsx +20 -22
  120. package/src/OpenAPIDisclosureGroup.tsx +40 -22
  121. package/src/OpenAPIExample.tsx +55 -0
  122. package/src/OpenAPIMediaType.tsx +139 -0
  123. package/src/OpenAPIOperation.tsx +11 -104
  124. package/src/OpenAPIOperationDescription.tsx +34 -0
  125. package/src/OpenAPIOperationStability.tsx +39 -0
  126. package/src/OpenAPIPath.tsx +26 -6
  127. package/src/OpenAPIRequestBody.tsx +9 -4
  128. package/src/OpenAPIResponse.tsx +2 -2
  129. package/src/OpenAPIResponseExample.tsx +41 -215
  130. package/src/OpenAPIResponseExampleContent.tsx +123 -0
  131. package/src/OpenAPIResponses.tsx +83 -62
  132. package/src/OpenAPISchema.test.ts +80 -0
  133. package/src/OpenAPISchema.tsx +149 -25
  134. package/src/OpenAPISchemaName.tsx +28 -19
  135. package/src/OpenAPISchemaServer.tsx +1 -1
  136. package/src/OpenAPISecurities.tsx +46 -12
  137. package/src/OpenAPISelect.tsx +96 -0
  138. package/src/OpenAPISpec.tsx +21 -10
  139. package/src/OpenAPITabs.tsx +9 -9
  140. package/src/OpenAPIWebhook.tsx +33 -0
  141. package/src/OpenAPIWebhookExample.tsx +60 -0
  142. package/src/ScalarApiButton.tsx +6 -6
  143. package/src/StaticSection.tsx +37 -5
  144. package/src/code-samples.test.ts +3 -1
  145. package/src/code-samples.ts +67 -54
  146. package/src/common/OpenAPIColumnSpec.tsx +31 -0
  147. package/src/common/OpenAPIOperationDescription.tsx +31 -0
  148. package/src/common/OpenAPIStability.tsx +23 -0
  149. package/src/common/OpenAPISummary.tsx +45 -0
  150. package/src/context.ts +99 -0
  151. package/src/generateSchemaExample.test.ts +1020 -0
  152. package/src/generateSchemaExample.ts +5 -0
  153. package/src/getOrCreateStoreByKey.ts +33 -0
  154. package/src/index.ts +5 -1
  155. package/src/resolveOpenAPIOperation.ts +14 -3
  156. package/src/resolveOpenAPIWebhook.ts +99 -0
  157. package/src/schemas/OpenAPISchemas.tsx +76 -71
  158. package/src/schemas/resolveOpenAPISchemas.ts +4 -5
  159. package/src/stringifyOpenAPI.ts +11 -3
  160. package/src/translate.tsx +80 -0
  161. package/src/translations/de.ts +37 -0
  162. package/src/translations/en.ts +37 -0
  163. package/src/translations/es.ts +37 -0
  164. package/src/translations/fr.ts +37 -0
  165. package/src/translations/index.ts +33 -0
  166. package/src/translations/ja.ts +37 -0
  167. package/src/translations/nl.ts +37 -0
  168. package/src/translations/no.ts +37 -0
  169. package/src/translations/pt-br.ts +37 -0
  170. package/src/translations/types.ts +7 -0
  171. package/src/translations/zh.ts +37 -0
  172. package/src/types.ts +11 -46
  173. package/src/util/example.tsx +129 -0
  174. package/src/utils.ts +67 -0
  175. package/dist/useSyncedTabsGlobalState.d.ts +0 -10
  176. package/dist/useSyncedTabsGlobalState.js +0 -20
  177. package/src/useSyncedTabsGlobalState.ts +0 -35
@@ -0,0 +1,61 @@
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,9 +1,10 @@
1
- import type { OpenAPIContextProps, OpenAPIOperationData } from './types';
1
+ import { type OpenAPIContextInput } from './context';
2
+ import type { OpenAPIOperationData } from './types';
2
3
  /**
3
4
  * Display an interactive OpenAPI operation.
4
5
  */
5
6
  export declare function OpenAPIOperation(props: {
6
7
  className?: string;
7
8
  data: OpenAPIOperationData;
8
- context: OpenAPIContextProps;
9
+ context: OpenAPIContextInput;
9
10
  }): import("react").JSX.Element;
@@ -1,88 +1,25 @@
1
1
  import clsx from 'clsx';
2
- import { Markdown } from './Markdown';
3
2
  import { OpenAPICodeSample } from './OpenAPICodeSample';
4
- import { OpenAPIPath } from './OpenAPIPath';
5
3
  import { OpenAPIResponseExample } from './OpenAPIResponseExample';
6
- import { OpenAPISpec } from './OpenAPISpec';
7
- import { resolveDescription } from './utils';
4
+ import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec';
5
+ import { OpenAPISummary } from './common/OpenAPISummary';
6
+ import { resolveOpenAPIContext } from './context';
8
7
  /**
9
8
  * Display an interactive OpenAPI operation.
10
9
  */
11
10
  export function OpenAPIOperation(props) {
12
- var _a;
13
- var className = props.className, data = props.data, context = props.context;
14
- var operation = data.operation;
15
- var clientContext = {
16
- defaultInteractiveOpened: context.defaultInteractiveOpened,
17
- icons: context.icons,
18
- blockKey: context.blockKey,
19
- };
11
+ var className = props.className, data = props.data, contextInput = props.context;
12
+ var context = resolveOpenAPIContext(contextInput);
20
13
  return (<div className={clsx('openapi-operation', className)}>
21
- <div className="openapi-summary" id={operation.summary ? undefined : context.id}>
22
- {(operation.deprecated || operation['x-stability']) && (<div className="openapi-summary-tags">
23
- {operation.deprecated && (<div className="openapi-deprecated">Deprecated</div>)}
24
- {operation['x-stability'] && (<OpenAPIOperationStability stability={operation['x-stability']}/>)}
25
- </div>)}
26
- {operation.summary
27
- ? context.renderHeading({
28
- deprecated: (_a = operation.deprecated) !== null && _a !== void 0 ? _a : false,
29
- stability: operation['x-stability'],
30
- title: operation.summary,
31
- })
32
- : null}
33
- <OpenAPIPath data={data} context={context}/>
34
- </div>
14
+ <OpenAPISummary data={data} context={context}/>
35
15
  <div className="openapi-columns">
36
- <div className="openapi-column-spec">
37
- {operation['x-deprecated-sunset'] ? (<div className="openapi-deprecated-sunset openapi-description openapi-markdown">
38
- This operation is deprecated and will be sunset on{' '}
39
- <span className="openapi-deprecated-sunset-date">
40
- {operation['x-deprecated-sunset']}
41
- </span>
42
- {'.'}
43
- </div>) : null}
44
- <OpenAPIOperationDescription operation={operation} context={context}/>
45
- <OpenAPISpec data={data} context={clientContext}/>
46
- </div>
16
+ <OpenAPIColumnSpec data={data} context={context}/>
47
17
  <div className="openapi-column-preview">
48
18
  <div className="openapi-column-preview-body">
49
- <OpenAPICodeSample {...props}/>
50
- <OpenAPIResponseExample {...props}/>
19
+ <OpenAPICodeSample data={data} context={context}/>
20
+ <OpenAPIResponseExample data={data} context={context}/>
51
21
  </div>
52
22
  </div>
53
23
  </div>
54
24
  </div>);
55
25
  }
56
- function OpenAPIOperationDescription(props) {
57
- var operation = props.operation;
58
- if (operation['x-gitbook-description-document']) {
59
- return (<div className="openapi-intro">
60
- {props.context.renderDocument({
61
- document: operation['x-gitbook-description-document'],
62
- })}
63
- </div>);
64
- }
65
- var description = resolveDescription(operation);
66
- if (!description) {
67
- return null;
68
- }
69
- return (<div className="openapi-intro">
70
- <Markdown className="openapi-description" source={description}/>
71
- </div>);
72
- }
73
- var stabilityEnum = {
74
- experimental: 'Experimental',
75
- alpha: 'Alpha',
76
- beta: 'Beta',
77
- stable: 'Stable',
78
- };
79
- function OpenAPIOperationStability(props) {
80
- var stability = props.stability;
81
- var foundStability = stabilityEnum[stability];
82
- if (!foundStability) {
83
- return null;
84
- }
85
- return (<div className={"openapi-stability openapi-stability-".concat(foundStability.toLowerCase())}>
86
- {foundStability}
87
- </div>);
88
- }
@@ -0,0 +1,9 @@
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;
@@ -0,0 +1,22 @@
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
+ }
@@ -0,0 +1,9 @@
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;
@@ -0,0 +1,27 @@
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,8 +1,18 @@
1
- import type { OpenAPIContextProps, OpenAPIOperationData } from './types';
1
+ import { type OpenAPIUniversalContext } from './context';
2
+ import type { OpenAPIOperationData } from './types';
2
3
  /**
3
4
  * Display the path of an operation.
4
5
  */
5
6
  export declare function OpenAPIPath(props: {
6
7
  data: OpenAPIOperationData;
7
- context: OpenAPIContextProps;
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;
8
18
  }): import("react").JSX.Element;
@@ -1,19 +1,25 @@
1
1
  import { OpenAPICopyButton } from './OpenAPICopyButton';
2
+ import { getOpenAPIClientContext } from './context';
2
3
  import { getDefaultServerURL } from './util/server';
3
4
  /**
4
5
  * Display the path of an operation.
5
6
  */
6
7
  export function OpenAPIPath(props) {
7
- var data = props.data;
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;
8
9
  var method = data.method, path = data.path, operation = data.operation;
9
10
  var server = getDefaultServerURL(data.servers);
10
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
+ })();
11
18
  return (<div className="openapi-path">
12
19
  <div className={"openapi-method openapi-method-".concat(method)}>{method}</div>
13
20
 
14
- <OpenAPICopyButton value={server + path} className="openapi-path-title" data-deprecated={operation.deprecated}>
15
- <span className="openapi-path-server">{server}</span>
16
- {formattedPath}
21
+ <OpenAPICopyButton value={"".concat(withServer ? server : '').concat(path)} className="openapi-path-title" data-deprecated={operation.deprecated} isDisabled={!canCopy} context={getOpenAPIClientContext(context)}>
22
+ {element}
17
23
  </OpenAPICopyButton>
18
24
  </div>);
19
25
  }
@@ -1,9 +1,11 @@
1
1
  import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIClientContext } from './types';
2
+ import type { OpenAPIClientContext } from './context';
3
+ import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
3
4
  /**
4
5
  * Display an interactive request body.
5
6
  */
6
7
  export declare function OpenAPIRequestBody(props: {
7
8
  requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
8
9
  context: OpenAPIClientContext;
10
+ data: OpenAPIOperationData | OpenAPIWebhookData;
9
11
  }): import("react").JSX.Element | null;
@@ -1,16 +1,17 @@
1
1
  import { InteractiveSection } from './InteractiveSection';
2
2
  import { OpenAPIRootSchema } from './OpenAPISchemaServer';
3
- import { checkIsReference } from './utils';
3
+ import { t } from './translate';
4
+ import { checkIsReference, createStateKey } from './utils';
4
5
  /**
5
6
  * Display an interactive request body.
6
7
  */
7
8
  export function OpenAPIRequestBody(props) {
8
9
  var _a;
9
- var requestBody = props.requestBody, context = props.context;
10
+ var requestBody = props.requestBody, context = props.context, data = props.data;
10
11
  if (checkIsReference(requestBody)) {
11
12
  return null;
12
13
  }
13
- return (<InteractiveSection header="Body" className="openapi-requestbody" tabs={Object.entries((_a = requestBody.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
14
+ return (<InteractiveSection header={t(context.translation, 'name' in data ? 'payload' : 'body')} className="openapi-requestbody" stateKey={createStateKey('request-body-media-type', context.blockKey)} selectIcon={context.icons.chevronDown} tabs={Object.entries((_a = requestBody.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
14
15
  var _b;
15
16
  var contentType = _a[0], mediaTypeObject = _a[1];
16
17
  return {
@@ -1,5 +1,5 @@
1
1
  import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type { OpenAPIClientContext } from './types';
2
+ import type { OpenAPIClientContext } from './context';
3
3
  /**
4
4
  * Display an interactive response body.
5
5
  */
@@ -28,7 +28,7 @@ export function OpenAPIResponse(props) {
28
28
  return null;
29
29
  }
30
30
  return (<div className="openapi-response-body">
31
- {headers.length > 0 ? (<OpenAPIDisclosure context={context} label="Headers">
31
+ {headers.length > 0 ? (<OpenAPIDisclosure icon={context.icons.plus} label="Headers">
32
32
  <OpenAPISchemaProperties properties={headers.map(function (_a) {
33
33
  var name = _a[0], header = _a[1];
34
34
  return parameterToProperty(__assign({ name: name }, header));
@@ -1,8 +1,9 @@
1
- import type { OpenAPIContextProps, OpenAPIOperationData } from './types';
1
+ import { type OpenAPIContext } from './context';
2
+ import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
2
3
  /**
3
4
  * Display an example of the response content.
4
5
  */
5
6
  export declare function OpenAPIResponseExample(props: {
6
- data: OpenAPIOperationData;
7
- context: OpenAPIContextProps;
7
+ data: OpenAPIOperationData | OpenAPIWebhookData;
8
+ context: OpenAPIContext;
8
9
  }): import("react").JSX.Element | null;
@@ -1,10 +1,11 @@
1
1
  import { Markdown } from './Markdown';
2
- import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
3
- import { StaticSection } from './StaticSection';
4
- import { generateSchemaExample } from './generateSchemaExample';
5
- import { json2xml } from './json2xml';
6
- import { stringifyOpenAPI } from './stringifyOpenAPI';
7
- import { checkIsReference, createStateKey, resolveDescription } from './utils';
2
+ import { OpenAPIEmptyExample, OpenAPIExample } from './OpenAPIExample';
3
+ import { OpenAPIMediaTypeContent } from './OpenAPIMediaType';
4
+ import { OpenAPIResponseExampleContent } from './OpenAPIResponseExampleContent';
5
+ import { getOpenAPIClientContext } from './context';
6
+ import { getExampleFromReference, getExamples } from './util/example';
7
+ import { createStateKey, getStatusCodeDefaultLabel } from './utils';
8
+ import { checkIsReference, resolveDescription } from './utils';
8
9
  /**
9
10
  * Display an example of the response content.
10
11
  */
@@ -36,37 +37,34 @@ export function OpenAPIResponseExample(props) {
36
37
  var tabs = responses.map(function (_a) {
37
38
  var key = _a[0], responseObject = _a[1];
38
39
  var description = resolveDescription(responseObject);
40
+ var label = description ? (<Markdown source={description}/>) : (getStatusCodeDefaultLabel(key, context));
39
41
  if (checkIsReference(responseObject)) {
40
42
  return {
41
43
  key: key,
42
- label: key,
43
- body: (<OpenAPIExample example={getExampleFromReference(responseObject)} context={context} syntax="json"/>),
44
- footer: description ? <Markdown source={description}/> : undefined,
44
+ label: label,
45
+ statusCode: key,
46
+ body: (<OpenAPIExample example={getExampleFromReference(responseObject, context)} context={context} syntax="json"/>),
45
47
  };
46
48
  }
47
49
  if (!responseObject.content || Object.keys(responseObject.content).length === 0) {
48
50
  return {
49
51
  key: key,
50
- label: key,
51
- body: <OpenAPIEmptyResponseExample />,
52
- footer: description ? <Markdown source={description}/> : undefined,
52
+ label: label,
53
+ statusCode: key,
54
+ body: <OpenAPIEmptyExample context={context}/>,
53
55
  };
54
56
  }
55
57
  return {
56
58
  key: key,
57
- label: key,
59
+ label: label,
60
+ statusCode: key,
58
61
  body: <OpenAPIResponse context={context} content={responseObject.content}/>,
59
- footer: description ? <Markdown source={description}/> : undefined,
60
62
  };
61
63
  });
62
64
  if (tabs.length === 0) {
63
65
  return null;
64
66
  }
65
- return (<OpenAPITabs stateKey={createStateKey('response-example')} items={tabs}>
66
- <StaticSection header={<OpenAPITabsList />} className="openapi-response-example">
67
- <OpenAPITabsPanels />
68
- </StaticSection>
69
- </OpenAPITabs>);
67
+ return (<OpenAPIResponseExampleContent selectIcon={context.icons.chevronDown} blockKey={context.blockKey} items={tabs}/>);
70
68
  }
71
69
  function OpenAPIResponse(props) {
72
70
  var context = props.context, content = props.content;
@@ -75,146 +73,18 @@ function OpenAPIResponse(props) {
75
73
  if (!firstEntry) {
76
74
  throw new Error('One media type is required');
77
75
  }
78
- if (entries.length === 1) {
79
- var mediaType = firstEntry[0], mediaTypeObject = firstEntry[1];
80
- return (<OpenAPIResponseMediaType context={context} mediaType={mediaType} mediaTypeObject={mediaTypeObject}/>);
81
- }
82
76
  var tabs = entries.map(function (entry) {
83
77
  var mediaType = entry[0], mediaTypeObject = entry[1];
84
78
  return {
85
79
  key: mediaType,
86
80
  label: mediaType,
87
- body: (<OpenAPIResponseMediaType context={context} mediaType={mediaType} mediaTypeObject={mediaTypeObject}/>),
88
- };
89
- });
90
- return (<OpenAPITabs stateKey={createStateKey('response-media-types')} items={tabs}>
91
- <StaticSection header={<OpenAPITabsList />} className="openapi-response-media-types">
92
- <OpenAPITabsPanels />
93
- </StaticSection>
94
- </OpenAPITabs>);
95
- }
96
- function OpenAPIResponseMediaType(props) {
97
- var mediaTypeObject = props.mediaTypeObject, mediaType = props.mediaType;
98
- var examples = getExamplesFromMediaTypeObject({ mediaTypeObject: mediaTypeObject, mediaType: mediaType });
99
- var syntax = getSyntaxFromMediaType(mediaType);
100
- var firstExample = examples[0];
101
- if (!firstExample) {
102
- return <OpenAPIEmptyResponseExample />;
103
- }
104
- if (examples.length === 1) {
105
- return (<OpenAPIExample example={firstExample.example} context={props.context} syntax={syntax}/>);
106
- }
107
- var tabs = examples.map(function (example) {
108
- return {
109
- key: example.key,
110
- label: example.example.summary || example.key,
111
- body: (<OpenAPIExample example={example.example} context={props.context} syntax={syntax}/>),
81
+ body: <></>,
82
+ examples: getExamples({
83
+ mediaTypeObject: mediaTypeObject,
84
+ mediaType: mediaType,
85
+ context: context,
86
+ }),
112
87
  };
113
88
  });
114
- return (<OpenAPITabs stateKey={createStateKey('response-media-type-examples')} items={tabs}>
115
- <StaticSection header={<OpenAPITabsList />} className="openapi-response-media-type-examples">
116
- <OpenAPITabsPanels />
117
- </StaticSection>
118
- </OpenAPITabs>);
119
- }
120
- /**
121
- * Display an example.
122
- */
123
- function OpenAPIExample(props) {
124
- var example = props.example, context = props.context, syntax = props.syntax;
125
- var code = stringifyExample({ example: example, xml: syntax === 'xml' });
126
- if (code === null) {
127
- return <OpenAPIEmptyResponseExample />;
128
- }
129
- return context.renderCodeBlock({ code: code, syntax: syntax });
130
- }
131
- function stringifyExample(args) {
132
- var example = args.example, xml = args.xml;
133
- if (!example.value) {
134
- return null;
135
- }
136
- if (typeof example.value === 'string') {
137
- return example.value;
138
- }
139
- if (xml) {
140
- return json2xml(example.value);
141
- }
142
- return stringifyOpenAPI(example.value, null, 2);
143
- }
144
- /**
145
- * Get the syntax from a media type.
146
- */
147
- function getSyntaxFromMediaType(mediaType) {
148
- if (mediaType.includes('json')) {
149
- return 'json';
150
- }
151
- if (mediaType === 'application/xml') {
152
- return 'xml';
153
- }
154
- return 'text';
155
- }
156
- /**
157
- * Get examples from a media type object.
158
- */
159
- function getExamplesFromMediaTypeObject(args) {
160
- var _a;
161
- var _b, _c;
162
- var mediaTypeObject = args.mediaTypeObject, mediaType = args.mediaType;
163
- if (mediaTypeObject.examples) {
164
- return Object.entries(mediaTypeObject.examples).map(function (_a) {
165
- var key = _a[0], example = _a[1];
166
- return {
167
- key: key,
168
- example: checkIsReference(example) ? getExampleFromReference(example) : example,
169
- };
170
- });
171
- }
172
- if (mediaTypeObject.example) {
173
- return [{ key: 'default', example: { value: mediaTypeObject.example } }];
174
- }
175
- if (mediaTypeObject.schema) {
176
- if (mediaType === 'application/xml') {
177
- // @TODO normally we should use the name of the schema but we don't have it
178
- // fix it when we got the reference name
179
- var root = (_c = (_b = mediaTypeObject.schema.xml) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : 'object';
180
- return [
181
- {
182
- key: 'default',
183
- example: {
184
- value: (_a = {},
185
- _a[root] = generateSchemaExample(mediaTypeObject.schema, {
186
- xml: mediaType === 'application/xml',
187
- mode: 'read',
188
- }),
189
- _a),
190
- },
191
- },
192
- ];
193
- }
194
- return [
195
- {
196
- key: 'default',
197
- example: {
198
- value: generateSchemaExample(mediaTypeObject.schema, {
199
- mode: 'read',
200
- }),
201
- },
202
- },
203
- ];
204
- }
205
- return [];
206
- }
207
- /**
208
- * Empty response example.
209
- */
210
- function OpenAPIEmptyResponseExample() {
211
- return (<pre className="openapi-response-example-empty">
212
- <p>No body</p>
213
- </pre>);
214
- }
215
- /**
216
- * Generate an example from a reference object.
217
- */
218
- function getExampleFromReference(ref) {
219
- return { summary: 'Unresolved reference', value: { $ref: ref.$ref } };
89
+ return (<OpenAPIMediaTypeContent selectIcon={context.icons.chevronDown} stateKey={createStateKey('response-media-types', context.blockKey)} items={tabs} context={getOpenAPIClientContext(context)}/>);
220
90
  }
@@ -0,0 +1,19 @@
1
+ import type { Key } from 'react-aria';
2
+ import { OpenAPISelectItem } from './OpenAPISelect';
3
+ type OpenAPIResponseExampleItem = OpenAPISelectItem & {
4
+ statusCode: string;
5
+ body: React.ReactNode;
6
+ };
7
+ /**
8
+ * Get the state of the response examples select.
9
+ */
10
+ export declare function useResponseExamplesState(blockKey: string | undefined, initialKey?: Key): {
11
+ key: (string | number) | null;
12
+ setKey: (key: Key | null) => void;
13
+ };
14
+ export declare function OpenAPIResponseExampleContent(props: {
15
+ items: OpenAPIResponseExampleItem[];
16
+ blockKey?: string;
17
+ selectIcon?: React.ReactNode;
18
+ }): import("react").JSX.Element;
19
+ export {};