fumadocs-openapi 10.2.2 → 10.2.4

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 (278) hide show
  1. package/dist/generate-file.d.ts +53 -49
  2. package/dist/generate-file.d.ts.map +1 -1
  3. package/dist/generate-file.js +88 -102
  4. package/dist/generate-file.js.map +1 -0
  5. package/dist/index.d.ts +6 -6
  6. package/dist/index.js +3 -1
  7. package/dist/playground/client.d.ts +88 -72
  8. package/dist/playground/client.d.ts.map +1 -1
  9. package/dist/playground/client.js +446 -296
  10. package/dist/playground/client.js.map +1 -0
  11. package/dist/playground/components/inputs.js +395 -172
  12. package/dist/playground/components/inputs.js.map +1 -0
  13. package/dist/playground/components/oauth-dialog.js +270 -174
  14. package/dist/playground/components/oauth-dialog.js.map +1 -0
  15. package/dist/playground/components/server-select.js +115 -55
  16. package/dist/playground/components/server-select.js.map +1 -0
  17. package/dist/playground/fetcher.d.ts +10 -18
  18. package/dist/playground/fetcher.d.ts.map +1 -1
  19. package/dist/playground/fetcher.js +67 -75
  20. package/dist/playground/fetcher.js.map +1 -0
  21. package/dist/playground/get-default-values.js +23 -26
  22. package/dist/playground/get-default-values.js.map +1 -0
  23. package/dist/playground/index.d.ts +23 -13
  24. package/dist/playground/index.d.ts.map +1 -1
  25. package/dist/playground/index.js +87 -91
  26. package/dist/playground/index.js.map +1 -0
  27. package/dist/playground/lazy.js +9 -2
  28. package/dist/playground/lazy.js.map +1 -0
  29. package/dist/playground/schema.d.ts +18 -55
  30. package/dist/playground/schema.d.ts.map +1 -1
  31. package/dist/playground/schema.js +117 -106
  32. package/dist/playground/schema.js.map +1 -0
  33. package/dist/playground/status-info.js +49 -37
  34. package/dist/playground/status-info.js.map +1 -0
  35. package/dist/requests/generators/csharp.js +40 -50
  36. package/dist/requests/generators/csharp.js.map +1 -0
  37. package/dist/requests/generators/curl.js +28 -27
  38. package/dist/requests/generators/curl.js.map +1 -0
  39. package/dist/requests/generators/go.js +39 -35
  40. package/dist/requests/generators/go.js.map +1 -0
  41. package/dist/requests/generators/index.js +49 -43
  42. package/dist/requests/generators/index.js.map +1 -0
  43. package/dist/requests/generators/java.js +56 -67
  44. package/dist/requests/generators/java.js.map +1 -0
  45. package/dist/requests/generators/javascript.js +38 -45
  46. package/dist/requests/generators/javascript.js.map +1 -0
  47. package/dist/requests/generators/python.js +33 -37
  48. package/dist/requests/generators/python.js.map +1 -0
  49. package/dist/requests/media/adapter.d.ts +38 -84
  50. package/dist/requests/media/adapter.d.ts.map +1 -1
  51. package/dist/requests/media/adapter.js +122 -169
  52. package/dist/requests/media/adapter.js.map +1 -0
  53. package/dist/requests/media/encode.d.ts +12 -7
  54. package/dist/requests/media/encode.d.ts.map +1 -1
  55. package/dist/requests/media/encode.js +131 -109
  56. package/dist/requests/media/encode.js.map +1 -0
  57. package/dist/requests/media/resolve-adapter.js +28 -28
  58. package/dist/requests/media/resolve-adapter.js.map +1 -0
  59. package/dist/requests/string-utils.js +28 -35
  60. package/dist/requests/string-utils.js.map +1 -0
  61. package/dist/requests/to-python-object.js +16 -28
  62. package/dist/requests/to-python-object.js.map +1 -0
  63. package/dist/requests/types.d.ts +25 -21
  64. package/dist/requests/types.d.ts.map +1 -1
  65. package/dist/scalar/client.js +57 -20
  66. package/dist/scalar/client.js.map +1 -0
  67. package/dist/scalar/index.d.ts +8 -2
  68. package/dist/scalar/index.d.ts.map +1 -1
  69. package/dist/scalar/index.js +29 -19
  70. package/dist/scalar/index.js.map +1 -0
  71. package/dist/server/create.d.ts +29 -25
  72. package/dist/server/create.d.ts.map +1 -1
  73. package/dist/server/create.js +42 -39
  74. package/dist/server/create.js.map +1 -0
  75. package/dist/server/index.d.ts +3 -3
  76. package/dist/server/index.js +4 -2
  77. package/dist/server/proxy.d.ts +28 -28
  78. package/dist/server/proxy.d.ts.map +1 -1
  79. package/dist/server/proxy.js +58 -75
  80. package/dist/server/proxy.js.map +1 -0
  81. package/dist/server/source-api.d.ts +32 -29
  82. package/dist/server/source-api.d.ts.map +1 -1
  83. package/dist/server/source-api.js +82 -75
  84. package/dist/server/source-api.js.map +1 -0
  85. package/dist/types.d.ts +41 -36
  86. package/dist/types.d.ts.map +1 -1
  87. package/dist/ui/api-page.d.ts +140 -136
  88. package/dist/ui/api-page.d.ts.map +1 -1
  89. package/dist/ui/api-page.js +134 -118
  90. package/dist/ui/api-page.js.map +1 -0
  91. package/dist/ui/client/index.d.ts +30 -26
  92. package/dist/ui/client/index.d.ts.map +1 -1
  93. package/dist/ui/client/index.js +8 -2
  94. package/dist/ui/client/index.js.map +1 -0
  95. package/dist/ui/client/storage-key.js +16 -10
  96. package/dist/ui/client/storage-key.js.map +1 -0
  97. package/dist/ui/components/accordion.js +40 -14
  98. package/dist/ui/components/accordion.js.map +1 -0
  99. package/dist/ui/components/dialog.js +51 -15
  100. package/dist/ui/components/dialog.js.map +1 -0
  101. package/dist/ui/components/input.js +18 -8
  102. package/dist/ui/components/input.js.map +1 -0
  103. package/dist/ui/components/method-label.js +38 -33
  104. package/dist/ui/components/method-label.js.map +1 -0
  105. package/dist/ui/components/select.js +66 -15
  106. package/dist/ui/components/select.js.map +1 -0
  107. package/dist/ui/contexts/api.js +96 -85
  108. package/dist/ui/contexts/api.js.map +1 -0
  109. package/dist/ui/contexts/api.lazy.js +9 -2
  110. package/dist/ui/contexts/api.lazy.js.map +1 -0
  111. package/dist/ui/index.d.ts +2 -2
  112. package/dist/ui/index.js +3 -1
  113. package/dist/ui/operation/client.js +65 -27
  114. package/dist/ui/operation/client.js.map +1 -0
  115. package/dist/ui/operation/index.js +403 -186
  116. package/dist/ui/operation/index.js.map +1 -0
  117. package/dist/ui/operation/request-tabs.d.ts +15 -16
  118. package/dist/ui/operation/request-tabs.d.ts.map +1 -1
  119. package/dist/ui/operation/request-tabs.js +151 -131
  120. package/dist/ui/operation/request-tabs.js.map +1 -0
  121. package/dist/ui/operation/response-tabs.d.ts +27 -28
  122. package/dist/ui/operation/response-tabs.d.ts.map +1 -1
  123. package/dist/ui/operation/response-tabs.js +73 -56
  124. package/dist/ui/operation/response-tabs.js.map +1 -0
  125. package/dist/ui/operation/usage-tabs/client.js +117 -88
  126. package/dist/ui/operation/usage-tabs/client.js.map +1 -0
  127. package/dist/ui/operation/usage-tabs/index.d.ts +22 -21
  128. package/dist/ui/operation/usage-tabs/index.d.ts.map +1 -1
  129. package/dist/ui/operation/usage-tabs/index.js +63 -48
  130. package/dist/ui/operation/usage-tabs/index.js.map +1 -0
  131. package/dist/ui/operation/usage-tabs/lazy.js +11 -4
  132. package/dist/ui/operation/usage-tabs/lazy.js.map +1 -0
  133. package/dist/ui/schema/client.d.ts +11 -7
  134. package/dist/ui/schema/client.d.ts.map +1 -1
  135. package/dist/ui/schema/client.js +213 -127
  136. package/dist/ui/schema/client.js.map +1 -0
  137. package/dist/ui/schema/index.d.ts +51 -50
  138. package/dist/ui/schema/index.d.ts.map +1 -1
  139. package/dist/ui/schema/index.js +225 -248
  140. package/dist/ui/schema/index.js.map +1 -0
  141. package/dist/ui/schema/lazy.js +9 -2
  142. package/dist/ui/schema/lazy.js.map +1 -0
  143. package/dist/utils/cn.js +3 -1
  144. package/dist/utils/deep-equal.js +18 -26
  145. package/dist/utils/deep-equal.js.map +1 -0
  146. package/dist/utils/get-typescript-schema.js +21 -19
  147. package/dist/utils/get-typescript-schema.js.map +1 -0
  148. package/dist/utils/id-to-title.js +13 -16
  149. package/dist/utils/id-to-title.js.map +1 -0
  150. package/dist/utils/lazy.js +13 -11
  151. package/dist/utils/lazy.js.map +1 -0
  152. package/dist/utils/merge-schema.js +130 -174
  153. package/dist/utils/merge-schema.js.map +1 -0
  154. package/dist/utils/pages/builder.d.ts +80 -76
  155. package/dist/utils/pages/builder.d.ts.map +1 -1
  156. package/dist/utils/pages/builder.js +101 -118
  157. package/dist/utils/pages/builder.js.map +1 -0
  158. package/dist/utils/pages/preset-auto.d.ts +58 -55
  159. package/dist/utils/pages/preset-auto.d.ts.map +1 -1
  160. package/dist/utils/pages/preset-auto.js +124 -137
  161. package/dist/utils/pages/preset-auto.js.map +1 -0
  162. package/dist/utils/pages/to-body.js +21 -18
  163. package/dist/utils/pages/to-body.js.map +1 -0
  164. package/dist/utils/pages/to-static-data.js +48 -40
  165. package/dist/utils/pages/to-static-data.js.map +1 -0
  166. package/dist/utils/pages/to-text.d.ts +43 -41
  167. package/dist/utils/pages/to-text.d.ts.map +1 -1
  168. package/dist/utils/pages/to-text.js +93 -126
  169. package/dist/utils/pages/to-text.js.map +1 -0
  170. package/dist/utils/process-document.d.ts +18 -19
  171. package/dist/utils/process-document.d.ts.map +1 -1
  172. package/dist/utils/process-document.js +43 -54
  173. package/dist/utils/process-document.js.map +1 -0
  174. package/dist/utils/remove-undefined.js +18 -18
  175. package/dist/utils/remove-undefined.js.map +1 -0
  176. package/dist/utils/schema-to-string.js +46 -64
  177. package/dist/utils/schema-to-string.js.map +1 -0
  178. package/dist/utils/schema.d.ts +11 -27
  179. package/dist/utils/schema.d.ts.map +1 -1
  180. package/dist/utils/schema.js +43 -44
  181. package/dist/utils/schema.js.map +1 -0
  182. package/dist/utils/url.js +35 -56
  183. package/dist/utils/url.js.map +1 -0
  184. package/dist/utils/use-query.js +39 -33
  185. package/dist/utils/use-query.js.map +1 -0
  186. package/package.json +34 -33
  187. package/dist/index.d.ts.map +0 -1
  188. package/dist/playground/components/inputs.d.ts +0 -25
  189. package/dist/playground/components/inputs.d.ts.map +0 -1
  190. package/dist/playground/components/oauth-dialog.d.ts +0 -13
  191. package/dist/playground/components/oauth-dialog.d.ts.map +0 -1
  192. package/dist/playground/components/server-select.d.ts +0 -3
  193. package/dist/playground/components/server-select.d.ts.map +0 -1
  194. package/dist/playground/get-default-values.d.ts +0 -3
  195. package/dist/playground/get-default-values.d.ts.map +0 -1
  196. package/dist/playground/lazy.d.ts +0 -2
  197. package/dist/playground/lazy.d.ts.map +0 -1
  198. package/dist/playground/status-info.d.ts +0 -8
  199. package/dist/playground/status-info.d.ts.map +0 -1
  200. package/dist/requests/generators/csharp.d.ts +0 -3
  201. package/dist/requests/generators/csharp.d.ts.map +0 -1
  202. package/dist/requests/generators/curl.d.ts +0 -3
  203. package/dist/requests/generators/curl.d.ts.map +0 -1
  204. package/dist/requests/generators/go.d.ts +0 -3
  205. package/dist/requests/generators/go.d.ts.map +0 -1
  206. package/dist/requests/generators/index.d.ts +0 -3
  207. package/dist/requests/generators/index.d.ts.map +0 -1
  208. package/dist/requests/generators/java.d.ts +0 -3
  209. package/dist/requests/generators/java.d.ts.map +0 -1
  210. package/dist/requests/generators/javascript.d.ts +0 -3
  211. package/dist/requests/generators/javascript.d.ts.map +0 -1
  212. package/dist/requests/generators/python.d.ts +0 -3
  213. package/dist/requests/generators/python.d.ts.map +0 -1
  214. package/dist/requests/media/resolve-adapter.d.ts +0 -19
  215. package/dist/requests/media/resolve-adapter.d.ts.map +0 -1
  216. package/dist/requests/string-utils.d.ts +0 -7
  217. package/dist/requests/string-utils.d.ts.map +0 -1
  218. package/dist/requests/to-python-object.d.ts +0 -2
  219. package/dist/requests/to-python-object.d.ts.map +0 -1
  220. package/dist/requests/types.js +0 -1
  221. package/dist/scalar/client.d.ts +0 -7
  222. package/dist/scalar/client.d.ts.map +0 -1
  223. package/dist/server/index.d.ts.map +0 -1
  224. package/dist/types.js +0 -1
  225. package/dist/ui/client/storage-key.d.ts +0 -9
  226. package/dist/ui/client/storage-key.d.ts.map +0 -1
  227. package/dist/ui/components/accordion.d.ts +0 -8
  228. package/dist/ui/components/accordion.d.ts.map +0 -1
  229. package/dist/ui/components/dialog.d.ts +0 -20
  230. package/dist/ui/components/dialog.d.ts.map +0 -1
  231. package/dist/ui/components/input.d.ts +0 -6
  232. package/dist/ui/components/input.d.ts.map +0 -1
  233. package/dist/ui/components/method-label.d.ts +0 -10
  234. package/dist/ui/components/method-label.d.ts.map +0 -1
  235. package/dist/ui/components/select.d.ts +0 -14
  236. package/dist/ui/components/select.d.ts.map +0 -1
  237. package/dist/ui/contexts/api.d.ts +0 -33
  238. package/dist/ui/contexts/api.d.ts.map +0 -1
  239. package/dist/ui/contexts/api.lazy.d.ts +0 -2
  240. package/dist/ui/contexts/api.lazy.d.ts.map +0 -1
  241. package/dist/ui/icons.d.ts +0 -49
  242. package/dist/ui/icons.d.ts.map +0 -1
  243. package/dist/ui/icons.js +0 -281
  244. package/dist/ui/index.d.ts.map +0 -1
  245. package/dist/ui/operation/client.d.ts +0 -19
  246. package/dist/ui/operation/client.d.ts.map +0 -1
  247. package/dist/ui/operation/index.d.ts +0 -12
  248. package/dist/ui/operation/index.d.ts.map +0 -1
  249. package/dist/ui/operation/usage-tabs/client.d.ts +0 -23
  250. package/dist/ui/operation/usage-tabs/client.d.ts.map +0 -1
  251. package/dist/ui/operation/usage-tabs/lazy.d.ts +0 -4
  252. package/dist/ui/operation/usage-tabs/lazy.d.ts.map +0 -1
  253. package/dist/ui/schema/lazy.d.ts +0 -2
  254. package/dist/ui/schema/lazy.d.ts.map +0 -1
  255. package/dist/utils/cn.d.ts +0 -2
  256. package/dist/utils/cn.d.ts.map +0 -1
  257. package/dist/utils/deep-equal.d.ts +0 -2
  258. package/dist/utils/deep-equal.d.ts.map +0 -1
  259. package/dist/utils/get-typescript-schema.d.ts +0 -4
  260. package/dist/utils/get-typescript-schema.d.ts.map +0 -1
  261. package/dist/utils/id-to-title.d.ts +0 -2
  262. package/dist/utils/id-to-title.d.ts.map +0 -1
  263. package/dist/utils/lazy.d.ts +0 -5
  264. package/dist/utils/lazy.d.ts.map +0 -1
  265. package/dist/utils/merge-schema.d.ts +0 -7
  266. package/dist/utils/merge-schema.d.ts.map +0 -1
  267. package/dist/utils/pages/to-body.d.ts +0 -4
  268. package/dist/utils/pages/to-body.d.ts.map +0 -1
  269. package/dist/utils/pages/to-static-data.d.ts +0 -10
  270. package/dist/utils/pages/to-static-data.d.ts.map +0 -1
  271. package/dist/utils/remove-undefined.d.ts +0 -2
  272. package/dist/utils/remove-undefined.d.ts.map +0 -1
  273. package/dist/utils/schema-to-string.d.ts +0 -8
  274. package/dist/utils/schema-to-string.d.ts.map +0 -1
  275. package/dist/utils/url.d.ts +0 -11
  276. package/dist/utils/url.d.ts.map +0 -1
  277. package/dist/utils/use-query.d.ts +0 -8
  278. package/dist/utils/use-query.d.ts.map +0 -1
