@gitbook/react-openapi 1.4.3 → 1.5.2

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 (263) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/InteractiveSection.js +59 -0
  3. package/dist/Markdown.js +10 -0
  4. package/dist/OpenAPICodeSample.js +219 -0
  5. package/dist/OpenAPICodeSampleInteractive.js +66 -0
  6. package/dist/OpenAPICodeSampleSelector.js +45 -0
  7. package/dist/OpenAPICopyButton.js +39 -0
  8. package/dist/OpenAPIDisclosure.js +30 -0
  9. package/dist/OpenAPIDisclosureGroup.js +75 -0
  10. package/dist/OpenAPIExample.js +41 -0
  11. package/dist/OpenAPIMediaType.js +58 -0
  12. package/dist/OpenAPIOperation.d.ts +12 -7
  13. package/dist/OpenAPIOperation.js +30 -0
  14. package/dist/OpenAPIOperationContext.d.ts +10 -6
  15. package/dist/OpenAPIOperationContext.js +30 -0
  16. package/dist/OpenAPIPath.js +51 -0
  17. package/dist/OpenAPIPrefillContextProvider.d.ts +11 -7
  18. package/dist/OpenAPIPrefillContextProvider.js +25 -0
  19. package/dist/OpenAPIRequestBody.js +28 -0
  20. package/dist/OpenAPIRequestBodyHeaderType.js +23 -0
  21. package/dist/OpenAPIResponse.js +39 -0
  22. package/dist/OpenAPIResponseExample.js +75 -0
  23. package/dist/OpenAPIResponseExampleContent.js +61 -0
  24. package/dist/OpenAPIResponses.js +61 -0
  25. package/dist/OpenAPISchema.js +373 -0
  26. package/dist/OpenAPISchemaName.js +45 -0
  27. package/dist/OpenAPISchemaServer.js +13 -0
  28. package/dist/OpenAPISecurities.js +124 -0
  29. package/dist/OpenAPISelect.js +45 -0
  30. package/dist/OpenAPISpec.js +73 -0
  31. package/dist/OpenAPIWebhook.d.ts +12 -7
  32. package/dist/OpenAPIWebhook.js +28 -0
  33. package/dist/OpenAPIWebhookExample.js +40 -0
  34. package/dist/ScalarApiButton.js +87 -0
  35. package/dist/StaticSection.js +37 -0
  36. package/dist/code-samples.js +267 -419
  37. package/dist/common/OpenAPIColumnSpec.js +23 -0
  38. package/dist/common/OpenAPIOperationDescription.js +18 -0
  39. package/dist/common/OpenAPIStability.js +17 -0
  40. package/dist/common/OpenAPISummary.js +27 -0
  41. package/dist/contentTypeChecks.js +24 -20
  42. package/dist/context.d.ts +68 -72
  43. package/dist/context.js +25 -39
  44. package/dist/decycle.js +39 -68
  45. package/dist/dereference.js +20 -64
  46. package/dist/generateSchemaExample.js +188 -332
  47. package/dist/getDisclosureLabel.js +15 -16
  48. package/dist/getOrCreateStoreByKey.js +20 -17
  49. package/dist/index.d.ts +12 -10
  50. package/dist/index.js +11 -8
  51. package/dist/json2xml.js +10 -5
  52. package/dist/resolveOpenAPIOperation.d.ts +11 -7
  53. package/dist/resolveOpenAPIOperation.js +88 -159
  54. package/dist/resolveOpenAPIWebhook.d.ts +11 -7
  55. package/dist/resolveOpenAPIWebhook.js +41 -116
  56. package/dist/schemas/OpenAPISchemaItem.js +26 -0
  57. package/dist/schemas/OpenAPISchemas.d.ts +16 -11
  58. package/dist/schemas/OpenAPISchemas.js +57 -0
  59. package/dist/schemas/resolveOpenAPISchemas.d.ts +9 -4
  60. package/dist/schemas/resolveOpenAPISchemas.js +15 -59
  61. package/dist/stringifyOpenAPI.js +12 -13
  62. package/dist/translate.js +43 -0
  63. package/dist/translations/de.js +47 -42
  64. package/dist/translations/en.d.ts +46 -42
  65. package/dist/translations/en.js +47 -42
  66. package/dist/translations/es.js +47 -42
  67. package/dist/translations/fr.js +47 -42
  68. package/dist/translations/index.d.ts +404 -391
  69. package/dist/translations/index.js +28 -24
  70. package/dist/translations/ja.js +47 -42
  71. package/dist/translations/nl.js +47 -42
  72. package/dist/translations/no.js +47 -42
  73. package/dist/translations/pt-br.js +47 -42
  74. package/dist/translations/types.d.ts +7 -5
  75. package/dist/translations/zh.js +47 -42
  76. package/dist/types.d.ts +30 -24
  77. package/dist/util/example.js +84 -0
  78. package/dist/util/server.js +32 -38
  79. package/dist/util/tryit-prefill.js +135 -121
  80. package/dist/utils.js +135 -196
  81. package/package.json +18 -11
  82. package/dist/InteractiveSection.d.ts +0 -33
  83. package/dist/InteractiveSection.jsx +0 -61
  84. package/dist/Markdown.d.ts +0 -4
  85. package/dist/Markdown.jsx +0 -5
  86. package/dist/OpenAPICodeSample.d.ts +0 -19
  87. package/dist/OpenAPICodeSample.jsx +0 -230
  88. package/dist/OpenAPICodeSampleInteractive.d.ts +0 -14
  89. package/dist/OpenAPICodeSampleInteractive.jsx +0 -73
  90. package/dist/OpenAPICodeSampleSelector.d.ts +0 -14
  91. package/dist/OpenAPICodeSampleSelector.jsx +0 -44
  92. package/dist/OpenAPICopyButton.d.ts +0 -13
  93. package/dist/OpenAPICopyButton.jsx +0 -35
  94. package/dist/OpenAPIDisclosure.d.ts +0 -11
  95. package/dist/OpenAPIDisclosure.jsx +0 -30
  96. package/dist/OpenAPIDisclosureGroup.d.ts +0 -23
  97. package/dist/OpenAPIDisclosureGroup.jsx +0 -83
  98. package/dist/OpenAPIExample.d.ts +0 -16
  99. package/dist/OpenAPIExample.jsx +0 -36
  100. package/dist/OpenAPIMediaType.d.ts +0 -21
  101. package/dist/OpenAPIMediaType.jsx +0 -61
  102. package/dist/OpenAPIOperation.jsx +0 -25
  103. package/dist/OpenAPIOperationContext.jsx +0 -26
  104. package/dist/OpenAPIOperationDescription.d.ts +0 -9
  105. package/dist/OpenAPIOperationDescription.jsx +0 -22
  106. package/dist/OpenAPIOperationStability.d.ts +0 -9
  107. package/dist/OpenAPIOperationStability.jsx +0 -27
  108. package/dist/OpenAPIPath.d.ts +0 -18
  109. package/dist/OpenAPIPath.jsx +0 -55
  110. package/dist/OpenAPIPrefillContextProvider.jsx +0 -19
  111. package/dist/OpenAPIRequestBody.d.ts +0 -11
  112. package/dist/OpenAPIRequestBody.jsx +0 -28
  113. package/dist/OpenAPIRequestBodyHeaderType.d.ts +0 -8
  114. package/dist/OpenAPIRequestBodyHeaderType.jsx +0 -25
  115. package/dist/OpenAPIResponse.d.ts +0 -10
  116. package/dist/OpenAPIResponse.jsx +0 -57
  117. package/dist/OpenAPIResponseExample.d.ts +0 -9
  118. package/dist/OpenAPIResponseExample.jsx +0 -105
  119. package/dist/OpenAPIResponseExampleContent.d.ts +0 -22
  120. package/dist/OpenAPIResponseExampleContent.jsx +0 -60
  121. package/dist/OpenAPIResponses.d.ts +0 -9
  122. package/dist/OpenAPIResponses.jsx +0 -77
  123. package/dist/OpenAPISchema.d.ts +0 -27
  124. package/dist/OpenAPISchema.jsx +0 -400
  125. package/dist/OpenAPISchemaName.d.ts +0 -16
  126. package/dist/OpenAPISchemaName.jsx +0 -43
  127. package/dist/OpenAPISchemaServer.d.ts +0 -12
  128. package/dist/OpenAPISchemaServer.jsx +0 -8
  129. package/dist/OpenAPISecurities.d.ts +0 -9
  130. package/dist/OpenAPISecurities.jsx +0 -114
  131. package/dist/OpenAPISelect.d.ts +0 -22
  132. package/dist/OpenAPISelect.jsx +0 -44
  133. package/dist/OpenAPISpec.d.ts +0 -6
  134. package/dist/OpenAPISpec.jsx +0 -80
  135. package/dist/OpenAPITabs.d.ts +0 -26
  136. package/dist/OpenAPITabs.jsx +0 -109
  137. package/dist/OpenAPIWebhook.jsx +0 -23
  138. package/dist/OpenAPIWebhookExample.d.ts +0 -6
  139. package/dist/OpenAPIWebhookExample.jsx +0 -41
  140. package/dist/ScalarApiButton.d.ts +0 -14
  141. package/dist/ScalarApiButton.jsx +0 -81
  142. package/dist/StaticSection.d.ts +0 -13
  143. package/dist/StaticSection.jsx +0 -32
  144. package/dist/code-samples.d.ts +0 -17
  145. package/dist/common/OpenAPIColumnSpec.d.ts +0 -6
  146. package/dist/common/OpenAPIColumnSpec.jsx +0 -20
  147. package/dist/common/OpenAPIOperationDescription.d.ts +0 -6
  148. package/dist/common/OpenAPIOperationDescription.jsx +0 -19
  149. package/dist/common/OpenAPIStability.d.ts +0 -4
  150. package/dist/common/OpenAPIStability.jsx +0 -15
  151. package/dist/common/OpenAPISummary.d.ts +0 -6
  152. package/dist/common/OpenAPISummary.jsx +0 -30
  153. package/dist/contentTypeChecks.d.ts +0 -10
  154. package/dist/decycle.d.ts +0 -2
  155. package/dist/dereference.d.ts +0 -5
  156. package/dist/generateSchemaExample.d.ts +0 -45
  157. package/dist/getDisclosureLabel.d.ts +0 -7
  158. package/dist/getOrCreateStoreByKey.d.ts +0 -10
  159. package/dist/json2xml.d.ts +0 -4
  160. package/dist/schemas/OpenAPISchemaItem.d.ts +0 -7
  161. package/dist/schemas/OpenAPISchemaItem.jsx +0 -16
  162. package/dist/schemas/OpenAPISchemas.jsx +0 -59
  163. package/dist/schemas/index.d.ts +0 -2
  164. package/dist/schemas/index.js +0 -2
  165. package/dist/stringifyOpenAPI.d.ts +0 -4
  166. package/dist/translate.d.ts +0 -10
  167. package/dist/translate.jsx +0 -75
  168. package/dist/translations/de.d.ts +0 -43
  169. package/dist/translations/es.d.ts +0 -43
  170. package/dist/translations/fr.d.ts +0 -43
  171. package/dist/translations/ja.d.ts +0 -43
  172. package/dist/translations/nl.d.ts +0 -43
  173. package/dist/translations/no.d.ts +0 -43
  174. package/dist/translations/pt-br.d.ts +0 -43
  175. package/dist/translations/types.js +0 -1
  176. package/dist/translations/zh.d.ts +0 -43
  177. package/dist/tsconfig.build.tsbuildinfo +0 -1
  178. package/dist/types.js +0 -1
  179. package/dist/util/example.d.ts +0 -35
  180. package/dist/util/example.jsx +0 -103
  181. package/dist/util/server.d.ts +0 -9
  182. package/dist/util/tryit-prefill.d.ts +0 -20
  183. package/dist/utils.d.ts +0 -50
  184. package/src/InteractiveSection.tsx +0 -147
  185. package/src/Markdown.tsx +0 -12
  186. package/src/OpenAPICodeSample.tsx +0 -330
  187. package/src/OpenAPICodeSampleInteractive.tsx +0 -136
  188. package/src/OpenAPICodeSampleSelector.tsx +0 -94
  189. package/src/OpenAPICopyButton.tsx +0 -72
  190. package/src/OpenAPIDisclosure.tsx +0 -46
  191. package/src/OpenAPIDisclosureGroup.tsx +0 -158
  192. package/src/OpenAPIExample.tsx +0 -55
  193. package/src/OpenAPIMediaType.tsx +0 -139
  194. package/src/OpenAPIOperation.tsx +0 -35
  195. package/src/OpenAPIOperationContext.tsx +0 -45
  196. package/src/OpenAPIOperationDescription.tsx +0 -34
  197. package/src/OpenAPIOperationStability.tsx +0 -39
  198. package/src/OpenAPIPath.tsx +0 -90
  199. package/src/OpenAPIPrefillContextProvider.tsx +0 -40
  200. package/src/OpenAPIRequestBody.tsx +0 -54
  201. package/src/OpenAPIRequestBodyHeaderType.tsx +0 -36
  202. package/src/OpenAPIResponse.tsx +0 -82
  203. package/src/OpenAPIResponseExample.tsx +0 -151
  204. package/src/OpenAPIResponseExampleContent.tsx +0 -125
  205. package/src/OpenAPIResponses.tsx +0 -125
  206. package/src/OpenAPISchema.test.ts +0 -172
  207. package/src/OpenAPISchema.tsx +0 -654
  208. package/src/OpenAPISchemaName.tsx +0 -80
  209. package/src/OpenAPISchemaServer.tsx +0 -34
  210. package/src/OpenAPISecurities.tsx +0 -231
  211. package/src/OpenAPISelect.tsx +0 -96
  212. package/src/OpenAPISpec.tsx +0 -138
  213. package/src/OpenAPITabs.tsx +0 -147
  214. package/src/OpenAPIWebhook.tsx +0 -33
  215. package/src/OpenAPIWebhookExample.tsx +0 -60
  216. package/src/ScalarApiButton.tsx +0 -132
  217. package/src/StaticSection.tsx +0 -91
  218. package/src/__snapshots__/json2xml.test.ts.snap +0 -18
  219. package/src/code-samples.test.ts +0 -714
  220. package/src/code-samples.ts +0 -448
  221. package/src/common/OpenAPIColumnSpec.tsx +0 -31
  222. package/src/common/OpenAPIOperationDescription.tsx +0 -31
  223. package/src/common/OpenAPIStability.tsx +0 -23
  224. package/src/common/OpenAPISummary.tsx +0 -45
  225. package/src/contentTypeChecks.ts +0 -39
  226. package/src/context.ts +0 -99
  227. package/src/decycle.ts +0 -68
  228. package/src/dereference.ts +0 -29
  229. package/src/generateSchemaExample.test.ts +0 -1040
  230. package/src/generateSchemaExample.ts +0 -530
  231. package/src/getDisclosureLabel.ts +0 -25
  232. package/src/getOrCreateStoreByKey.ts +0 -33
  233. package/src/index.ts +0 -10
  234. package/src/json2xml.test.ts +0 -46
  235. package/src/json2xml.ts +0 -8
  236. package/src/resolveOpenAPIOperation.test.ts +0 -177
  237. package/src/resolveOpenAPIOperation.ts +0 -151
  238. package/src/resolveOpenAPIWebhook.ts +0 -99
  239. package/src/schemas/OpenAPISchemaItem.tsx +0 -34
  240. package/src/schemas/OpenAPISchemas.tsx +0 -98
  241. package/src/schemas/index.ts +0 -2
  242. package/src/schemas/resolveOpenAPISchemas.test.ts +0 -174
  243. package/src/schemas/resolveOpenAPISchemas.ts +0 -28
  244. package/src/stringifyOpenAPI.ts +0 -25
  245. package/src/translate.tsx +0 -80
  246. package/src/translations/de.ts +0 -43
  247. package/src/translations/en.ts +0 -43
  248. package/src/translations/es.ts +0 -43
  249. package/src/translations/fr.ts +0 -43
  250. package/src/translations/index.ts +0 -33
  251. package/src/translations/ja.ts +0 -43
  252. package/src/translations/nl.ts +0 -43
  253. package/src/translations/no.ts +0 -43
  254. package/src/translations/pt-br.ts +0 -43
  255. package/src/translations/types.ts +0 -7
  256. package/src/translations/zh.ts +0 -43
  257. package/src/types.ts +0 -46
  258. package/src/util/example.tsx +0 -129
  259. package/src/util/server.test.ts +0 -58
  260. package/src/util/server.ts +0 -47
  261. package/src/util/tryit-prefill.test.ts +0 -311
  262. package/src/util/tryit-prefill.ts +0 -160
  263. package/src/utils.ts +0 -255
