@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
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- export * from './schemas';
2
- export * from './OpenAPIOperation';
3
- export * from './OpenAPIWebhook';
4
- export * from './OpenAPIOperationContext';
5
- export * from './OpenAPIPrefillContextProvider';
6
- export * from './resolveOpenAPIOperation';
7
- export * from './resolveOpenAPIWebhook';
8
- export type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
9
- export type { OpenAPIContextInput } from './context';
10
- export { checkIsValidLocale } from './translations';
1
+ import { checkIsValidLocale } from "./translations/index.js";
2
+ import { OpenAPIContextInput } from "./context.js";
3
+ import { OpenAPISchemas } from "./schemas/OpenAPISchemas.js";
4
+ import { resolveOpenAPISchemas } from "./schemas/resolveOpenAPISchemas.js";
5
+ import { OpenAPIOperationData, OpenAPIWebhookData } from "./types.js";
6
+ import { OpenAPIOperation } from "./OpenAPIOperation.js";
7
+ import { OpenAPIWebhook } from "./OpenAPIWebhook.js";
8
+ import { OpenAPIOperationContextProvider, useOpenAPIOperationContext } from "./OpenAPIOperationContext.js";
9
+ import { OpenAPIPrefillContextProvider, PrefillInputContextData, useOpenAPIPrefillContext } from "./OpenAPIPrefillContextProvider.js";
10
+ import { resolveOpenAPIOperation } from "./resolveOpenAPIOperation.js";
11
+ import { resolveOpenAPIWebhook } from "./resolveOpenAPIWebhook.js";
12
+ export { type OpenAPIContextInput, OpenAPIOperation, OpenAPIOperationContextProvider, type OpenAPIOperationData, OpenAPIPrefillContextProvider, OpenAPISchemas, OpenAPIWebhook, type OpenAPIWebhookData, PrefillInputContextData, checkIsValidLocale, resolveOpenAPIOperation, resolveOpenAPISchemas, resolveOpenAPIWebhook, useOpenAPIOperationContext, useOpenAPIPrefillContext };
package/dist/index.js CHANGED
@@ -1,8 +1,11 @@
1
- export * from './schemas';
2
- export * from './OpenAPIOperation';
3
- export * from './OpenAPIWebhook';
4
- export * from './OpenAPIOperationContext';
5
- export * from './OpenAPIPrefillContextProvider';
6
- export * from './resolveOpenAPIOperation';
7
- export * from './resolveOpenAPIWebhook';
8
- export { checkIsValidLocale } from './translations';
1
+ import { checkIsValidLocale } from "./translations/index.js";
2
+ import { OpenAPISchemas } from "./schemas/OpenAPISchemas.js";
3
+ import { resolveOpenAPISchemas } from "./schemas/resolveOpenAPISchemas.js";
4
+ import { OpenAPIOperationContextProvider, useOpenAPIOperationContext } from "./OpenAPIOperationContext.js";
5
+ import { OpenAPIPrefillContextProvider, useOpenAPIPrefillContext } from "./OpenAPIPrefillContextProvider.js";
6
+ import { OpenAPIOperation } from "./OpenAPIOperation.js";
7
+ import { OpenAPIWebhook } from "./OpenAPIWebhook.js";
8
+ import { resolveOpenAPIOperation } from "./resolveOpenAPIOperation.js";
9
+ import { resolveOpenAPIWebhook } from "./resolveOpenAPIWebhook.js";
10
+
11
+ export { OpenAPIOperation, OpenAPIOperationContextProvider, OpenAPIPrefillContextProvider, OpenAPISchemas, OpenAPIWebhook, checkIsValidLocale, resolveOpenAPIOperation, resolveOpenAPISchemas, resolveOpenAPIWebhook, useOpenAPIOperationContext, useOpenAPIPrefillContext };
package/dist/json2xml.js CHANGED
@@ -1,7 +1,12 @@
1
- import { jsXml } from 'json-xml-parse';
1
+ import { jsXml } from "json-xml-parse";
2
+
3
+ //#region src/json2xml.ts
2
4
  /**
3
- * This function converts an object to XML.
4
- */
5
- export function json2xml(data) {
6
- return jsXml.toXmlString(data, { beautify: true });
5
+ * This function converts an object to XML.
6
+ */
7
+ function json2xml(data) {
8
+ return jsXml.toXmlString(data, { beautify: true });
7
9
  }
10
+
11
+ //#endregion
12
+ export { json2xml };
@@ -1,11 +1,15 @@
1
- import { fromJSON, toJSON } from 'flatted';
2
- import type { Filesystem, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
3
- import type { OpenAPIOperationData } from './types';
4
- export { fromJSON, toJSON };
1
+ import { OpenAPIOperationData } from "./types.js";
2
+ import { Filesystem, OpenAPIV3xDocument } from "@gitbook/openapi-parser";
3
+ import "flatted";
4
+
5
+ //#region src/resolveOpenAPIOperation.d.ts
6
+
5
7
  /**
6
8
  * Resolve an OpenAPI operation in a file and compile it to a more usable format.
7
9
  */
8
- export declare function resolveOpenAPIOperation(filesystem: Filesystem<OpenAPIV3xDocument>, operationDescriptor: {
9
- path: string;
10
- method: string;
10
+ declare function resolveOpenAPIOperation(filesystem: Filesystem<OpenAPIV3xDocument>, operationDescriptor: {
11
+ path: string;
12
+ method: string;
11
13
  }): Promise<OpenAPIOperationData | null>;
14
+ //#endregion
15
+ export { resolveOpenAPIOperation };
@@ -1,173 +1,102 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- 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);
23
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- 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;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
- if (ar || !(i in from)) {
51
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
- ar[i] = from[i];
53
- }
54
- }
55
- return to.concat(ar || Array.prototype.slice.call(from));
56
- };
57
- import { fromJSON, toJSON } from 'flatted';
58
- import { dereferenceFilesystem } from './dereference';
59
- import { checkIsReference } from './utils';
60
- export { fromJSON, toJSON };
1
+ import { checkIsReference } from "./utils.js";
2
+ import { dereferenceFilesystem } from "./dereference.js";
3
+ import "flatted";
4
+
5
+ //#region src/resolveOpenAPIOperation.ts
61
6
  /**
62
- * Resolve an OpenAPI operation in a file and compile it to a more usable format.
63
- */
64
- export function resolveOpenAPIOperation(filesystem, operationDescriptor) {
65
- return __awaiter(this, void 0, void 0, function () {
66
- var path, method, schema, operation, commonParameters, servers, schemaSecurity, security, isOptionalSecurity, flatSecurities, securities, _i, flatSecurities_1, entry, securityKey, securityScheme;
67
- var _a, _b, _c, _d, _e;
68
- return __generator(this, function (_f) {
69
- switch (_f.label) {
70
- case 0:
71
- path = operationDescriptor.path, method = operationDescriptor.method;
72
- return [4 /*yield*/, dereferenceFilesystem(filesystem)];
73
- case 1:
74
- schema = _f.sent();
75
- operation = getOperationByPathAndMethod(schema, path, method);
76
- if (!operation) {
77
- return [2 /*return*/, null];
78
- }
79
- commonParameters = getPathObjectParameter(schema, path);
80
- if (commonParameters) {
81
- operation = __assign(__assign({}, operation), { parameters: __spreadArray(__spreadArray([], commonParameters, true), ((_a = operation.parameters) !== null && _a !== void 0 ? _a : []), true) });
82
- }
83
- servers = 'servers' in schema ? ((_b = schema.servers) !== null && _b !== void 0 ? _b : []) : [];
84
- schemaSecurity = Array.isArray(schema.security)
85
- ? schema.security
86
- : schema.security
87
- ? [schema.security]
88
- : [];
89
- security = (_c = operation.security) !== null && _c !== void 0 ? _c : schemaSecurity;
90
- isOptionalSecurity = security.some(function (entry) { return Object.keys(entry).length === 0; });
91
- flatSecurities = flattenSecurities(security);
92
- securities = [];
93
- for (_i = 0, flatSecurities_1 = flatSecurities; _i < flatSecurities_1.length; _i++) {
94
- entry = flatSecurities_1[_i];
95
- securityKey = Object.keys(entry)[0];
96
- if (securityKey) {
97
- securityScheme = (_e = (_d = schema.components) === null || _d === void 0 ? void 0 : _d.securitySchemes) === null || _e === void 0 ? void 0 : _e[securityKey];
98
- if (securityScheme && !checkIsReference(securityScheme)) {
99
- securities.push([
100
- securityKey,
101
- __assign(__assign({}, securityScheme), { required: !isOptionalSecurity }),
102
- ]);
103
- }
104
- }
105
- }
106
- return [2 /*return*/, {
107
- servers: servers,
108
- operation: operation,
109
- method: method,
110
- path: path,
111
- securities: securities,
112
- 'x-codeSamples': typeof schema['x-codeSamples'] === 'boolean' ? schema['x-codeSamples'] : undefined,
113
- 'x-hideTryItPanel': typeof schema['x-hideTryItPanel'] === 'boolean'
114
- ? schema['x-hideTryItPanel']
115
- : undefined,
116
- }];
117
- }
118
- });
119
- });
7
+ * Resolve an OpenAPI operation in a file and compile it to a more usable format.
8
+ */
9
+ async function resolveOpenAPIOperation(filesystem, operationDescriptor) {
10
+ const { path, method } = operationDescriptor;
11
+ const schema = await dereferenceFilesystem(filesystem);
12
+ let operation = getOperationByPathAndMethod(schema, path, method);
13
+ if (!operation) return null;
14
+ const commonParameters = getPathObjectParameter(schema, path);
15
+ if (commonParameters) operation = {
16
+ ...operation,
17
+ parameters: [...commonParameters, ...operation.parameters ?? []]
18
+ };
19
+ const servers = "servers" in schema ? schema.servers ?? [] : [];
20
+ const schemaSecurity = Array.isArray(schema.security) ? schema.security : schema.security ? [schema.security] : [];
21
+ const security = operation.security ?? schemaSecurity;
22
+ const isOptionalSecurity = security.some((entry) => Object.keys(entry).length === 0);
23
+ const flatSecurities = flattenSecurities(security);
24
+ const securities = [];
25
+ for (const entry of flatSecurities) {
26
+ const [securityKey, operationScopes] = Object.entries(entry)[0] ?? [];
27
+ if (securityKey) {
28
+ const securityScheme = schema.components?.securitySchemes?.[securityKey];
29
+ const scopes = resolveSecurityScopes({
30
+ securityScheme,
31
+ operationScopes
32
+ });
33
+ securities.push([securityKey, {
34
+ ...securityScheme,
35
+ required: !isOptionalSecurity,
36
+ scopes
37
+ }]);
38
+ }
39
+ }
40
+ return {
41
+ servers,
42
+ operation: {
43
+ ...operation,
44
+ security
45
+ },
46
+ method,
47
+ path,
48
+ securities,
49
+ "x-codeSamples": typeof schema["x-codeSamples"] === "boolean" ? schema["x-codeSamples"] : void 0,
50
+ "x-hideTryItPanel": typeof schema["x-hideTryItPanel"] === "boolean" ? schema["x-hideTryItPanel"] : void 0
51
+ };
120
52
  }
121
53
  /**
122
- * Get a path object from its path.
123
- */
54
+ * Get a path object from its path.
55
+ */
124
56
  function getPathObject(schema, path) {
125
- var _a;
126
- if ((_a = schema.paths) === null || _a === void 0 ? void 0 : _a[path]) {
127
- return schema.paths[path];
128
- }
129
- return null;
57
+ return schema.paths?.[path] || null;
130
58
  }
131
59
  /**
132
- * Resolve parameters from a path in an OpenAPI schema.
133
- */
60
+ * Resolve parameters from a path in an OpenAPI schema.
61
+ */
134
62
  function getPathObjectParameter(schema, path) {
135
- var pathObject = getPathObject(schema, path);
136
- if (pathObject === null || pathObject === void 0 ? void 0 : pathObject.parameters) {
137
- return pathObject.parameters;
138
- }
139
- return null;
63
+ const pathObject = getPathObject(schema, path);
64
+ if (pathObject?.parameters) return pathObject.parameters;
65
+ return null;
140
66
  }
141
67
  /**
142
- * Get an operation by its path and method.
143
- */
68
+ * Get an operation by its path and method.
69
+ */
144
70
  function getOperationByPathAndMethod(schema, path, method) {
145
- // Types are buffy for OpenAPIV3_1.OperationObject, so we use v3
146
- var pathObject = getPathObject(schema, path);
147
- if (!pathObject) {
148
- return null;
149
- }
150
- var normalizedMethod = method.toLowerCase();
151
- if (!pathObject[normalizedMethod]) {
152
- return null;
153
- }
154
- return pathObject[normalizedMethod];
71
+ const pathObject = getPathObject(schema, path);
72
+ if (!pathObject) return null;
73
+ const normalizedMethod = method.toLowerCase();
74
+ if (!pathObject[normalizedMethod]) return null;
75
+ return pathObject[normalizedMethod];
155
76
  }
156
77
  /**
157
- * Flatten security objects in case they are nested.
158
- * @example [{bearerAuth:[], basicAuth:[]}] => [{ bearerAuth: [] }, { basicAuth: [] }]
159
- */
78
+ * Flatten security objects in case they are nested.
79
+ * @example [{bearerAuth:[], basicAuth:[]}] => [{ bearerAuth: [] }, { basicAuth: [] }]
80
+ */
160
81
  function flattenSecurities(security) {
161
- if (!Array.isArray(security) || security.length === 0) {
162
- return [];
163
- }
164
- return security.flatMap(function (securityObject) {
165
- return Object.entries(securityObject).map(function (_a) {
166
- var _b;
167
- var authType = _a[0], config = _a[1];
168
- return (_b = {},
169
- _b[authType] = config,
170
- _b);
171
- });
172
- });
82
+ if (!Array.isArray(security) || security.length === 0) return [];
83
+ return security.flatMap((securityObject) => {
84
+ return Object.entries(securityObject).map(([authType, config]) => ({ [authType]: config }));
85
+ });
173
86
  }
87
+ /**
88
+ * Resolve the scopes for a security scheme.
89
+ */
90
+ function resolveSecurityScopes({ securityScheme, operationScopes }) {
91
+ if (!securityScheme || checkIsReference(securityScheme) || isOAuthSecurityScheme(securityScheme)) return null;
92
+ return operationScopes?.map((scope) => [scope, void 0]) || [];
93
+ }
94
+ /**
95
+ * Check if a security scheme is an OAuth or OpenID Connect security scheme.
96
+ */
97
+ function isOAuthSecurityScheme(securityScheme) {
98
+ return securityScheme.type === "oauth2";
99
+ }
100
+
101
+ //#endregion
102
+ export { resolveOpenAPIOperation };
@@ -1,11 +1,15 @@
1
- import { fromJSON, toJSON } from 'flatted';
2
- import type { Filesystem, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
3
- import type { OpenAPIWebhookData } from './types';
4
- export { fromJSON, toJSON };
1
+ import { OpenAPIWebhookData } from "./types.js";
2
+ import { Filesystem, OpenAPIV3xDocument } from "@gitbook/openapi-parser";
3
+ import "flatted";
4
+
5
+ //#region src/resolveOpenAPIWebhook.d.ts
6
+
5
7
  /**
6
8
  * Resolve an OpenAPI webhook in a file and compile it to a more usable format.
7
9
  */
8
- export declare function resolveOpenAPIWebhook(filesystem: Filesystem<OpenAPIV3xDocument>, webhookDescriptor: {
9
- name: string;
10
- method: string;
10
+ declare function resolveOpenAPIWebhook(filesystem: Filesystem<OpenAPIV3xDocument>, webhookDescriptor: {
11
+ name: string;
12
+ method: string;
11
13
  }): Promise<OpenAPIWebhookData | null>;
14
+ //#endregion
15
+ export { resolveOpenAPIWebhook };
@@ -1,127 +1,52 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- 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);
23
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- 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;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
- if (ar || !(i in from)) {
51
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
- ar[i] = from[i];
53
- }
54
- }
55
- return to.concat(ar || Array.prototype.slice.call(from));
56
- };
57
- import { fromJSON, toJSON } from 'flatted';
58
- import { dereferenceFilesystem } from './dereference';
59
- export { fromJSON, toJSON };
1
+ import { dereferenceFilesystem } from "./dereference.js";
2
+ import "flatted";
3
+
4
+ //#region src/resolveOpenAPIWebhook.ts
60
5
  /**
61
- * Resolve an OpenAPI webhook in a file and compile it to a more usable format.
62
- */
63
- export function resolveOpenAPIWebhook(filesystem, webhookDescriptor) {
64
- return __awaiter(this, void 0, void 0, function () {
65
- var name, method, schema, operation, commonParameters, servers;
66
- var _a, _b;
67
- return __generator(this, function (_c) {
68
- switch (_c.label) {
69
- case 0:
70
- name = webhookDescriptor.name, method = webhookDescriptor.method;
71
- return [4 /*yield*/, dereferenceFilesystem(filesystem)];
72
- case 1:
73
- schema = _c.sent();
74
- operation = getWebhookByNameAndMethod(schema, name, method);
75
- if (!operation) {
76
- return [2 /*return*/, null];
77
- }
78
- commonParameters = getPathObjectParameter(schema, name);
79
- if (commonParameters) {
80
- operation = __assign(__assign({}, operation), { parameters: __spreadArray(__spreadArray([], commonParameters, true), ((_a = operation.parameters) !== null && _a !== void 0 ? _a : []), true) });
81
- }
82
- servers = 'servers' in schema ? ((_b = schema.servers) !== null && _b !== void 0 ? _b : []) : [];
83
- return [2 /*return*/, {
84
- servers: servers,
85
- operation: operation,
86
- method: method,
87
- name: name,
88
- }];
89
- }
90
- });
91
- });
6
+ * Resolve an OpenAPI webhook in a file and compile it to a more usable format.
7
+ */
8
+ async function resolveOpenAPIWebhook(filesystem, webhookDescriptor) {
9
+ const { name, method } = webhookDescriptor;
10
+ const schema = await dereferenceFilesystem(filesystem);
11
+ let operation = getWebhookByNameAndMethod(schema, name, method);
12
+ if (!operation) return null;
13
+ const commonParameters = getPathObjectParameter(schema, name);
14
+ if (commonParameters) operation = {
15
+ ...operation,
16
+ parameters: [...commonParameters, ...operation.parameters ?? []]
17
+ };
18
+ return {
19
+ servers: "servers" in schema ? schema.servers ?? [] : [],
20
+ operation,
21
+ method,
22
+ name
23
+ };
92
24
  }
93
25
  /**
94
- * Get a path object from its path.
95
- */
26
+ * Get a path object from its path.
27
+ */
96
28
  function getPathObject(schema, name) {
97
- var _a;
98
- if ((_a = schema.webhooks) === null || _a === void 0 ? void 0 : _a[name]) {
99
- return schema.webhooks[name];
100
- }
101
- return null;
29
+ if (schema.webhooks?.[name]) return schema.webhooks[name];
30
+ return null;
102
31
  }
103
32
  /**
104
- * Resolve parameters from a path in an OpenAPI schema.
105
- */
33
+ * Resolve parameters from a path in an OpenAPI schema.
34
+ */
106
35
  function getPathObjectParameter(schema, path) {
107
- var pathObject = getPathObject(schema, path);
108
- if (pathObject === null || pathObject === void 0 ? void 0 : pathObject.parameters) {
109
- return pathObject.parameters;
110
- }
111
- return null;
36
+ const pathObject = getPathObject(schema, path);
37
+ if (pathObject?.parameters) return pathObject.parameters;
38
+ return null;
112
39
  }
113
40
  /**
114
- * Get an operation by its path and method.
115
- */
41
+ * Get an operation by its path and method.
42
+ */
116
43
  function getWebhookByNameAndMethod(schema, name, method) {
117
- // Types are buffy for OpenAPIV3_1.OperationObject, so we use v3
118
- var pathObject = getPathObject(schema, name);
119
- if (!pathObject) {
120
- return null;
121
- }
122
- var normalizedMethod = method.toLowerCase();
123
- if (!pathObject[normalizedMethod]) {
124
- return null;
125
- }
126
- return pathObject[normalizedMethod];
44
+ const pathObject = getPathObject(schema, name);
45
+ if (!pathObject) return null;
46
+ const normalizedMethod = method.toLowerCase();
47
+ if (!pathObject[normalizedMethod]) return null;
48
+ return pathObject[normalizedMethod];
127
49
  }
50
+
51
+ //#endregion
52
+ export { resolveOpenAPIWebhook };
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+
3
+
4
+ import { OpenAPIDisclosure } from "../OpenAPIDisclosure.js";
5
+ import { getDisclosureLabel } from "../getDisclosureLabel.js";
6
+ import { OpenAPIRootSchema } from "../OpenAPISchemaServer.js";
7
+ import { Section, SectionBody } from "../StaticSection.js";
8
+
9
+ //#region src/schemas/OpenAPISchemaItem.tsx
10
+ function OpenAPISchemaItem(props) {
11
+ const { schema, context, name } = props;
12
+ return <OpenAPIDisclosure className="openapi-schemas-disclosure" key={name} icon={context.icons.plus} header={name} label={(isExpanded) => getDisclosureLabel({
13
+ schema,
14
+ isExpanded,
15
+ context
16
+ })}>
17
+ <Section className="openapi-section-schemas">
18
+ <SectionBody>
19
+ <OpenAPIRootSchema schema={schema} context={context} />
20
+ </SectionBody>
21
+ </Section>
22
+ </OpenAPIDisclosure>;
23
+ }
24
+
25
+ //#endregion
26
+ export { OpenAPISchemaItem };
@@ -1,14 +1,19 @@
1
- import type { OpenAPISchema } from '@gitbook/openapi-parser';
2
- import { type OpenAPIContextInput } from '../context';
1
+ import { OpenAPIContextInput } from "../context.js";
2
+ import * as react2 from "react";
3
+ import { OpenAPISchema } from "@gitbook/openapi-parser";
4
+
5
+ //#region src/schemas/OpenAPISchemas.d.ts
3
6
  /**
4
7
  * OpenAPI Schemas component.
5
8
  */
6
- export declare function OpenAPISchemas(props: {
7
- className?: string;
8
- schemas: OpenAPISchema[];
9
- context: OpenAPIContextInput;
10
- /**
11
- * Whether to show the schema directly if there is only one.
12
- */
13
- grouped?: boolean;
14
- }): import("react").JSX.Element | null;
9
+ declare function OpenAPISchemas(props: {
10
+ className?: string;
11
+ schemas: OpenAPISchema[];
12
+ context: OpenAPIContextInput;
13
+ /**
14
+ * Whether to show the schema directly if there is only one.
15
+ */
16
+ grouped?: boolean;
17
+ }): react2.JSX.Element | null;
18
+ //#endregion
19
+ export { OpenAPISchemas };