@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
@@ -0,0 +1,23 @@
1
+ import { t } from "../translate.js";
2
+ import { getOpenAPIClientContext } from "../context.js";
3
+ import { OpenAPISpec } from "../OpenAPISpec.js";
4
+ import { OpenAPIOperationDescription } from "./OpenAPIOperationDescription.js";
5
+
6
+ //#region src/common/OpenAPIColumnSpec.tsx
7
+ function OpenAPIColumnSpec(props) {
8
+ const { data, context } = props;
9
+ const { operation } = data;
10
+ const clientContext = getOpenAPIClientContext(context);
11
+ return <div className="openapi-column-spec">
12
+ {operation["x-deprecated-sunset"] ? <div className="openapi-deprecated-sunset openapi-description openapi-markdown">
13
+ {t(context.translation, "deprecated_and_sunset_on", [<span key="date" className="openapi-deprecated-sunset-date">
14
+ {operation["x-deprecated-sunset"]}
15
+ </span>])}
16
+ </div> : null}
17
+ <OpenAPIOperationDescription operation={operation} context={context} />
18
+ <OpenAPISpec data={data} context={clientContext} />
19
+ </div>;
20
+ }
21
+
22
+ //#endregion
23
+ export { OpenAPIColumnSpec };
@@ -0,0 +1,18 @@
1
+ import { Markdown } from "../Markdown.js";
2
+ import { resolveDescription } from "../utils.js";
3
+
4
+ //#region src/common/OpenAPIOperationDescription.tsx
5
+ function OpenAPIOperationDescription(props) {
6
+ const { operation } = props;
7
+ if (operation["x-gitbook-description-document"]) return <div className="openapi-intro">
8
+ {props.context.renderDocument({ document: operation["x-gitbook-description-document"] })}
9
+ </div>;
10
+ const description = resolveDescription(operation);
11
+ if (!description) return null;
12
+ return <div className="openapi-intro">
13
+ <Markdown className="openapi-description" source={description} />
14
+ </div>;
15
+ }
16
+
17
+ //#endregion
18
+ export { OpenAPIOperationDescription };
@@ -0,0 +1,17 @@
1
+ //#region src/common/OpenAPIStability.tsx
2
+ const stabilityEnum = {
3
+ experimental: "Experimental",
4
+ alpha: "Alpha",
5
+ beta: "Beta"
6
+ };
7
+ function OpenAPIStability(props) {
8
+ const { stability } = props;
9
+ const foundStability = stabilityEnum[stability];
10
+ if (!foundStability) return null;
11
+ return <div className={`openapi-stability openapi-stability-${foundStability.toLowerCase()}`}>
12
+ {foundStability}
13
+ </div>;
14
+ }
15
+
16
+ //#endregion
17
+ export { OpenAPIStability };
@@ -0,0 +1,27 @@
1
+ import { OpenAPIPath } from "../OpenAPIPath.js";
2
+ import { OpenAPIStability } from "./OpenAPIStability.js";
3
+
4
+ //#region src/common/OpenAPISummary.tsx
5
+ function OpenAPISummary(props) {
6
+ const { data, context } = props;
7
+ const { operation } = data;
8
+ const title = (() => {
9
+ if (operation.summary) return operation.summary;
10
+ if ("name" in data) return data.name;
11
+ })();
12
+ return <div className="openapi-summary" id={operation.summary ? void 0 : context.id}>
13
+ {(operation.deprecated || operation["x-stability"]) && <div className="openapi-summary-tags">
14
+ {operation.deprecated && <div className="openapi-deprecated">Deprecated</div>}
15
+ {operation["x-stability"] && <OpenAPIStability stability={operation["x-stability"]} />}
16
+ </div>}
17
+ {title ? context.renderHeading({
18
+ deprecated: operation.deprecated ?? false,
19
+ stability: operation["x-stability"],
20
+ title
21
+ }) : null}
22
+ {"path" in data ? <OpenAPIPath data={data} context={context} /> : null}
23
+ </div>;
24
+ }
25
+
26
+ //#endregion
27
+ export { OpenAPISummary };
@@ -1,30 +1,34 @@
1
- export function isJSON(contentType) {
2
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/json')) || false;
1
+ //#region src/contentTypeChecks.ts
2
+ function isJSON(contentType) {
3
+ return contentType?.toLowerCase().includes("application/json") || false;
3
4
  }
4
- export function isXML(contentType) {
5
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/xml')) || false;
5
+ function isXML(contentType) {
6
+ return contentType?.toLowerCase().includes("application/xml") || false;
6
7
  }
7
- export function isYAML(contentType) {
8
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/yaml')) || false;
8
+ function isYAML(contentType) {
9
+ return contentType?.toLowerCase().includes("application/yaml") || false;
9
10
  }
10
- export function isGraphQL(contentType) {
11
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/graphql')) || false;
11
+ function isGraphQL(contentType) {
12
+ return contentType?.toLowerCase().includes("application/graphql") || false;
12
13
  }
13
- export function isCSV(contentType) {
14
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('text/csv')) || false;
14
+ function isCSV(contentType) {
15
+ return contentType?.toLowerCase().includes("text/csv") || false;
15
16
  }
16
- export function isPDF(contentType) {
17
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/pdf')) || false;
17
+ function isPDF(contentType) {
18
+ return contentType?.toLowerCase().includes("application/pdf") || false;
18
19
  }
19
- export function isText(contentType) {
20
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('text/plain')) || false;
20
+ function isText(contentType) {
21
+ return contentType?.toLowerCase().includes("text/plain") || false;
21
22
  }
22
- export function isFormUrlEncoded(contentType) {
23
- return (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes('application/x-www-form-urlencoded')) || false;
23
+ function isFormUrlEncoded(contentType) {
24
+ return contentType?.toLowerCase().includes("application/x-www-form-urlencoded") || false;
24
25
  }
25
- export function isFormData(contentType) {
26
- return !!contentType && contentType.toLowerCase().includes('multipart/form-data');
26
+ function isFormData(contentType) {
27
+ return !!contentType && contentType.toLowerCase().includes("multipart/form-data");
27
28
  }
28
- export function isPlainObject(value) {
29
- return typeof value === 'object' && value !== null && !Array.isArray(value);
29
+ function isPlainObject(value) {
30
+ return typeof value === "object" && value !== null && !Array.isArray(value);
30
31
  }
32
+
33
+ //#endregion
34
+ export { isCSV, isFormData, isFormUrlEncoded, isGraphQL, isJSON, isPDF, isPlainObject, isText, isXML, isYAML };
package/dist/context.d.ts CHANGED
@@ -1,75 +1,71 @@
1
- import { type Translation, type TranslationLocale } from './translations';
2
- export interface OpenAPIClientContext {
3
- /**
4
- * The translation language to use.
5
- */
6
- translation: Translation;
7
- /**
8
- * Icons used in the block.
9
- */
10
- icons: {
11
- chevronDown: React.ReactNode;
12
- chevronRight: React.ReactNode;
13
- plus: React.ReactNode;
14
- };
15
- /**
16
- * Force all sections to be opened by default.
17
- * @default false
18
- */
19
- defaultInteractiveOpened?: boolean;
20
- /**
21
- * The key of the block
22
- */
23
- blockKey?: string;
24
- /**
25
- * Optional id attached to the heading and used as an anchor.
26
- */
27
- id?: string;
28
- /**
29
- * Mark the context as a client context.
30
- */
31
- $$isClientContext$$: true;
1
+ import { Translation } from "./translations/types.js";
2
+ import { TranslationLocale } from "./translations/index.js";
3
+
4
+ //#region src/context.d.ts
5
+ interface OpenAPIClientContext {
6
+ /**
7
+ * The translation language to use.
8
+ */
9
+ translation: Translation;
10
+ /**
11
+ * Icons used in the block.
12
+ */
13
+ icons: {
14
+ chevronDown: React.ReactNode;
15
+ chevronRight: React.ReactNode;
16
+ plus: React.ReactNode;
17
+ };
18
+ /**
19
+ * Force all sections to be opened by default.
20
+ * @default false
21
+ */
22
+ defaultInteractiveOpened?: boolean;
23
+ /**
24
+ * The key of the block
25
+ */
26
+ blockKey?: string;
27
+ /**
28
+ * Optional id attached to the heading and used as an anchor.
29
+ */
30
+ id?: string;
31
+ /**
32
+ * Mark the context as a client context.
33
+ */
34
+ $$isClientContext$$: true;
32
35
  }
33
- export interface OpenAPIContext extends Omit<OpenAPIClientContext, '$$isClientContext$$'> {
34
- /**
35
- * Render a code block.
36
- */
37
- renderCodeBlock: (props: {
38
- code: string;
39
- syntax: string;
40
- }) => React.ReactNode;
41
- /**
42
- * Render the heading of the operation.
43
- */
44
- renderHeading: (props: {
45
- deprecated: boolean;
46
- title: string;
47
- stability?: string;
48
- }) => React.ReactNode;
49
- /**
50
- * Render the document of the operation.
51
- */
52
- renderDocument: (props: {
53
- document: object;
54
- }) => React.ReactNode;
55
- /**
56
- * Specification URL.
57
- */
58
- specUrl: string;
36
+ interface OpenAPIContext extends Omit<OpenAPIClientContext, '$$isClientContext$$'> {
37
+ /**
38
+ * Render a code block.
39
+ */
40
+ renderCodeBlock: (props: {
41
+ code: string;
42
+ syntax: string;
43
+ }) => React.ReactNode;
44
+ /**
45
+ * Render the heading of the operation.
46
+ */
47
+ renderHeading: (props: {
48
+ deprecated: boolean;
49
+ title: string;
50
+ stability?: string;
51
+ }) => React.ReactNode;
52
+ /**
53
+ * Render the document of the operation.
54
+ */
55
+ renderDocument: (props: {
56
+ document: object;
57
+ }) => React.ReactNode;
58
+ /**
59
+ * Specification URL.
60
+ */
61
+ specUrl: string;
59
62
  }
60
- export type OpenAPIUniversalContext = OpenAPIClientContext | OpenAPIContext;
61
- export interface OpenAPIContextInput extends Omit<OpenAPIContext, 'translation'> {
62
- /**
63
- * The translation language to use.
64
- * @default 'en'
65
- */
66
- locale?: TranslationLocale | undefined;
63
+ interface OpenAPIContextInput extends Omit<OpenAPIContext, 'translation'> {
64
+ /**
65
+ * The translation language to use.
66
+ * @default 'en'
67
+ */
68
+ locale?: TranslationLocale | undefined;
67
69
  }
68
- /**
69
- * Resolve OpenAPI context from the input.
70
- */
71
- export declare function resolveOpenAPIContext(context: OpenAPIContextInput): OpenAPIContext;
72
- /**
73
- * Get the client context from the OpenAPI context.
74
- */
75
- export declare function getOpenAPIClientContext(context: OpenAPIUniversalContext): OpenAPIClientContext;
70
+ //#endregion
71
+ export { OpenAPIContextInput };
package/dist/context.js CHANGED
@@ -1,43 +1,29 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __rest = (this && this.__rest) || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
- t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
- t[p[i]] = s[p[i]];
20
- }
21
- return t;
22
- };
23
- import { translations } from './translations';
1
+ import { translations } from "./translations/index.js";
2
+
3
+ //#region src/context.ts
24
4
  /**
25
- * Resolve OpenAPI context from the input.
26
- */
27
- export function resolveOpenAPIContext(context) {
28
- var locale = context.locale, rest = __rest(context, ["locale"]);
29
- return __assign(__assign({}, rest), { translation: translations[locale !== null && locale !== void 0 ? locale : 'en'] });
5
+ * Resolve OpenAPI context from the input.
6
+ */
7
+ function resolveOpenAPIContext(context) {
8
+ const { locale,...rest } = context;
9
+ return {
10
+ ...rest,
11
+ translation: translations[locale ?? "en"]
12
+ };
30
13
  }
31
14
  /**
32
- * Get the client context from the OpenAPI context.
33
- */
34
- export function getOpenAPIClientContext(context) {
35
- return {
36
- translation: context.translation,
37
- icons: context.icons,
38
- defaultInteractiveOpened: context.defaultInteractiveOpened,
39
- blockKey: context.blockKey,
40
- id: context.id,
41
- $$isClientContext$$: true,
42
- };
15
+ * Get the client context from the OpenAPI context.
16
+ */
17
+ function getOpenAPIClientContext(context) {
18
+ return {
19
+ translation: context.translation,
20
+ icons: context.icons,
21
+ defaultInteractiveOpened: context.defaultInteractiveOpened,
22
+ blockKey: context.blockKey,
23
+ id: context.id,
24
+ $$isClientContext$$: true
25
+ };
43
26
  }
27
+
28
+ //#endregion
29
+ export { getOpenAPIClientContext, resolveOpenAPIContext };
package/dist/decycle.js CHANGED
@@ -1,70 +1,41 @@
1
- // Forked from: https://github.com/YChebotaev/json-decycle/blob/master/src/index.ts
2
- // Replaced `$ref` with `$reference` to avoid conflicts with OpenAPI
3
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
4
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
5
- if (ar || !(i in from)) {
6
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
7
- ar[i] = from[i];
8
- }
9
- }
10
- return to.concat(ar || Array.prototype.slice.call(from));
1
+ //#region src/decycle.ts
2
+ const isObject = (value) => typeof value === "object" && value != null && !(value instanceof Boolean) && !(value instanceof Date) && !(value instanceof Number) && !(value instanceof RegExp) && !(value instanceof String);
3
+ const toPointer = (parts) => `#${parts.map((part) => String(part).replace(/~/g, "~0").replace(/\//g, "~1")).join("/")}`;
4
+ const decycle = () => {
5
+ const paths = /* @__PURE__ */ new WeakMap();
6
+ return function replacer(key, value) {
7
+ if (key !== "$reference" && isObject(value)) {
8
+ if (paths.has(value)) return { $reference: toPointer(paths.get(value)) };
9
+ paths.set(value, [...paths.get(this) ?? [], key]);
10
+ }
11
+ return value;
12
+ };
11
13
  };
12
- var isObject = function (value) {
13
- return typeof value === 'object' &&
14
- value != null &&
15
- !(value instanceof Boolean) &&
16
- !(value instanceof Date) &&
17
- !(value instanceof Number) &&
18
- !(value instanceof RegExp) &&
19
- !(value instanceof String);
20
- };
21
- var toPointer = function (parts) {
22
- return "#".concat(parts.map(function (part) { return String(part).replace(/~/g, '~0').replace(/\//g, '~1'); }).join('/'));
23
- };
24
- export var decycle = function () {
25
- var paths = new WeakMap();
26
- return function replacer(key, value) {
27
- var _a;
28
- if (key !== '$reference' && isObject(value)) {
29
- var seen = paths.has(value);
30
- if (seen) {
31
- return { $reference: toPointer(paths.get(value)) };
32
- }
33
- paths.set(value, __spreadArray(__spreadArray([], ((_a = paths.get(this)) !== null && _a !== void 0 ? _a : []), true), [key], false));
34
- }
35
- return value;
36
- };
37
- };
38
- export function retrocycle() {
39
- var parents = new WeakMap();
40
- var keys = new WeakMap();
41
- var refs = new Set();
42
- function dereference(ref) {
43
- var _a;
44
- var parts = ref.$reference.slice(1).split('/');
45
- var key;
46
- var value = this;
47
- for (var i = 0; i < parts.length; i++) {
48
- key = (_a = parts[i]) === null || _a === void 0 ? void 0 : _a.replace(/~1/g, '/').replace(/~0/g, '~');
49
- value = value[key];
50
- }
51
- var parent = parents.get(ref);
52
- parent[keys.get(ref)] = value;
53
- }
54
- return function reviver(key, value) {
55
- if (key === '$reference') {
56
- refs.add(this);
57
- }
58
- else if (isObject(value)) {
59
- var isRoot = key === '' && Object.keys(this).length === 1;
60
- if (isRoot) {
61
- refs.forEach(dereference, this);
62
- }
63
- else {
64
- parents.set(value, this);
65
- keys.set(value, key);
66
- }
67
- }
68
- return value;
69
- };
14
+ function retrocycle() {
15
+ const parents = /* @__PURE__ */ new WeakMap();
16
+ const keys = /* @__PURE__ */ new WeakMap();
17
+ const refs = /* @__PURE__ */ new Set();
18
+ function dereference(ref) {
19
+ const parts = ref.$reference.slice(1).split("/");
20
+ let key;
21
+ let value = this;
22
+ for (let i = 0; i < parts.length; i++) {
23
+ key = parts[i]?.replace(/~1/g, "/").replace(/~0/g, "~");
24
+ value = value[key];
25
+ }
26
+ const parent = parents.get(ref);
27
+ parent[keys.get(ref)] = value;
28
+ }
29
+ return function reviver(key, value) {
30
+ if (key === "$reference") refs.add(this);
31
+ else if (isObject(value)) if (key === "" && Object.keys(this).length === 1) refs.forEach(dereference, this);
32
+ else {
33
+ parents.set(value, this);
34
+ keys.set(value, key);
35
+ }
36
+ return value;
37
+ };
70
38
  }
39
+
40
+ //#endregion
41
+ export { decycle, retrocycle };
@@ -1,68 +1,24 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import { dereference } from '@gitbook/openapi-parser';
38
- var dereferenceCache = new WeakMap();
1
+ import { dereference } from "@gitbook/openapi-parser";
2
+
3
+ //#region src/dereference.ts
4
+ const dereferenceCache = /* @__PURE__ */ new WeakMap();
39
5
  /**
40
- * Memoized version of `dereferenceSchema`.
41
- */
42
- export function dereferenceFilesystem(filesystem) {
43
- if (dereferenceCache.has(filesystem)) {
44
- return dereferenceCache.get(filesystem);
45
- }
46
- var promise = baseDereferenceFilesystem(filesystem);
47
- dereferenceCache.set(filesystem, promise);
48
- return promise;
6
+ * Memoized version of `dereferenceSchema`.
7
+ */
8
+ function dereferenceFilesystem(filesystem) {
9
+ if (dereferenceCache.has(filesystem)) return dereferenceCache.get(filesystem);
10
+ const promise = baseDereferenceFilesystem(filesystem);
11
+ dereferenceCache.set(filesystem, promise);
12
+ return promise;
49
13
  }
50
14
  /**
51
- * Dereference an OpenAPI schema.
52
- */
53
- function baseDereferenceFilesystem(filesystem) {
54
- return __awaiter(this, void 0, void 0, function () {
55
- var result;
56
- return __generator(this, function (_a) {
57
- switch (_a.label) {
58
- case 0: return [4 /*yield*/, dereference(filesystem)];
59
- case 1:
60
- result = _a.sent();
61
- if (!result.schema) {
62
- throw new Error('Failed to dereference OpenAPI document');
63
- }
64
- return [2 /*return*/, result.schema];
65
- }
66
- });
67
- });
15
+ * Dereference an OpenAPI schema.
16
+ */
17
+ async function baseDereferenceFilesystem(filesystem) {
18
+ const result = await dereference(filesystem);
19
+ if (!result.schema) throw new Error("Failed to dereference OpenAPI document");
20
+ return result.schema;
68
21
  }
22
+
23
+ //#endregion
24
+ export { dereferenceFilesystem };