@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,342 +1,198 @@
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
- if (ar || !(i in from)) {
15
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
- ar[i] = from[i];
17
- }
18
- }
19
- return to.concat(ar || Array.prototype.slice.call(from));
20
- };
21
- var _a, _b, _c;
22
- import { checkIsReference } from './utils';
1
+ import { checkIsReference } from "./utils.js";
2
+
3
+ //#region src/generateSchemaExample.ts
23
4
  /**
24
- * Generate a JSON example from a schema
25
- */
26
- export function generateSchemaExample(schema, options) {
27
- return getExampleFromSchema(schema, __assign({ emptyString: 'text' }, options));
5
+ * Generate a JSON example from a schema
6
+ */
7
+ function generateSchemaExample(schema, options) {
8
+ return getExampleFromSchema(schema, {
9
+ emptyString: "text",
10
+ ...options
11
+ });
28
12
  }
29
13
  /**
30
- * Generate an example for a media type.
31
- */
32
- export function generateMediaTypeExamples(mediaType, options) {
33
- if (mediaType.example) {
34
- return [{ summary: 'default', value: mediaType.example }];
35
- }
36
- if (mediaType.examples) {
37
- var examples_1 = mediaType.examples;
38
- var keys = Object.keys(examples_1);
39
- if (keys.length > 0) {
40
- return keys.reduce(function (result, key) {
41
- var example = examples_1[key];
42
- if (!example || checkIsReference(example)) {
43
- return result;
44
- }
45
- result.push({
46
- summary: example.summary || key,
47
- value: example.value,
48
- description: example.description,
49
- externalValue: example.externalValue,
50
- });
51
- return result;
52
- }, []);
53
- }
54
- }
55
- if (mediaType.schema) {
56
- return [{ summary: 'default', value: generateSchemaExample(mediaType.schema, options) }];
57
- }
58
- return [];
14
+ * Generate an example for a media type.
15
+ */
16
+ function generateMediaTypeExamples(mediaType, options) {
17
+ if (mediaType.example) return [{
18
+ summary: "default",
19
+ value: mediaType.example
20
+ }];
21
+ if (mediaType.examples) {
22
+ const { examples } = mediaType;
23
+ const keys = Object.keys(examples);
24
+ if (keys.length > 0) return keys.reduce((result, key) => {
25
+ const example = examples[key];
26
+ if (!example || checkIsReference(example)) return result;
27
+ result.push({
28
+ summary: example.summary || key,
29
+ value: example.value,
30
+ description: example.description,
31
+ externalValue: example.externalValue
32
+ });
33
+ return result;
34
+ }, []);
35
+ }
36
+ if (mediaType.schema) return [{
37
+ summary: "default",
38
+ value: generateSchemaExample(mediaType.schema, options)
39
+ }];
40
+ return [];
59
41
  }
60
42
  /** Hard limit for rendering circular references */
61
- var MAX_LEVELS_DEEP = 5;
62
- var genericExampleValues = {
63
- 'date-time': new Date().toISOString(),
64
- date: (_a = new Date().toISOString().split('T')[0]) !== null && _a !== void 0 ? _a : '1970-01-01',
65
- email: 'name@gmail.com',
66
- hostname: 'example.com',
67
- ipv4: '0.0.0.0',
68
- ipv6: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
69
- uri: 'https://example.com',
70
- uuid: '123e4567-e89b-12d3-a456-426614174000',
71
- binary: 'binary',
72
- byte: 'Ynl0ZXM=',
73
- password: 'password',
74
- 'idn-email': 'jane.doe@example.com',
75
- 'idn-hostname': 'example.com',
76
- 'iri-reference': '/entitiy/1',
77
- // https://tools.ietf.org/html/rfc3987
78
- iri: 'https://example.com/entity/123',
79
- 'json-pointer': '/nested/objects',
80
- regex: '/[a-z]/',
81
- // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01
82
- 'relative-json-pointer': '1/nested/objects',
83
- // full-time in https://tools.ietf.org/html/rfc3339#section-5.6
84
- time: (_c = (_b = new Date().toISOString().split('T')[1]) === null || _b === void 0 ? void 0 : _b.split('.')[0]) !== null && _c !== void 0 ? _c : '00:00:00Z',
85
- // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1
86
- 'uri-reference': '../folder',
87
- 'uri-template': 'https://example.com/{id}',
88
- 'object-id': '6592008029c8c3e4dc76256c',
43
+ const MAX_LEVELS_DEEP = 5;
44
+ const genericExampleValues = {
45
+ "date-time": (/* @__PURE__ */ new Date()).toISOString(),
46
+ date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "1970-01-01",
47
+ email: "name@gmail.com",
48
+ hostname: "example.com",
49
+ ipv4: "0.0.0.0",
50
+ ipv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
51
+ uri: "https://example.com",
52
+ uuid: "123e4567-e89b-12d3-a456-426614174000",
53
+ binary: "binary",
54
+ byte: "Ynl0ZXM=",
55
+ password: "password",
56
+ "idn-email": "jane.doe@example.com",
57
+ "idn-hostname": "example.com",
58
+ "iri-reference": "/entitiy/1",
59
+ iri: "https://example.com/entity/123",
60
+ "json-pointer": "/nested/objects",
61
+ regex: "/[a-z]/",
62
+ "relative-json-pointer": "1/nested/objects",
63
+ time: (/* @__PURE__ */ new Date()).toISOString().split("T")[1]?.split(".")[0] ?? "00:00:00Z",
64
+ "uri-reference": "../folder",
65
+ "uri-template": "https://example.com/{id}",
66
+ "object-id": "6592008029c8c3e4dc76256c"
89
67
  };
90
68
  /**
91
- * We can use the `format` to generate some random values.
92
- */
93
- function guessFromFormat(schema, fallback) {
94
- var _a;
95
- if (fallback === void 0) { fallback = ''; }
96
- return (_a = genericExampleValues[schema.format]) !== null && _a !== void 0 ? _a : fallback;
69
+ * We can use the `format` to generate some random values.
70
+ */
71
+ function guessFromFormat(schema, fallback = "") {
72
+ return genericExampleValues[schema.format] ?? fallback;
97
73
  }
98
74
  /**
99
- * This function takes an OpenAPI schema and generates an example from it
100
- * Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts
101
- */
102
- var getExampleFromSchema = function (schema, options, level, parentSchema, name, resultCache) {
103
- var _a, _b, _c, _d;
104
- var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
105
- if (level === void 0) { level = 0; }
106
- if (resultCache === void 0) { resultCache = new WeakMap(); }
107
- // Store result in the cache, and return the result
108
- function cache(schema, result) {
109
- // Avoid unnecessary WeakMap operations for primitive values
110
- if (typeof result !== 'object' || result === null) {
111
- return result;
112
- }
113
- resultCache.set(schema, result);
114
- return result;
115
- }
116
- // Check if the result is already cached
117
- if (resultCache.has(schema)) {
118
- return resultCache.get(schema);
119
- }
120
- // Check whether it’s a circular reference
121
- if (level === MAX_LEVELS_DEEP + 1) {
122
- try {
123
- // Fails if it contains a circular reference
124
- JSON.stringify(schema);
125
- }
126
- catch (_w) {
127
- return '[Circular Reference]';
128
- }
129
- }
130
- // Sometimes, we just want the structure and no values.
131
- // But if `emptyString` is set, we do want to see some values.
132
- var makeUpRandomData = !!(options === null || options === void 0 ? void 0 : options.emptyString);
133
- // If the property is deprecated we don't show it in examples.
134
- if (schema.deprecated || (schema.type === 'array' && ((_e = schema.items) === null || _e === void 0 ? void 0 : _e.deprecated))) {
135
- return undefined;
136
- }
137
- // Check if the property is read-only/write-only
138
- if (((options === null || options === void 0 ? void 0 : options.mode) === 'write' && schema.readOnly) ||
139
- ((options === null || options === void 0 ? void 0 : options.mode) === 'read' && schema.writeOnly)) {
140
- return undefined;
141
- }
142
- // Use given variables as values
143
- if (schema['x-variable']) {
144
- var value = (_f = options === null || options === void 0 ? void 0 : options.variables) === null || _f === void 0 ? void 0 : _f[schema['x-variable']];
145
- // Return the value if it’s defined
146
- if (value !== undefined) {
147
- // Type-casting
148
- if (schema.type === 'number' || schema.type === 'integer') {
149
- return Number.parseInt(value, 10);
150
- }
151
- return cache(schema, value);
152
- }
153
- }
154
- // Use the first example, if there’s an array
155
- if (Array.isArray(schema.examples) && schema.examples.length > 0) {
156
- return cache(schema, schema.examples[0]);
157
- }
158
- // Use an example, if there’s one
159
- if (schema.example !== undefined) {
160
- return cache(schema, schema.example);
161
- }
162
- // Use a default value, if there’s one and it’s a string or number
163
- if (schema.default !== undefined &&
164
- ['string', 'number', 'boolean'].includes(typeof schema.default)) {
165
- return cache(schema, schema.default);
166
- }
167
- // enum: [ 'available', 'pending', 'sold' ]
168
- if (Array.isArray(schema.enum) && schema.enum.length > 0) {
169
- return cache(schema, schema.enum[0]);
170
- }
171
- // Check if the property is required
172
- var isObjectOrArray = schema.type === 'object' ||
173
- schema.type === 'array' ||
174
- !!((_h = (_g = schema.allOf) === null || _g === void 0 ? void 0 : _g.at) === null || _h === void 0 ? void 0 : _h.call(_g, 0)) ||
175
- !!((_k = (_j = schema.anyOf) === null || _j === void 0 ? void 0 : _j.at) === null || _k === void 0 ? void 0 : _k.call(_j, 0)) ||
176
- !!((_m = (_l = schema.oneOf) === null || _l === void 0 ? void 0 : _l.at) === null || _m === void 0 ? void 0 : _m.call(_l, 0));
177
- if (!isObjectOrArray && (options === null || options === void 0 ? void 0 : options.omitEmptyAndOptionalProperties) === true) {
178
- var isRequired = schema.required === true ||
179
- (parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.required) === true ||
180
- ((_o = parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.required) === null || _o === void 0 ? void 0 : _o.includes(name !== null && name !== void 0 ? name : schema.name));
181
- if (!isRequired) {
182
- return undefined;
183
- }
184
- }
185
- // Object
186
- if (schema.type === 'object' || schema.properties !== undefined) {
187
- var response = {};
188
- // Regular properties
189
- if (schema.properties !== undefined) {
190
- for (var propertyName in schema.properties) {
191
- if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
192
- var property = schema.properties[propertyName];
193
- var propertyXmlTagName = (options === null || options === void 0 ? void 0 : options.xml) ? (_p = property.xml) === null || _p === void 0 ? void 0 : _p.name : undefined;
194
- response[propertyXmlTagName !== null && propertyXmlTagName !== void 0 ? propertyXmlTagName : propertyName] = getExampleFromSchema(property, options, level + 1, schema, propertyName, resultCache);
195
- if (typeof response[propertyXmlTagName !== null && propertyXmlTagName !== void 0 ? propertyXmlTagName : propertyName] === 'undefined') {
196
- delete response[propertyXmlTagName !== null && propertyXmlTagName !== void 0 ? propertyXmlTagName : propertyName];
197
- }
198
- }
199
- }
200
- }
201
- // Pattern properties (regex)
202
- if (schema.patternProperties !== undefined) {
203
- for (var pattern in schema.patternProperties) {
204
- if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {
205
- var property = schema.patternProperties[pattern];
206
- // Use the regex pattern as an example key
207
- var exampleKey = pattern;
208
- response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey, resultCache);
209
- }
210
- }
211
- }
212
- // Additional properties
213
- if (schema.additionalProperties !== undefined) {
214
- var anyTypeIsValid =
215
- // true
216
- schema.additionalProperties === true ||
217
- // or an empty object {}
218
- (typeof schema.additionalProperties === 'object' &&
219
- !Object.keys(schema.additionalProperties).length);
220
- if (anyTypeIsValid) {
221
- response.ANY_ADDITIONAL_PROPERTY = 'anything';
222
- }
223
- else if (schema.additionalProperties !== false) {
224
- response.ANY_ADDITIONAL_PROPERTY = getExampleFromSchema(schema.additionalProperties, options, level + 1, undefined, undefined, resultCache);
225
- }
226
- }
227
- if (schema.anyOf !== undefined) {
228
- Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1, undefined, undefined, resultCache));
229
- }
230
- else if (schema.oneOf !== undefined) {
231
- Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1, undefined, undefined, resultCache));
232
- }
233
- else if (schema.allOf !== undefined) {
234
- Object.assign.apply(Object, __spreadArray([response], schema.allOf
235
- .map(function (item) {
236
- return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
237
- })
238
- .filter(function (item) { return item !== undefined; }), false));
239
- }
240
- return cache(schema, response);
241
- }
242
- // Array
243
- if (schema.type === 'array' || schema.items !== undefined) {
244
- var itemsXmlTagName_1 = (_r = (_q = schema === null || schema === void 0 ? void 0 : schema.items) === null || _q === void 0 ? void 0 : _q.xml) === null || _r === void 0 ? void 0 : _r.name;
245
- var wrapItems = !!((options === null || options === void 0 ? void 0 : options.xml) && ((_s = schema.xml) === null || _s === void 0 ? void 0 : _s.wrapped) && itemsXmlTagName_1);
246
- if (schema.example !== undefined) {
247
- return cache(schema, wrapItems ? (_a = {}, _a[itemsXmlTagName_1] = schema.example, _a) : schema.example);
248
- }
249
- // Check whether the array has a anyOf, oneOf, or allOf rule
250
- if (schema.items) {
251
- // First handle allOf separately since it needs special handling
252
- if (schema.items.allOf) {
253
- // If the first item is an object type, merge all schemas
254
- if (schema.items.allOf[0].type === 'object') {
255
- var mergedExample = getExampleFromSchema({ type: 'object', allOf: schema.items.allOf }, options, level + 1, schema, undefined, resultCache);
256
- return cache(schema, wrapItems ? [(_b = {}, _b[itemsXmlTagName_1] = mergedExample, _b)] : [mergedExample]);
257
- }
258
- // For non-objects (like strings), collect all examples
259
- var examples = schema.items.allOf
260
- .map(function (item) {
261
- return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
262
- })
263
- .filter(function (item) { return item !== undefined; });
264
- return cache(schema, wrapItems
265
- ? examples.map(function (example) {
266
- var _a;
267
- return (_a = {}, _a[itemsXmlTagName_1] = example, _a);
268
- })
269
- : examples);
270
- }
271
- // Handle other rules (anyOf, oneOf)
272
- var rules = ['anyOf', 'oneOf'];
273
- for (var _i = 0, rules_1 = rules; _i < rules_1.length; _i++) {
274
- var rule = rules_1[_i];
275
- if (!schema.items[rule]) {
276
- continue;
277
- }
278
- var schemas = schema.items[rule].slice(0, 1);
279
- var exampleFromRule = schemas
280
- .map(function (item) {
281
- return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
282
- })
283
- .filter(function (item) { return item !== undefined; });
284
- return cache(schema, wrapItems ? [(_c = {}, _c[itemsXmlTagName_1] = exampleFromRule, _c)] : exampleFromRule);
285
- }
286
- }
287
- if ((_t = schema.items) === null || _t === void 0 ? void 0 : _t.type) {
288
- var exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1, undefined, undefined, resultCache);
289
- return wrapItems ? [(_d = {}, _d[itemsXmlTagName_1] = exampleFromSchema, _d)] : [exampleFromSchema];
290
- }
291
- return [];
292
- }
293
- var exampleValues = {
294
- string: makeUpRandomData ? guessFromFormat(schema, options === null || options === void 0 ? void 0 : options.emptyString) : '',
295
- boolean: true,
296
- integer: (_u = schema.min) !== null && _u !== void 0 ? _u : 1,
297
- number: (_v = schema.min) !== null && _v !== void 0 ? _v : 1,
298
- array: [],
299
- };
300
- if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {
301
- return cache(schema, exampleValues[schema.type]);
302
- }
303
- var discriminateSchema = schema.oneOf || schema.anyOf;
304
- // Check if property has the `oneOf` | `anyOf` key
305
- if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
306
- // Get the first item from the `oneOf` | `anyOf` array
307
- var firstOneOfItem = discriminateSchema[0];
308
- // Return an example for the first item
309
- return getExampleFromSchema(firstOneOfItem, options, level + 1, undefined, undefined, resultCache);
310
- }
311
- // Check if schema has the `allOf` key
312
- if (Array.isArray(schema.allOf)) {
313
- var example_1 = null;
314
- // Loop through all `allOf` schemas
315
- schema.allOf.forEach(function (allOfItem) {
316
- // Return an example from the schema
317
- var newExample = getExampleFromSchema(allOfItem, options, level + 1, undefined, undefined, resultCache);
318
- // Merge or overwrite the example
319
- example_1 =
320
- typeof newExample === 'object' && typeof example_1 === 'object'
321
- ? __assign(__assign({}, (example_1 !== null && example_1 !== void 0 ? example_1 : {})), newExample) : Array.isArray(newExample) && Array.isArray(example_1)
322
- ? __spreadArray(__spreadArray([], (example_1 !== null && example_1 !== void 0 ? example_1 : {}), true), newExample, true) : newExample;
323
- });
324
- return cache(schema, example_1);
325
- }
326
- // Check if schema is a union type
327
- if (Array.isArray(schema.type)) {
328
- // Return null if the type is nullable
329
- if (schema.type.includes('null')) {
330
- return null;
331
- }
332
- // Return an example for the first type in the union
333
- var exampleValue = exampleValues[schema.type[0]];
334
- if (exampleValue !== undefined) {
335
- return cache(schema, exampleValue);
336
- }
337
- }
338
- // Warn if the type is unknown …
339
- // console.warn(`[getExampleFromSchema] Unknown property type "${schema.type}".`)
340
- // … and just return null for now.
341
- return null;
75
+ * This function takes an OpenAPI schema and generates an example from it
76
+ * Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts
77
+ */
78
+ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name, resultCache = /* @__PURE__ */ new WeakMap()) => {
79
+ function cache(schema$1, result) {
80
+ if (typeof result !== "object" || result === null) return result;
81
+ resultCache.set(schema$1, result);
82
+ return result;
83
+ }
84
+ if (resultCache.has(schema)) return resultCache.get(schema);
85
+ if (level === MAX_LEVELS_DEEP + 1) try {
86
+ JSON.stringify(schema);
87
+ } catch {
88
+ return "[Circular Reference]";
89
+ }
90
+ const makeUpRandomData = !!options?.emptyString;
91
+ if (schema.deprecated || schema.type === "array" && schema.items?.deprecated) return;
92
+ if (options?.mode === "write" && schema.readOnly || options?.mode === "read" && schema.writeOnly) return;
93
+ if (schema["x-variable"]) {
94
+ const value = options?.variables?.[schema["x-variable"]];
95
+ if (value !== void 0) {
96
+ if (schema.type === "number" || schema.type === "integer") return Number.parseInt(value, 10);
97
+ return cache(schema, value);
98
+ }
99
+ }
100
+ if (Array.isArray(schema.examples) && schema.examples.length > 0) return cache(schema, schema.examples[0]);
101
+ if (schema.example !== void 0) return cache(schema, schema.example);
102
+ if (schema.default !== void 0 && [
103
+ "string",
104
+ "number",
105
+ "boolean"
106
+ ].includes(typeof schema.default)) return cache(schema, schema.default);
107
+ if (Array.isArray(schema.enum) && schema.enum.length > 0) return cache(schema, schema.enum[0]);
108
+ if (!(schema.type === "object" || schema.type === "array" || !!schema.allOf?.at?.(0) || !!schema.anyOf?.at?.(0) || !!schema.oneOf?.at?.(0)) && options?.omitEmptyAndOptionalProperties === true) {
109
+ if (!(schema.required === true || parentSchema?.required === true || parentSchema?.required?.includes(name ?? schema.name))) return;
110
+ }
111
+ if (schema.type === "object" || schema.properties !== void 0) {
112
+ const response = {};
113
+ if (schema.properties !== void 0) {
114
+ for (const propertyName in schema.properties) if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
115
+ const property = schema.properties[propertyName];
116
+ const propertyXmlTagName = options?.xml ? property.xml?.name : void 0;
117
+ response[propertyXmlTagName ?? propertyName] = getExampleFromSchema(property, options, level + 1, schema, propertyName, resultCache);
118
+ if (typeof response[propertyXmlTagName ?? propertyName] === "undefined") delete response[propertyXmlTagName ?? propertyName];
119
+ }
120
+ }
121
+ if (schema.patternProperties !== void 0) {
122
+ for (const pattern in schema.patternProperties) if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {
123
+ const property = schema.patternProperties[pattern];
124
+ const exampleKey = pattern;
125
+ response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey, resultCache);
126
+ }
127
+ }
128
+ if (schema.additionalProperties !== void 0) {
129
+ if (schema.additionalProperties === true || typeof schema.additionalProperties === "object" && !Object.keys(schema.additionalProperties).length) response.ANY_ADDITIONAL_PROPERTY = "anything";
130
+ else if (schema.additionalProperties !== false) response.ANY_ADDITIONAL_PROPERTY = getExampleFromSchema(schema.additionalProperties, options, level + 1, void 0, void 0, resultCache);
131
+ }
132
+ if (schema.anyOf !== void 0) Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1, void 0, void 0, resultCache));
133
+ else if (schema.oneOf !== void 0) Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1, void 0, void 0, resultCache));
134
+ else if (schema.allOf !== void 0) Object.assign(response, ...schema.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema, void 0, resultCache)).filter((item) => item !== void 0));
135
+ return cache(schema, response);
136
+ }
137
+ if (schema.type === "array" || schema.items !== void 0) {
138
+ const itemsXmlTagName = schema?.items?.xml?.name;
139
+ const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName);
140
+ if (schema.example !== void 0) return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example);
141
+ if (schema.items) {
142
+ if (schema.items.allOf) {
143
+ if (schema.items.allOf[0].type === "object") {
144
+ const mergedExample = getExampleFromSchema({
145
+ type: "object",
146
+ allOf: schema.items.allOf
147
+ }, options, level + 1, schema, void 0, resultCache);
148
+ return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample]);
149
+ }
150
+ const examples = schema.items.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema, void 0, resultCache)).filter((item) => item !== void 0);
151
+ return cache(schema, wrapItems ? examples.map((example) => ({ [itemsXmlTagName]: example })) : examples);
152
+ }
153
+ for (const rule of ["anyOf", "oneOf"]) {
154
+ if (!schema.items[rule]) continue;
155
+ const exampleFromRule = schema.items[rule].slice(0, 1).map((item) => getExampleFromSchema(item, options, level + 1, schema, void 0, resultCache)).filter((item) => item !== void 0);
156
+ return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule);
157
+ }
158
+ }
159
+ if (schema.items?.type) {
160
+ const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1, void 0, void 0, resultCache);
161
+ return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
162
+ }
163
+ return [];
164
+ }
165
+ const exampleValues = {
166
+ string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : "",
167
+ boolean: true,
168
+ integer: schema.min ?? 1,
169
+ number: schema.min ?? 1,
170
+ array: []
171
+ };
172
+ if (schema.type !== void 0 && exampleValues[schema.type] !== void 0) return cache(schema, exampleValues[schema.type]);
173
+ const discriminateSchema = schema.oneOf || schema.anyOf;
174
+ if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
175
+ const firstOneOfItem = discriminateSchema[0];
176
+ return getExampleFromSchema(firstOneOfItem, options, level + 1, void 0, void 0, resultCache);
177
+ }
178
+ if (Array.isArray(schema.allOf)) {
179
+ let example = null;
180
+ schema.allOf.forEach((allOfItem) => {
181
+ const newExample = getExampleFromSchema(allOfItem, options, level + 1, void 0, void 0, resultCache);
182
+ example = typeof newExample === "object" && typeof example === "object" ? {
183
+ ...example ?? {},
184
+ ...newExample
185
+ } : Array.isArray(newExample) && Array.isArray(example) ? [...example ?? {}, ...newExample] : newExample;
186
+ });
187
+ return cache(schema, example);
188
+ }
189
+ if (Array.isArray(schema.type)) {
190
+ if (schema.type.includes("null")) return null;
191
+ const exampleValue = exampleValues[schema.type[0]];
192
+ if (exampleValue !== void 0) return cache(schema, exampleValue);
193
+ }
194
+ return null;
342
195
  };