@@ -1,35 +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 { type OpenAPIContextInput, resolveOpenAPIContext } from './context';
7
- import type { OpenAPIOperationData } from './types';
8
-
9
- /**
10
- * Display an interactive OpenAPI operation.
11
- */
12
- export function OpenAPIOperation(props: {
13
- className?: string;
14
- data: OpenAPIOperationData;
15
- context: OpenAPIContextInput;
16
- }) {
17
- const { className, data, context: contextInput } = props;
18
-
19
- const context = resolveOpenAPIContext(contextInput);
20
-
21
- return (
22
- <div className={clsx('openapi-operation', className)}>
23
- <OpenAPISummary data={data} context={context} />
24
- <div className="openapi-columns">
25
- <OpenAPIColumnSpec data={data} context={context} />
26
- <div className="openapi-column-preview">
27
- <div className="openapi-column-preview-body">
28
- <OpenAPICodeSample data={data} context={context} />
29
- <OpenAPIResponseExample data={data} context={context} />
30
- </div>
31
- </div>
32
- </div>
33
- </div>
34
- );
35
- }
@@ -1,45 +0,0 @@
1
- 'use client';
2
-
3
- import { createContext, useContext, useMemo } from 'react';
4
- import { useEventCallback } from 'usehooks-ts';
5
-
6
- interface OpenAPIOperationPointer {
7
- path: string;
8
- method: string;
9
- }
10
-
11
- interface OpenAPIOperationContextValue {
12
- onOpenClient: (pointer: OpenAPIOperationPointer) => void;
13
- }
14
-
15
- const OpenAPIOperationContext = createContext<OpenAPIOperationContextValue>({
16
- onOpenClient: () => {},
17
- });
18
-
19
- /**
20
- * Provider for the OpenAPIOperationContext.
21
- */
22
- export function OpenAPIOperationContextProvider(
23
- props: React.PropsWithChildren<Partial<OpenAPIOperationContextValue>>
24
- ) {
25
- const { children } = props;
26
-
27
- const onOpenClient = useEventCallback((pointer: OpenAPIOperationPointer) => {
28
- props.onOpenClient?.(pointer);
29
- });
30
-
31
- const value = useMemo(() => ({ onOpenClient }), [onOpenClient]);
32
-
33
- return (
34
- <OpenAPIOperationContext.Provider value={value}>
35
- {children}
36
- </OpenAPIOperationContext.Provider>
37
- );
38
- }
39
-
40
- /**
41
- * Hook to access the OpenAPIOperationContext.
42
- */
43
- export function useOpenAPIOperationContext() {
44
- return useContext(OpenAPIOperationContext);
45
- }
@@ -1,34 +0,0 @@
1
- import type { OpenAPICustomOperationProperties, OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import { Markdown } from './Markdown';
3
- import type { OpenAPIContext } from './context';
4
- import { resolveDescription } from './utils';
5
-
6
- /**
7
- * Display the description of an OpenAPI operation.
8
- */
9
- export function OpenAPIOperationDescription(props: {
10
- operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
11
- context: OpenAPIContext;
12
- }) {
13
- const { operation } = props;
14
- if (operation['x-gitbook-description-document']) {
15
- return (
16
- <div className="openapi-intro">
17
- {props.context.renderDocument({
18
- document: operation['x-gitbook-description-document'],
19
- })}
20
- </div>
21
- );
22
- }
23
-
24
- const description = resolveDescription(operation);
25
- if (!description) {
26
- return null;
27
- }
28
-
29
- return (
30
- <div className="openapi-intro">
31
- <Markdown className="openapi-description" source={description} />
32
- </div>
33
- );
34
- }
@@ -1,39 +0,0 @@
1
- import type { OpenAPIStability } from '@gitbook/openapi-parser';
2
- import type { OpenAPIContext } from './context';
3
- import { t } from './translate';
4
-
5
- /**
6
- * Display the stability of an OpenAPI operation.
7
- */
8
- export function OpenAPIOperationStability(props: {
9
- stability: OpenAPIStability;
10
- context: OpenAPIContext;
11
- }) {
12
- const { stability, context } = props;
13
-
14
- const stabilityLabel = getStabilityLabel(stability, context);
15
-
16
- if (!stabilityLabel) {
17
- return null;
18
- }
19
-
20
- return (
21
- <div className={`openapi-stability openapi-stability-${stability}`}>{stabilityLabel}</div>
22
- );
23
- }
24
-
25
- /**
26
- * Get the stability label for the given stability level.
27
- */
28
- function getStabilityLabel(stability: OpenAPIStability, context: OpenAPIContext) {
29
- switch (stability) {
30
- case 'experimental':
31
- return t(context.translation, 'stability_experimental');
32
- case 'alpha':
33
- return t(context.translation, 'stability_alpha');
34
- case 'beta':
35
- return t(context.translation, 'stability_beta');
36
- default:
37
- return null;
38
- }
39
- }
@@ -1,90 +0,0 @@
1
- import { OpenAPICopyButton } from './OpenAPICopyButton';
2
- import { type OpenAPIUniversalContext, getOpenAPIClientContext } from './context';
3
- import type { OpenAPIOperationData } from './types';
4
- import { getDefaultServerURL } from './util/server';
5
-
6
- /**
7
- * Display the path of an operation.
8
- */
9
- export function OpenAPIPath(props: {
10
- data: OpenAPIOperationData;
11
- context: OpenAPIUniversalContext;
12
- /** Whether to show the server URL.
13
- * @default true
14
- */
15
- withServer?: boolean;
16
- /**
17
- * Whether the path is copyable.
18
- * @default true
19
- */
20
- canCopy?: boolean;
21
- }) {
22
- const { data, context, withServer = true, canCopy = true } = props;
23
- const { method, path, operation } = data;
24
-
25
- const server = getDefaultServerURL(data.servers);
26
- const formattedPath = formatPath(path);
27
-
28
- const element = (() => {
29
- return (
30
- <>
31
- {withServer ? <span className="openapi-path-server">{server}</span> : null}
32
- {formattedPath}
33
- </>
34
- );
35
- })();
36
-
37
- return (
38
- <div className="openapi-path">
39
- <div className={`openapi-method openapi-method-${method}`}>{method}</div>
40
-
41
- <OpenAPICopyButton
42
- value={`${withServer ? server : ''}${path}`}
43
- className="openapi-path-title"
44
- data-deprecated={operation.deprecated}
45
- isDisabled={!canCopy}
46
- context={getOpenAPIClientContext(context)}
47
- >
48
- {element}
49
- </OpenAPICopyButton>
50
- </div>
51
- );
52
- }
53
-
54
- /**
55
- * Format the path by wrapping placeholders in <span> tags.
56
- */
57
- function formatPath(path: string) {
58
- // Matches placeholders like {id}, {userId}, etc.
59
- const regex = /\{\s*(\w+)\s*\}|:\w+/g;
60
-
61
- const parts: (string | React.JSX.Element)[] = [];
62
- let lastIndex = 0;
63
-
64
- //Wrap the variables in <span> tags and maintain either {variable} or :variable
65
- path.replace(regex, (match, _, offset) => {
66
- if (offset > lastIndex) {
67
- parts.push(path.slice(lastIndex, offset));
68
- }
69
- parts.push(
70
- <span key={`offset-${offset}`} className="openapi-path-variable">
71
- {match}
72
- </span>
73
- );
74
- lastIndex = offset + match.length;
75
- return match;
76
- });
77
-
78
- if (lastIndex < path.length) {
79
- parts.push(path.slice(lastIndex));
80
- }
81
-
82
- const formattedPath = parts.map((part, index) => {
83
- if (typeof part === 'string') {
84
- return <span key={`part-${index}`}>{part}</span>;
85
- }
86
- return part;
87
- });
88
-
89
- return formattedPath;
90
- }
@@ -1,40 +0,0 @@
1
- 'use client';
2
-
3
- import * as React from 'react';
4
-
5
- /**
6
- * Prefill data that can be used to dynamically inject info into OpenAPI operation blocks.
7
- *
8
- * This is typically dynamic input context, such as visitor data or environment info.
9
- */
10
- export type PrefillInputContextData = Record<string, unknown>;
11
-
12
- /**
13
- * Context value is function that returns prefill data.
14
- */
15
- type PrefillContextValue = () => PrefillInputContextData | null;
16
-
17
- const OpenAPIPrefillContext = React.createContext<PrefillContextValue | null>(null);
18
-
19
- /**
20
- * Provide context to help prefill dynamic info like visitor data in OpenAPI blocks.
21
- */
22
- export function OpenAPIPrefillContextProvider(
23
- props: React.PropsWithChildren<{
24
- getPrefillInputContextData: () => PrefillInputContextData | null;
25
- }>
26
- ) {
27
- const { getPrefillInputContextData, children } = props;
28
- return (
29
- <OpenAPIPrefillContext.Provider value={getPrefillInputContextData}>
30
- {children}
31
- </OpenAPIPrefillContext.Provider>
32
- );
33
- }
34
-
35
- /**
36
- * Hook to access the prefill context function.
37
- */
38
- export function useOpenAPIPrefillContext(): PrefillContextValue {
39
- return React.useContext(OpenAPIPrefillContext) ?? (() => null);
40
- }
@@ -1,54 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import { InteractiveSection } from './InteractiveSection';
3
- import { OpenAPIRequestBodyHeaderType } from './OpenAPIRequestBodyHeaderType';
4
- import { OpenAPIRootSchema } from './OpenAPISchemaServer';
5
- import type { OpenAPIClientContext } from './context';
6
- import { t } from './translate';
7
- import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
8
- import { checkIsReference, createStateKey } from './utils';
9
-
10
- /**
11
- * Display an interactive request body.
12
- */
13
- export function OpenAPIRequestBody(props: {
14
- requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
15
- context: OpenAPIClientContext;
16
- data: OpenAPIOperationData | OpenAPIWebhookData;
17
- }) {
18
- const { requestBody, context, data } = props;
19
-
20
- if (checkIsReference(requestBody)) {
21
- return null;
22
- }
23
-
24
- const stateKey = createStateKey('request-body-media-type', context.blockKey);
25
-
26
- return (
27
- <InteractiveSection
28
- header={
29
- <>
30
- <span>{t(context.translation, 'name' in data ? 'payload' : 'body')}</span>
31
- <OpenAPIRequestBodyHeaderType requestBody={requestBody} stateKey={stateKey} />
32
- </>
33
- }
34
- className="openapi-requestbody"
35
- stateKey={stateKey}
36
- selectIcon={context.icons.chevronDown}
37
- tabs={Object.entries(requestBody.content ?? {}).map(
38
- ([contentType, mediaTypeObject]) => {
39
- return {
40
- key: contentType,
41
- label: contentType,
42
- body: (
43
- <OpenAPIRootSchema
44
- schema={mediaTypeObject.schema ?? {}}
45
- context={context}
46
- key={contentType}
47
- />
48
- ),
49
- };
50
- }
51
- )}
52
- />
53
- );
54
- }
@@ -1,36 +0,0 @@
1
- 'use client';
2
-
3
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
4
- import { useSelectState } from './OpenAPISelect';
5
- import { getSchemaTitle } from './utils';
6
-
7
- /**
8
- * Display the type of a request body. It only displays the type if the selected content is an array.
9
- */
10
- export function OpenAPIRequestBodyHeaderType(props: {
11
- requestBody: OpenAPIV3.RequestBodyObject;
12
- stateKey: string;
13
- }) {
14
- const { requestBody, stateKey } = props;
15
- const content = requestBody.content ?? {};
16
- const state = useSelectState(stateKey, Object.keys(content)[0]);
17
-
18
- const selectedContentMediaType = Object.entries(content).find(
19
- ([contentType]) => contentType === state.key
20
- )?.[1];
21
-
22
- // If the selected content is not an array, we don't display the type
23
- if (
24
- !selectedContentMediaType ||
25
- !selectedContentMediaType.schema?.type ||
26
- selectedContentMediaType.schema.type !== 'array'
27
- ) {
28
- return null;
29
- }
30
-
31
- return (
32
- <span className="openapi-requestbody-header-type">
33
- {`${getSchemaTitle(selectedContentMediaType.schema)}`}
34
- </span>
35
- );
36
- }
@@ -1,82 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import { OpenAPIDisclosure } from './OpenAPIDisclosure';
3
- import { OpenAPISchemaPresentation } from './OpenAPISchema';
4
- import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
5
- import type { OpenAPIClientContext } from './context';
6
- import { tString } from './translate';
7
- import { parameterToProperty, resolveDescription } from './utils';
8
-
9
- /**
10
- * Display an interactive response body.
11
- */
12
- export function OpenAPIResponse(props: {
13
- response: OpenAPIV3.ResponseObject;
14
- mediaType: OpenAPIV3.MediaTypeObject | null;
15
- context: OpenAPIClientContext;
16
- }) {
17
- const { response, context, mediaType } = props;
18
- const headers = Object.entries(response.headers ?? {}).map(
19
- ([name, header]) => [name, header ?? {}] as const
20
- );
21
- const content = Object.entries(mediaType?.schema ?? {});
22
-
23
- const description = resolveDescription(response);
24
-
25
- if (content.length === 0 && !description && headers.length === 0) {
26
- return null;
27
- }
28
-
29
- return (
30
- <div className="openapi-response-body">
31
- {headers.length > 0 ? (
32
- <OpenAPIDisclosure
33
- header={
34
- <OpenAPISchemaPresentation
35
- context={context}
36
- property={{
37
- propertyName: tString(context.translation, 'headers'),
38
- schema: {
39
- type: 'object',
40
- },
41
- required: null,
42
- }}
43
- />
44
- }
45
- icon={context.icons.plus}
46
- label={(isExpanded) =>
47
- tString(
48
- context.translation,
49
- isExpanded ? 'hide' : 'show',
50
- tString(
51
- context.translation,
52
- headers.length === 1 ? 'header' : 'headers'
53
- )
54
- )
55
- }
56
- >
57
- <OpenAPISchemaProperties
58
- properties={headers.map(([name, header]) =>
59
- parameterToProperty({ name, ...header })
60
- )}
61
- context={context}
62
- />
63
- </OpenAPIDisclosure>
64
- ) : null}
65
- {mediaType?.schema && (
66
- <div className="openapi-responsebody">
67
- <OpenAPISchemaProperties
68
- id={`response-${context.blockKey}`}
69
- properties={[
70
- {
71
- schema: mediaType.schema,
72
- propertyName: tString(context.translation, 'response'),
73
- required: null,
74
- },
75
- ]}
76
- context={context}
77
- />
78
- </div>
79
- )}
80
- </div>
81
- );
82
- }
@@ -1,151 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import { Markdown } from './Markdown';
3
- import { OpenAPIEmptyExample, OpenAPIExample } from './OpenAPIExample';
4
- import { OpenAPIMediaTypeContent } from './OpenAPIMediaType';
5
- import { OpenAPIResponseExampleContent } from './OpenAPIResponseExampleContent';
6
- import { type OpenAPIContext, getOpenAPIClientContext } from './context';
7
- import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
8
- import { getExampleFromReference, getExamples } from './util/example';
9
- import { createStateKey, getStatusCodeDefaultLabel, resolveDescription } from './utils';
10
- import { checkIsReference } from './utils';
11
-
12
- /**
13
- * Display an example of the response content.
14
- */
15
- export function OpenAPIResponseExample(props: {
16
- data: OpenAPIOperationData | OpenAPIWebhookData;
17
- context: OpenAPIContext;
18
- }) {
19
- const { data, context } = props;
20
-
21
- // if there are no responses defined for the operation
22
- if (!data.operation.responses) {
23
- return null;
24
- }
25
-
26
- const responses = Object.entries(data.operation.responses);
27
- // Sort response to get 200, and 2xx first
28
- responses.sort(([a], [b]) => {
29
- if (a === 'default') {
30
- return 1;
31
- }
32
- if (b === 'default') {
33
- return -1;
34
- }
35
- if (a === '200') {
36
- return -1;
37
- }
38
- if (b === '200') {
39
- return 1;
40
- }
41
- return Number(a) - Number(b);
42
- });
43
-
44
- const tabs = responses
45
- .filter(
46
- ([_, responseObject]) =>
47
- responseObject &&
48
- typeof responseObject === 'object' &&
49
- // Make sure the response is not hidden
50
- !responseObject['x-hideSample']
51
- )
52
- .map(([key, responseObject]) => {
53
- const description = resolveDescription(responseObject);
54
- const label = description ? (
55
- <Markdown key={`response-description-${key}`} source={description} />
56
- ) : (
57
- getStatusCodeDefaultLabel(key, context)
58
- );
59
-
60
- if (checkIsReference(responseObject)) {
61
- return {
62
- key: key,
63
- label,
64
- statusCode: key,
65
- body: (
66
- <OpenAPIExample
67
- example={getExampleFromReference(responseObject, context)}
68
- context={context}
69
- syntax="json"
70
- />
71
- ),
72
- };
73
- }
74
-
75
- if (!responseObject.content || Object.keys(responseObject.content).length === 0) {
76
- return {
77
- key: key,
78
- label,
79
- statusCode: key,
80
- body: <OpenAPIEmptyExample context={context} />,
81
- };
82
- }
83
-
84
- return {
85
- key: key,
86
- label,
87
- statusCode: key,
88
- body: <OpenAPIResponse context={context} content={responseObject.content} />,
89
- };
90
- });
91
-
92
- if (tabs.length === 0) {
93
- return null;
94
- }
95
-
96
- return (
97
- <OpenAPIResponseExampleContent
98
- selectIcon={context.icons.chevronDown}
99
- blockKey={context.blockKey}
100
- items={tabs}
101
- />
102
- );
103
- }
104
-
105
- function OpenAPIResponse(props: {
106
- context: OpenAPIContext;
107
- content: {
108
- [media: string]: OpenAPIV3.MediaTypeObject | null;
109
- };
110
- }) {
111
- const { context, content } = props;
112
-
113
- const entries = Object.entries(content);
114
- const firstEntry = entries[0];
115
-
116
- if (!firstEntry) {
117
- throw new Error('One media type is required');
118
- }
119
-
120
- const tabs = entries.map((entry) => {
121
- const [mediaType, mediaTypeObject] = entry;
122
-
123
- if (!mediaTypeObject) {
124
- return {
125
- key: mediaType,
126
- label: mediaType,
127
- body: <OpenAPIEmptyExample context={context} />,
128
- };
129
- }
130
-
131
- return {
132
- key: mediaType,
133
- label: mediaType,
134
- body: <></>,
135
- examples: getExamples({
136
- mediaTypeObject,
137
- mediaType,
138
- context,
139
- }),
140
- };
141
- });
142
-
143
- return (
144
- <OpenAPIMediaTypeContent
145
- selectIcon={context.icons.chevronDown}
146
- stateKey={createStateKey('response-media-types', context.blockKey)}
147
- items={tabs}
148
- context={getOpenAPIClientContext(context)}
149
- />
150
- );
151
- }