@@ -1,95 +1,91 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { getPreferredType, } from '../utils/schema.js';
3
- import { ClientLazy } from './lazy.js';
4
- export async function APIPlayground({ path, method, ctx }) {
5
- if (ctx.playground?.render) {
6
- return ctx.playground.render({ path, method, ctx });
7
- }
8
- let currentId = 0;
9
- const bodyContent = method.requestBody?.content;
10
- const mediaType = bodyContent ? getPreferredType(bodyContent) : undefined;
11
- const context = {
12
- references: {},
13
- nextId() {
14
- return String(currentId++);
15
- },
16
- registered: new WeakMap(),
17
- };
18
- const props = {
19
- securities: parseSecurities(method, ctx),
20
- method: method.method,
21
- route: path,
22
- parameters: method.parameters,
23
- body: bodyContent && mediaType
24
- ? {
25
- schema: writeReferences(bodyContent[mediaType].schema, context),
26
- mediaType,
27
- }
28
- : undefined,
29
- references: context.references,
30
- proxyUrl: ctx.proxyUrl,
31
- writeOnly: true,
32
- readOnly: false,
33
- };
34
- return _jsx(ClientLazy, { ...props });
1
+ import { getPreferredType } from "../utils/schema.js";
2
+ import { ClientLazy } from "./lazy.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+
5
+ //#region src/playground/index.tsx
6
+ async function APIPlayground({ path, method, ctx }) {
7
+ if (ctx.playground?.render) return ctx.playground.render({
8
+ path,
9
+ method,
10
+ ctx
11
+ });
12
+ let currentId = 0;
13
+ const bodyContent = method.requestBody?.content;
14
+ const mediaType = bodyContent ? getPreferredType(bodyContent) : void 0;
15
+ const context = {
16
+ references: {},
17
+ nextId() {
18
+ return String(currentId++);
19
+ },
20
+ registered: /* @__PURE__ */ new WeakMap()
21
+ };
22
+ return /* @__PURE__ */ jsx(ClientLazy, {
23
+ securities: parseSecurities(method, ctx),
24
+ method: method.method,
25
+ route: path,
26
+ parameters: method.parameters,
27
+ body: bodyContent && mediaType ? {
28
+ schema: writeReferences(bodyContent[mediaType].schema, context),
29
+ mediaType
30
+ } : void 0,
31
+ references: context.references,
32
+ proxyUrl: ctx.proxyUrl,
33
+ writeOnly: true,
34
+ readOnly: false
35
+ });
35
36
  }
36
- function writeReferences(schema, ctx, stack = new WeakMap()) {
37
- if (typeof schema !== 'object' || !schema)
38
- return schema;
39
- if (stack.has(schema)) {
40
- const out = stack.get(schema);
41
- const id = ctx.nextId();
42
- ctx.references[id] = out;
43
- return {
44
- $ref: id,
45
- };
46
- }
47
- const output = { ...schema };
48
- stack.set(schema, output);
49
- for (const _n in output) {
50
- const name = _n;
51
- if (!output[name])
52
- continue;
53
- switch (name) {
54
- case 'oneOf':
55
- case 'allOf':
56
- case 'anyOf':
57
- output[name] = output[name].map((item) => writeReferences(item, ctx, stack));
58
- continue;
59
- case 'items':
60
- case 'additionalProperties':
61
- case 'not':
62
- output[name] = writeReferences(output[name], ctx, stack);
63
- continue;
64
- case 'properties':
65
- case 'patternProperties':
66
- output[name] = { ...output[name] };
67
- for (const key in output[name]) {
68
- output[name][key] = writeReferences(output[name][key], ctx, stack);
69
- }
70
- }
71
- }
72
- return output;
37
+ function writeReferences(schema, ctx, stack = /* @__PURE__ */ new WeakMap()) {
38
+ if (typeof schema !== "object" || !schema) return schema;
39
+ if (stack.has(schema)) {
40
+ const out = stack.get(schema);
41
+ const id = ctx.nextId();
42
+ ctx.references[id] = out;
43
+ return { $ref: id };
44
+ }
45
+ const output = { ...schema };
46
+ stack.set(schema, output);
47
+ for (const _n in output) {
48
+ const name = _n;
49
+ if (!output[name]) continue;
50
+ switch (name) {
51
+ case "oneOf":
52
+ case "allOf":
53
+ case "anyOf":
54
+ output[name] = output[name].map((item) => writeReferences(item, ctx, stack));
55
+ continue;
56
+ case "items":
57
+ case "additionalProperties":
58
+ case "not":
59
+ output[name] = writeReferences(output[name], ctx, stack);
60
+ continue;
61
+ case "properties":
62
+ case "patternProperties":
63
+ output[name] = { ...output[name] };
64
+ for (const key in output[name]) output[name][key] = writeReferences(output[name][key], ctx, stack);
65
+ }
66
+ }
67
+ return output;
73
68
  }
74
69
  function parseSecurities(method, { schema: { dereferenced } }) {
75
- const result = [];
76
- const security = method.security ?? dereferenced.security ?? [];
77
- if (security.length === 0)
78
- return result;
79
- for (const map of security) {
80
- const list = [];
81
- for (const [key, scopes] of Object.entries(map)) {
82
- const scheme = dereferenced.components?.securitySchemes?.[key];
83
- if (!scheme)
84
- continue;
85
- list.push({
86
- ...scheme,
87
- scopes,
88
- id: key,
89
- });
90
- }
91
- if (list.length > 0)
92
- result.push(list);
93
- }
94
- return result;
70
+ const result = [];
71
+ const security = method.security ?? dereferenced.security ?? [];
72
+ if (security.length === 0) return result;
73
+ for (const map of security) {
74
+ const list = [];
75
+ for (const [key, scopes] of Object.entries(map)) {
76
+ const scheme = dereferenced.components?.securitySchemes?.[key];
77
+ if (!scheme) continue;
78
+ list.push({
79
+ ...scheme,
80
+ scopes,
81
+ id: key
82
+ });
83
+ }
84
+ if (list.length > 0) result.push(list);
85
+ }
86
+ return result;
95
87
  }
88
+
89
+ //#endregion
90
+ export { APIPlayground };
91
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["context: Context","result: PlaygroundClientProps['securities']","list: PlaygroundClientProps['securities'][number]"],"sources":["../../src/playground/index.tsx"],"sourcesContent":["import type {\n MethodInformation,\n ParameterObject,\n RenderContext,\n SecuritySchemeObject,\n} from '@/types';\nimport { getPreferredType, type NoReference, type ParsedSchema } from '@/utils/schema';\nimport { type PlaygroundClientProps } from './client';\nimport { ClientLazy } from './lazy';\n\nexport type ParameterField = NoReference<ParameterObject> & {\n schema: ParsedSchema;\n in: 'cookie' | 'header' | 'query' | 'path';\n};\n\ninterface Context {\n references: Record<string, ParsedSchema>;\n registered: WeakMap<Exclude<ParsedSchema, boolean>, string>;\n nextId: () => string;\n}\n\nexport interface APIPlaygroundProps {\n path: string;\n method: MethodInformation;\n ctx: RenderContext;\n}\n\nexport type SecurityEntry = SecuritySchemeObject & {\n scopes: string[];\n id: string;\n};\n\nexport async function APIPlayground({ path, method, ctx }: APIPlaygroundProps) {\n if (ctx.playground?.render) {\n return ctx.playground.render({ path, method, ctx });\n }\n\n let currentId = 0;\n const bodyContent = method.requestBody?.content;\n const mediaType = bodyContent ? getPreferredType(bodyContent) : undefined;\n\n const context: Context = {\n references: {},\n nextId() {\n return String(currentId++);\n },\n registered: new WeakMap(),\n };\n\n const props: PlaygroundClientProps = {\n securities: parseSecurities(method, ctx),\n method: method.method,\n route: path,\n parameters: method.parameters as ParameterField[],\n body:\n bodyContent && mediaType\n ? ({\n schema: writeReferences(bodyContent[mediaType].schema as ParsedSchema, context),\n mediaType,\n } as PlaygroundClientProps['body'])\n : undefined,\n references: context.references,\n proxyUrl: ctx.proxyUrl,\n writeOnly: true,\n readOnly: false,\n };\n\n return <ClientLazy {...props} />;\n}\n\nfunction writeReferences(\n schema: ParsedSchema,\n ctx: Context,\n stack: WeakMap<object, object> = new WeakMap(),\n): ParsedSchema {\n if (typeof schema !== 'object' || !schema) return schema;\n if (stack.has(schema)) {\n const out = stack.get(schema)!;\n const id = ctx.nextId();\n ctx.references[id] = out;\n\n return {\n $ref: id,\n };\n }\n\n const output = { ...schema };\n stack.set(schema, output);\n for (const _n in output) {\n const name = _n as keyof typeof output;\n if (!output[name]) continue;\n\n switch (name) {\n case 'oneOf':\n case 'allOf':\n case 'anyOf':\n output[name] = output[name].map((item) => writeReferences(item, ctx, stack));\n continue;\n case 'items':\n case 'additionalProperties':\n case 'not':\n output[name] = writeReferences(output[name], ctx, stack);\n continue;\n case 'properties':\n case 'patternProperties':\n output[name] = { ...output[name] };\n\n for (const key in output[name]) {\n output[name][key] = writeReferences(output[name][key], ctx, stack);\n }\n }\n }\n\n return output;\n}\n\nfunction parseSecurities(\n method: MethodInformation,\n { schema: { dereferenced } }: RenderContext,\n): PlaygroundClientProps['securities'] {\n const result: PlaygroundClientProps['securities'] = [];\n const security = method.security ?? dereferenced.security ?? [];\n if (security.length === 0) return result;\n\n for (const map of security) {\n const list: PlaygroundClientProps['securities'][number] = [];\n\n for (const [key, scopes] of Object.entries(map)) {\n const scheme = dereferenced.components?.securitySchemes?.[key];\n if (!scheme) continue;\n\n list.push({\n ...scheme,\n scopes,\n id: key,\n });\n }\n\n if (list.length > 0) result.push(list);\n }\n\n return result;\n}\n"],"mappings":";;;;;AAgCA,eAAsB,cAAc,EAAE,MAAM,QAAQ,OAA2B;AAC7E,KAAI,IAAI,YAAY,OAClB,QAAO,IAAI,WAAW,OAAO;EAAE;EAAM;EAAQ;EAAK,CAAC;CAGrD,IAAI,YAAY;CAChB,MAAM,cAAc,OAAO,aAAa;CACxC,MAAM,YAAY,cAAc,iBAAiB,YAAY,GAAG;CAEhE,MAAMA,UAAmB;EACvB,YAAY,EAAE;EACd,SAAS;AACP,UAAO,OAAO,YAAY;;EAE5B,4BAAY,IAAI,SAAS;EAC1B;AAoBD,QAAO,oBAAC;EAjBN,YAAY,gBAAgB,QAAQ,IAAI;EACxC,QAAQ,OAAO;EACf,OAAO;EACP,YAAY,OAAO;EACnB,MACE,eAAe,YACV;GACC,QAAQ,gBAAgB,YAAY,WAAW,QAAwB,QAAQ;GAC/E;GACD,GACD;EACN,YAAY,QAAQ;EACpB,UAAU,IAAI;EACd,WAAW;EACX,UAAU;GAGoB;;AAGlC,SAAS,gBACP,QACA,KACA,wBAAiC,IAAI,SAAS,EAChC;AACd,KAAI,OAAO,WAAW,YAAY,CAAC,OAAQ,QAAO;AAClD,KAAI,MAAM,IAAI,OAAO,EAAE;EACrB,MAAM,MAAM,MAAM,IAAI,OAAO;EAC7B,MAAM,KAAK,IAAI,QAAQ;AACvB,MAAI,WAAW,MAAM;AAErB,SAAO,EACL,MAAM,IACP;;CAGH,MAAM,SAAS,EAAE,GAAG,QAAQ;AAC5B,OAAM,IAAI,QAAQ,OAAO;AACzB,MAAK,MAAM,MAAM,QAAQ;EACvB,MAAM,OAAO;AACb,MAAI,CAAC,OAAO,MAAO;AAEnB,UAAQ,MAAR;GACE,KAAK;GACL,KAAK;GACL,KAAK;AACH,WAAO,QAAQ,OAAO,MAAM,KAAK,SAAS,gBAAgB,MAAM,KAAK,MAAM,CAAC;AAC5E;GACF,KAAK;GACL,KAAK;GACL,KAAK;AACH,WAAO,QAAQ,gBAAgB,OAAO,OAAO,KAAK,MAAM;AACxD;GACF,KAAK;GACL,KAAK;AACH,WAAO,QAAQ,EAAE,GAAG,OAAO,OAAO;AAElC,SAAK,MAAM,OAAO,OAAO,MACvB,QAAO,MAAM,OAAO,gBAAgB,OAAO,MAAM,MAAM,KAAK,MAAM;;;AAK1E,QAAO;;AAGT,SAAS,gBACP,QACA,EAAE,QAAQ,EAAE,kBACyB;CACrC,MAAMC,SAA8C,EAAE;CACtD,MAAM,WAAW,OAAO,YAAY,aAAa,YAAY,EAAE;AAC/D,KAAI,SAAS,WAAW,EAAG,QAAO;AAElC,MAAK,MAAM,OAAO,UAAU;EAC1B,MAAMC,OAAoD,EAAE;AAE5D,OAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,IAAI,EAAE;GAC/C,MAAM,SAAS,aAAa,YAAY,kBAAkB;AAC1D,OAAI,CAAC,OAAQ;AAEb,QAAK,KAAK;IACR,GAAG;IACH;IACA,IAAI;IACL,CAAC;;AAGJ,MAAI,KAAK,SAAS,EAAG,QAAO,KAAK,KAAK;;AAGxC,QAAO"}
@@ -1,3 +1,10 @@
1
1
  'use client';
2
- import { wrapLazy } from '../utils/lazy.js';
3
- export const ClientLazy = wrapLazy(() => import('./client.js'));
2
+
3
+ import { wrapLazy } from "../utils/lazy.js";
4
+
5
+ //#region src/playground/lazy.ts
6
+ const ClientLazy = wrapLazy(() => import("./client.js"));
7
+
8
+ //#endregion
9
+ export { ClientLazy };
10
+ //# sourceMappingURL=lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy.js","names":[],"sources":["../../src/playground/lazy.ts"],"sourcesContent":["'use client';\nimport { wrapLazy } from '../utils/lazy';\n\nexport const ClientLazy = wrapLazy(() => import('./client'));\n"],"mappings":";;;;;AAGA,MAAa,aAAa,eAAe,OAAO,eAAY"}
@@ -1,57 +1,20 @@
1
- import { Ajv2020 } from 'ajv/dist/2020';
2
- import { ReactNode } from 'react';
3
- import type { ParsedSchema } from '../utils/schema.js';
4
- interface SchemaContextType extends SchemaScope {
5
- references: Record<string, ParsedSchema>;
6
- fieldInfoMap: Map<string, FieldInfo>;
7
- ajv: Ajv2020;
1
+ import "../utils/schema.js";
2
+ import { ReactNode } from "react";
3
+ import "react/jsx-runtime";
4
+ import { Ajv2020 } from "ajv/dist/2020";
5
+
6
+ //#region src/playground/schema.d.ts
7
+
8
+ interface SchemaScope {
9
+ /**
10
+ * show write only fields
11
+ */
12
+ writeOnly: boolean;
13
+ /**
14
+ * show read only fields
15
+ */
16
+ readOnly: boolean;
8
17
  }
9
- export interface SchemaScope {
10
- /**
11
- * show write only fields
12
- */
13
- writeOnly: boolean;
14
- /**
15
- * show read only fields
16
- */
17
- readOnly: boolean;
18
- }
19
- type UnionField = 'anyOf' | 'oneOf';
20
- export interface FieldInfo {
21
- selectedType?: string;
22
- oneOf: number;
23
- /**
24
- * The actual field that represents union members.
25
- */
26
- unionField?: UnionField;
27
- intersection?: {
28
- merged: Exclude<ParsedSchema, boolean>;
29
- };
30
- }
31
- export declare const anyFields: {
32
- type: string[];
33
- items: true;
34
- additionalProperties: true;
35
- };
36
- export declare function SchemaProvider({ references, fieldInfoMap, readOnly, writeOnly, children, }: Omit<SchemaContextType, 'ajv'> & {
37
- children: ReactNode;
38
- }): import("react/jsx-runtime").JSX.Element;
39
- export declare function useSchemaScope(): SchemaScope;
40
- /**
41
- * A hook to store dynamic info of a field, such as selected schema of `oneOf`.
42
- *
43
- * @param fieldName - field name of form.
44
- * @param schema - The JSON Schema to generate initial values.
45
- * @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).
46
- */
47
- export declare function useFieldInfo(fieldName: string, schema: Exclude<ParsedSchema, boolean>, depth: number): {
48
- info: FieldInfo;
49
- updateInfo: (value: Partial<FieldInfo>) => void;
50
- };
51
- /**
52
- * Resolve `$ref` in the schema, **not recursive**.
53
- */
54
- export declare function useResolvedSchema(schema: ParsedSchema): Exclude<ParsedSchema, boolean>;
55
- export declare function fallbackAny(schema: ParsedSchema): Exclude<ParsedSchema, boolean>;
56
- export {};
18
+ //#endregion
19
+ export { SchemaScope };
57
20
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/playground/schema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAiB,SAAS,EAA0B,MAAM,OAAO,CAAC;AAGzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,UAAU,iBAAkB,SAAQ,WAAW;IAC7C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACzC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrC,GAAG,EAAE,OAAO,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,UAAU,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpC,MAAM,WAAW,SAAS;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB,YAAY,CAAC,EAAE;QACb,MAAM,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;KACxC,CAAC;CACH;AAGD,eAAO,MAAM,SAAS;;;;CAIE,CAAC;AAEzB,wBAAgB,cAAc,CAAC,EAC7B,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,QAAQ,GACT,EAAE,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,GAAG;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAsB1D;AAED,wBAAgB,cAAc,IAAI,WAAW,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,EACtC,KAAK,EAAE,MAAM,GACZ;IACD,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;CACjD,CA0EA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAQhC;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAEhC"}
1
+ {"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/playground/schema.tsx"],"sourcesContent":[],"mappings":";;;;;;;UAaiB,WAAA"}
@@ -1,116 +1,127 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Ajv2020 } from 'ajv/dist/2020';
3
- import { createContext, use, useMemo, useState } from 'react';
4
- import { useFormContext } from 'react-hook-form';
5
- import { getDefaultValue } from '../playground/get-default-values.js';
6
- import { mergeAllOf } from '../utils/merge-schema.js';
7
- const SchemaContext = createContext(undefined);
8
- export const anyFields = {
9
- type: ['string', 'number', 'boolean', 'array', 'object'],
10
- items: true,
11
- additionalProperties: true,
1
+ import { getDefaultValue } from "./get-default-values.js";
2
+ import { mergeAllOf } from "../utils/merge-schema.js";
3
+ import { createContext, use, useMemo, useState } from "react";
4
+ import { useFormContext } from "react-hook-form";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { Ajv2020 } from "ajv/dist/2020";
7
+
8
+ //#region src/playground/schema.tsx
9
+ const SchemaContext = createContext(void 0);
10
+ const anyFields = {
11
+ type: [
12
+ "string",
13
+ "number",
14
+ "boolean",
15
+ "array",
16
+ "object"
17
+ ],
18
+ items: true,
19
+ additionalProperties: true
12
20
  };
13
- export function SchemaProvider({ references, fieldInfoMap, readOnly, writeOnly, children, }) {
14
- const ajv = useMemo(() => new Ajv2020({
15
- strict: false,
16
- validateSchema: false,
17
- validateFormats: false,
18
- schemas: references,
19
- }), [references]);
20
- return (_jsx(SchemaContext.Provider, { value: useMemo(() => ({ references, fieldInfoMap, ajv, readOnly, writeOnly }), [references, fieldInfoMap, ajv, readOnly, writeOnly]), children: children }));
21
+ function SchemaProvider({ references, fieldInfoMap, readOnly, writeOnly, children }) {
22
+ const ajv = useMemo(() => new Ajv2020({
23
+ strict: false,
24
+ validateSchema: false,
25
+ validateFormats: false,
26
+ schemas: references
27
+ }), [references]);
28
+ return /* @__PURE__ */ jsx(SchemaContext.Provider, {
29
+ value: useMemo(() => ({
30
+ references,
31
+ fieldInfoMap,
32
+ ajv,
33
+ readOnly,
34
+ writeOnly
35
+ }), [
36
+ references,
37
+ fieldInfoMap,
38
+ ajv,
39
+ readOnly,
40
+ writeOnly
41
+ ]),
42
+ children
43
+ });
21
44
  }
22
- export function useSchemaScope() {
23
- return use(SchemaContext);
45
+ function useSchemaScope() {
46
+ return use(SchemaContext);
24
47
  }
25
48
  /**
26
- * A hook to store dynamic info of a field, such as selected schema of `oneOf`.
27
- *
28
- * @param fieldName - field name of form.
29
- * @param schema - The JSON Schema to generate initial values.
30
- * @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).
31
- */
32
- export function useFieldInfo(fieldName, schema, depth) {
33
- const { fieldInfoMap, ajv } = use(SchemaContext);
34
- const form = useFormContext();
35
- const keyName = `${fieldName}:${depth}`;
36
- const [info, setInfo] = useState(() => {
37
- const value = form.getValues(fieldName);
38
- const initialInfo = fieldInfoMap.get(keyName);
39
- if (initialInfo)
40
- return initialInfo;
41
- const out = {
42
- oneOf: -1,
43
- };
44
- const union = getUnion(schema);
45
- if (union) {
46
- const [members, field] = union;
47
- out.oneOf = members.findIndex((item) => ajv.validate(item, value));
48
- if (out.oneOf === -1)
49
- out.oneOf = 0;
50
- out.unionField = field;
51
- }
52
- if (Array.isArray(schema.type)) {
53
- const types = schema.type;
54
- out.selectedType =
55
- types.find((type) => {
56
- schema.type = type;
57
- const match = ajv.validate(schema, value);
58
- schema.type = types;
59
- return match;
60
- }) ?? types.at(0);
61
- }
62
- if (schema.allOf) {
63
- const merged = mergeAllOf(schema);
64
- if (typeof merged !== 'boolean')
65
- out.intersection = {
66
- merged,
67
- };
68
- }
69
- return out;
70
- });
71
- fieldInfoMap.set(keyName, info);
72
- return {
73
- info,
74
- updateInfo: (value) => {
75
- const updated = {
76
- ...info,
77
- ...value,
78
- };
79
- if (updated.oneOf === info.oneOf &&
80
- updated.selectedType === info.selectedType)
81
- return;
82
- setInfo(updated);
83
- let valueSchema = schema;
84
- if (updated.unionField) {
85
- valueSchema = schema[updated.unionField][updated.oneOf];
86
- }
87
- else if (updated.selectedType) {
88
- valueSchema = { ...schema, type: updated.selectedType };
89
- }
90
- form.setValue(fieldName, getDefaultValue(valueSchema));
91
- },
92
- };
49
+ * A hook to store dynamic info of a field, such as selected schema of `oneOf`.
50
+ *
51
+ * @param fieldName - field name of form.
52
+ * @param schema - The JSON Schema to generate initial values.
53
+ * @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).
54
+ */
55
+ function useFieldInfo(fieldName, schema, depth) {
56
+ const { fieldInfoMap, ajv } = use(SchemaContext);
57
+ const form = useFormContext();
58
+ const keyName = `${fieldName}:${depth}`;
59
+ const [info, setInfo] = useState(() => {
60
+ const value = form.getValues(fieldName);
61
+ const initialInfo = fieldInfoMap.get(keyName);
62
+ if (initialInfo) return initialInfo;
63
+ const out = { oneOf: -1 };
64
+ const union = getUnion(schema);
65
+ if (union) {
66
+ const [members, field] = union;
67
+ out.oneOf = members.findIndex((item) => ajv.validate(item, value));
68
+ if (out.oneOf === -1) out.oneOf = 0;
69
+ out.unionField = field;
70
+ }
71
+ if (Array.isArray(schema.type)) {
72
+ const types = schema.type;
73
+ out.selectedType = types.find((type) => {
74
+ schema.type = type;
75
+ const match = ajv.validate(schema, value);
76
+ schema.type = types;
77
+ return match;
78
+ }) ?? types.at(0);
79
+ }
80
+ if (schema.allOf) {
81
+ const merged = mergeAllOf(schema);
82
+ if (typeof merged !== "boolean") out.intersection = { merged };
83
+ }
84
+ return out;
85
+ });
86
+ fieldInfoMap.set(keyName, info);
87
+ return {
88
+ info,
89
+ updateInfo: (value) => {
90
+ const updated = {
91
+ ...info,
92
+ ...value
93
+ };
94
+ if (updated.oneOf === info.oneOf && updated.selectedType === info.selectedType) return;
95
+ setInfo(updated);
96
+ let valueSchema = schema;
97
+ if (updated.unionField) valueSchema = schema[updated.unionField][updated.oneOf];
98
+ else if (updated.selectedType) valueSchema = {
99
+ ...schema,
100
+ type: updated.selectedType
101
+ };
102
+ form.setValue(fieldName, getDefaultValue(valueSchema));
103
+ }
104
+ };
93
105
  }
94
106
  /**
95
- * Resolve `$ref` in the schema, **not recursive**.
96
- */
97
- export function useResolvedSchema(schema) {
98
- const { references } = use(SchemaContext);
99
- return useMemo(() => {
100
- if (typeof schema === 'boolean')
101
- return anyFields;
102
- if (schema.$ref)
103
- return fallbackAny(references[schema.$ref]);
104
- return schema;
105
- }, [references, schema]);
107
+ * Resolve `$ref` in the schema, **not recursive**.
108
+ */
109
+ function useResolvedSchema(schema) {
110
+ const { references } = use(SchemaContext);
111
+ return useMemo(() => {
112
+ if (typeof schema === "boolean") return anyFields;
113
+ if (schema.$ref) return fallbackAny(references[schema.$ref]);
114
+ return schema;
115
+ }, [references, schema]);
106
116
  }
107
- export function fallbackAny(schema) {
108
- return typeof schema === 'boolean' ? anyFields : schema;
117
+ function fallbackAny(schema) {
118
+ return typeof schema === "boolean" ? anyFields : schema;
109
119
  }
110
120
  function getUnion(schema) {
111
- if (schema.anyOf) {
112
- return [schema.anyOf, 'anyOf'];
113
- }
114
- if (schema.oneOf)
115
- return [schema.oneOf, 'oneOf'];
121
+ if (schema.anyOf) return [schema.anyOf, "anyOf"];
122
+ if (schema.oneOf) return [schema.oneOf, "oneOf"];
116
123
  }
124
+
125
+ //#endregion
126
+ export { SchemaProvider, anyFields, useFieldInfo, useResolvedSchema, useSchemaScope };
127
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","names":["out: FieldInfo","valueSchema: ParsedSchema"],"sources":["../../src/playground/schema.tsx"],"sourcesContent":["import { Ajv2020 } from 'ajv/dist/2020';\nimport { createContext, ReactNode, use, useMemo, useState } from 'react';\nimport { useFormContext } from 'react-hook-form';\nimport { getDefaultValue } from '@/playground/get-default-values';\nimport type { ParsedSchema } from '@/utils/schema';\nimport { mergeAllOf } from '@/utils/merge-schema';\n\ninterface SchemaContextType extends SchemaScope {\n references: Record<string, ParsedSchema>;\n fieldInfoMap: Map<string, FieldInfo>;\n ajv: Ajv2020;\n}\n\nexport interface SchemaScope {\n /**\n * show write only fields\n */\n writeOnly: boolean;\n\n /**\n * show read only fields\n */\n readOnly: boolean;\n}\n\ntype UnionField = 'anyOf' | 'oneOf';\n\nexport interface FieldInfo {\n selectedType?: string;\n oneOf: number;\n\n /**\n * The actual field that represents union members.\n */\n unionField?: UnionField;\n\n intersection?: {\n merged: Exclude<ParsedSchema, boolean>;\n };\n}\n\nconst SchemaContext = createContext<SchemaContextType | undefined>(undefined);\nexport const anyFields = {\n type: ['string', 'number', 'boolean', 'array', 'object'],\n items: true,\n additionalProperties: true,\n} satisfies ParsedSchema;\n\nexport function SchemaProvider({\n references,\n fieldInfoMap,\n readOnly,\n writeOnly,\n children,\n}: Omit<SchemaContextType, 'ajv'> & { children: ReactNode }) {\n const ajv = useMemo(\n () =>\n new Ajv2020({\n strict: false,\n validateSchema: false,\n validateFormats: false,\n schemas: references,\n }),\n [references],\n );\n\n return (\n <SchemaContext.Provider\n value={useMemo(\n () => ({ references, fieldInfoMap, ajv, readOnly, writeOnly }),\n [references, fieldInfoMap, ajv, readOnly, writeOnly],\n )}\n >\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport function useSchemaScope(): SchemaScope {\n return use(SchemaContext)!;\n}\n\n/**\n * A hook to store dynamic info of a field, such as selected schema of `oneOf`.\n *\n * @param fieldName - field name of form.\n * @param schema - The JSON Schema to generate initial values.\n * @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).\n */\nexport function useFieldInfo(\n fieldName: string,\n schema: Exclude<ParsedSchema, boolean>,\n depth: number,\n): {\n info: FieldInfo;\n updateInfo: (value: Partial<FieldInfo>) => void;\n} {\n const { fieldInfoMap, ajv } = use(SchemaContext)!;\n const form = useFormContext();\n const keyName = `${fieldName}:${depth}`;\n const [info, setInfo] = useState<FieldInfo>(() => {\n const value = form.getValues(fieldName as 'body');\n const initialInfo = fieldInfoMap.get(keyName);\n if (initialInfo) return initialInfo;\n\n const out: FieldInfo = {\n oneOf: -1,\n };\n const union = getUnion(schema);\n if (union) {\n const [members, field] = union;\n\n out.oneOf = members.findIndex((item) => ajv.validate(item, value));\n if (out.oneOf === -1) out.oneOf = 0;\n out.unionField = field;\n }\n\n if (Array.isArray(schema.type)) {\n const types = schema.type;\n\n out.selectedType =\n types.find((type) => {\n schema.type = type;\n const match = ajv.validate(schema, value);\n schema.type = types;\n\n return match;\n }) ?? types.at(0);\n }\n\n if (schema.allOf) {\n const merged = mergeAllOf(schema);\n\n if (typeof merged !== 'boolean')\n out.intersection = {\n merged,\n };\n }\n\n return out;\n });\n\n fieldInfoMap.set(keyName, info);\n\n return {\n info,\n updateInfo: (value) => {\n const updated = {\n ...info,\n ...value,\n };\n\n if (updated.oneOf === info.oneOf && updated.selectedType === info.selectedType) return;\n\n setInfo(updated);\n\n let valueSchema: ParsedSchema = schema;\n if (updated.unionField) {\n valueSchema = schema[updated.unionField]![updated.oneOf];\n } else if (updated.selectedType) {\n valueSchema = { ...schema, type: updated.selectedType };\n }\n\n form.setValue(fieldName, getDefaultValue(valueSchema));\n },\n };\n}\n\n/**\n * Resolve `$ref` in the schema, **not recursive**.\n */\nexport function useResolvedSchema(schema: ParsedSchema): Exclude<ParsedSchema, boolean> {\n const { references } = use(SchemaContext)!;\n\n return useMemo(() => {\n if (typeof schema === 'boolean') return anyFields;\n if (schema.$ref) return fallbackAny(references[schema.$ref]);\n return schema;\n }, [references, schema]);\n}\n\nexport function fallbackAny(schema: ParsedSchema): Exclude<ParsedSchema, boolean> {\n return typeof schema === 'boolean' ? anyFields : schema;\n}\n\nfunction getUnion(\n schema: Exclude<ParsedSchema, boolean>,\n): [readonly ParsedSchema[], UnionField] | undefined {\n if (schema.anyOf) {\n return [schema.anyOf, 'anyOf'];\n }\n\n if (schema.oneOf) return [schema.oneOf, 'oneOf'];\n}\n"],"mappings":";;;;;;;;AAyCA,MAAM,gBAAgB,cAA6C,OAAU;AAC7E,MAAa,YAAY;CACvB,MAAM;EAAC;EAAU;EAAU;EAAW;EAAS;EAAS;CACxD,OAAO;CACP,sBAAsB;CACvB;AAED,SAAgB,eAAe,EAC7B,YACA,cACA,UACA,WACA,YAC2D;CAC3D,MAAM,MAAM,cAER,IAAI,QAAQ;EACV,QAAQ;EACR,gBAAgB;EAChB,iBAAiB;EACjB,SAAS;EACV,CAAC,EACJ,CAAC,WAAW,CACb;AAED,QACE,oBAAC,cAAc;EACb,OAAO,eACE;GAAE;GAAY;GAAc;GAAK;GAAU;GAAW,GAC7D;GAAC;GAAY;GAAc;GAAK;GAAU;GAAU,CACrD;EAEA;GACsB;;AAI7B,SAAgB,iBAA8B;AAC5C,QAAO,IAAI,cAAc;;;;;;;;;AAU3B,SAAgB,aACd,WACA,QACA,OAIA;CACA,MAAM,EAAE,cAAc,QAAQ,IAAI,cAAc;CAChD,MAAM,OAAO,gBAAgB;CAC7B,MAAM,UAAU,GAAG,UAAU,GAAG;CAChC,MAAM,CAAC,MAAM,WAAW,eAA0B;EAChD,MAAM,QAAQ,KAAK,UAAU,UAAoB;EACjD,MAAM,cAAc,aAAa,IAAI,QAAQ;AAC7C,MAAI,YAAa,QAAO;EAExB,MAAMA,MAAiB,EACrB,OAAO,IACR;EACD,MAAM,QAAQ,SAAS,OAAO;AAC9B,MAAI,OAAO;GACT,MAAM,CAAC,SAAS,SAAS;AAEzB,OAAI,QAAQ,QAAQ,WAAW,SAAS,IAAI,SAAS,MAAM,MAAM,CAAC;AAClE,OAAI,IAAI,UAAU,GAAI,KAAI,QAAQ;AAClC,OAAI,aAAa;;AAGnB,MAAI,MAAM,QAAQ,OAAO,KAAK,EAAE;GAC9B,MAAM,QAAQ,OAAO;AAErB,OAAI,eACF,MAAM,MAAM,SAAS;AACnB,WAAO,OAAO;IACd,MAAM,QAAQ,IAAI,SAAS,QAAQ,MAAM;AACzC,WAAO,OAAO;AAEd,WAAO;KACP,IAAI,MAAM,GAAG,EAAE;;AAGrB,MAAI,OAAO,OAAO;GAChB,MAAM,SAAS,WAAW,OAAO;AAEjC,OAAI,OAAO,WAAW,UACpB,KAAI,eAAe,EACjB,QACD;;AAGL,SAAO;GACP;AAEF,cAAa,IAAI,SAAS,KAAK;AAE/B,QAAO;EACL;EACA,aAAa,UAAU;GACrB,MAAM,UAAU;IACd,GAAG;IACH,GAAG;IACJ;AAED,OAAI,QAAQ,UAAU,KAAK,SAAS,QAAQ,iBAAiB,KAAK,aAAc;AAEhF,WAAQ,QAAQ;GAEhB,IAAIC,cAA4B;AAChC,OAAI,QAAQ,WACV,eAAc,OAAO,QAAQ,YAAa,QAAQ;YACzC,QAAQ,aACjB,eAAc;IAAE,GAAG;IAAQ,MAAM,QAAQ;IAAc;AAGzD,QAAK,SAAS,WAAW,gBAAgB,YAAY,CAAC;;EAEzD;;;;;AAMH,SAAgB,kBAAkB,QAAsD;CACtF,MAAM,EAAE,eAAe,IAAI,cAAc;AAEzC,QAAO,cAAc;AACnB,MAAI,OAAO,WAAW,UAAW,QAAO;AACxC,MAAI,OAAO,KAAM,QAAO,YAAY,WAAW,OAAO,MAAM;AAC5D,SAAO;IACN,CAAC,YAAY,OAAO,CAAC;;AAG1B,SAAgB,YAAY,QAAsD;AAChF,QAAO,OAAO,WAAW,YAAY,YAAY;;AAGnD,SAAS,SACP,QACmD;AACnD,KAAI,OAAO,MACT,QAAO,CAAC,OAAO,OAAO,QAAQ;AAGhC,KAAI,OAAO,MAAO,QAAO,CAAC,OAAO,OAAO,QAAQ"}
@@ -1,40 +1,52 @@
1
- import { CircleCheck, CircleX } from '../ui/icons.js';
1
+ import { CircleCheck, CircleX } from "lucide-react";
2
+
3
+ //#region src/playground/status-info.tsx
2
4
  const statusMap = {
3
- 400: { description: 'Bad Request', color: 'text-red-500', icon: CircleX },
4
- 401: {
5
- description: 'Unauthorized',
6
- color: 'text-red-500',
7
- icon: CircleX,
8
- },
9
- 403: { description: 'Forbidden', color: 'text-red-500', icon: CircleX },
10
- 404: {
11
- description: 'Not Found',
12
- color: 'text-fd-muted-foreground',
13
- icon: CircleX,
14
- },
15
- 500: {
16
- description: 'Internal Server Error',
17
- color: 'text-red-500',
18
- icon: CircleX,
19
- },
5
+ 400: {
6
+ description: "Bad Request",
7
+ color: "text-red-500",
8
+ icon: CircleX
9
+ },
10
+ 401: {
11
+ description: "Unauthorized",
12
+ color: "text-red-500",
13
+ icon: CircleX
14
+ },
15
+ 403: {
16
+ description: "Forbidden",
17
+ color: "text-red-500",
18
+ icon: CircleX
19
+ },
20
+ 404: {
21
+ description: "Not Found",
22
+ color: "text-fd-muted-foreground",
23
+ icon: CircleX
24
+ },
25
+ 500: {
26
+ description: "Internal Server Error",
27
+ color: "text-red-500",
28
+ icon: CircleX
29
+ }
20
30
  };
21
- export function getStatusInfo(status) {
22
- if (status in statusMap) {
23
- return statusMap[status];
24
- }
25
- if (status >= 200 && status < 300) {
26
- return {
27
- description: 'Successful',
28
- color: 'text-green-500',
29
- icon: CircleCheck,
30
- };
31
- }
32
- if (status >= 400) {
33
- return { description: 'Error', color: 'text-red-500', icon: CircleX };
34
- }
35
- return {
36
- description: 'No Description',
37
- color: 'text-fd-muted-foreground',
38
- icon: CircleX,
39
- };
31
+ function getStatusInfo(status) {
32
+ if (status in statusMap) return statusMap[status];
33
+ if (status >= 200 && status < 300) return {
34
+ description: "Successful",
35
+ color: "text-green-500",
36
+ icon: CircleCheck
37
+ };
38
+ if (status >= 400) return {
39
+ description: "Error",
40
+ color: "text-red-500",
41
+ icon: CircleX
42
+ };
43
+ return {
44
+ description: "No Description",
45
+ color: "text-fd-muted-foreground",
46
+ icon: CircleX
47
+ };
40
48
  }
49
+
50
+ //#endregion
51
+ export { getStatusInfo };
52
+ //# sourceMappingURL=status-info.js.map