196
+
197
+ //#endregion
198
+ export { generateMediaTypeExamples, generateSchemaExample };
@@ -1,18 +1,17 @@
1
1
  'use client';
2
- import { tString } from './translate';
3
- export function getDisclosureLabel(props) {
4
- var schema = props.schema, isExpanded = props.isExpanded, context = props.context;
5
- var label;
6
- if (schema.type === 'array' && !!schema.items) {
7
- if (schema.items.oneOf) {
8
- label = tString(context.translation, 'available_items').toLowerCase();
9
- }
10
- else {
11
- label = tString(context.translation, 'properties').toLowerCase();
12
- }
13
- }
14
- else {
15
- label = tString(context.translation, 'properties').toLowerCase();
16
- }
17
- return tString(context.translation, isExpanded ? 'hide' : 'show', label);
2
+
3
+
4
+ import { tString } from "./translate.js";
5
+
6
+ //#region src/getDisclosureLabel.ts
7
+ function getDisclosureLabel(props) {
8
+ const { schema, isExpanded, context } = props;
9
+ let label;
10
+ if (schema.type === "array" && !!schema.items) if (schema.items.oneOf) label = tString(context.translation, "available_items").toLowerCase();
11
+ else label = tString(context.translation, "properties").toLowerCase();
12
+ else label = tString(context.translation, "properties").toLowerCase();
13
+ return tString(context.translation, isExpanded ? "hide" : "show", label);
18
14
  }
15
+
16
+ //#endregion
17
+ export { getDisclosureLabel };
@@ -1,19 +1,22 @@
1
- import { createStore } from 'zustand';
2
- var createStateStore = function (initial) {
3
- return createStore()(function (set) { return ({
4
- key: initial !== null && initial !== void 0 ? initial : null,
5
- setKey: function (key) {
6
- set(function () { return ({ key: key }); });
7
- },
8
- }); });
1
+ import { createStore } from "zustand";
2
+
3
+ //#region src/getOrCreateStoreByKey.ts
4
+ const createStateStore = (initial) => {
5
+ return createStore()((set) => ({
6
+ key: initial ?? null,
7
+ setKey: (key) => {
8
+ set(() => ({ key }));
9
+ }
10
+ }));
9
11
  };
10
- var defaultStores = new Map();
11
- var createStateStoreFactory = function (stores) {
12
- return function (storeKey, initialKey) {
13
- if (!stores.has(storeKey)) {
14
- stores.set(storeKey, createStateStore(initialKey));
15
- }
16
- return stores.get(storeKey);
17
- };
12
+ const defaultStores = /* @__PURE__ */ new Map();
13
+ const createStateStoreFactory = (stores) => {
14
+ return (storeKey, initialKey) => {
15
+ if (!stores.has(storeKey)) stores.set(storeKey, createStateStore(initialKey));
16
+ return stores.get(storeKey);
17
+ };
18
18
  };
19
- export var getOrCreateStoreByKey = createStateStoreFactory(defaultStores);
19
+ const getOrCreateStoreByKey = createStateStoreFactory(defaultStores);
20
+
21
+ //#endregion
22
+ export { getOrCreateStoreByKey };