fumadocs-openapi 10.2.2 → 10.2.3

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 +129 -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 +33 -32
  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,122 +1,105 @@
1
- import { getTagDisplayName, methodKeys, } from '../../utils/schema.js';
2
- import { idToTitle } from '../../utils/id-to-title.js';
3
- export async function fromServer(server, config) {
4
- const schemas = await server.getSchemas();
5
- const generated = {};
6
- const entries = Object.entries(schemas);
7
- if (entries.length === 0) {
8
- throw new Error('No input files found.');
9
- }
10
- for (const [id, schema] of entries) {
11
- generated[id] = fromSchema(id, schema, config);
12
- }
13
- return generated;
1
+ import { idToTitle } from "../id-to-title.js";
2
+ import { getTagDisplayName, methodKeys } from "../schema.js";
3
+
4
+ //#region src/utils/pages/builder.ts
5
+ async function fromServer(server, config) {
6
+ const schemas = await server.getSchemas();
7
+ const generated = {};
8
+ const entries = Object.entries(schemas);
9
+ if (entries.length === 0) throw new Error("No input files found.");
10
+ for (const [id, schema] of entries) generated[id] = fromSchema(id, schema, config);
11
+ return generated;
14
12
  }
15
- export function fromSchema(schemaId, processed, config) {
16
- const files = [];
17
- const { toPages } = config;
18
- const { dereferenced } = processed;
19
- toPages({
20
- id: schemaId,
21
- document: processed,
22
- create(entry) {
23
- files.push(entry);
24
- },
25
- extract: () => extractInfo(dereferenced),
26
- routePathToFilePath(path) {
27
- return path
28
- .toLowerCase()
29
- .replaceAll('.', '-')
30
- .split('/')
31
- .flatMap((v) => {
32
- if (v.startsWith('{') && v.endsWith('}'))
33
- return v.slice(1, -1);
34
- if (v.length === 0)
35
- return [];
36
- return v;
37
- })
38
- .join('/');
39
- },
40
- fromExtractedWebhook(item) {
41
- const pathItem = dereferenced.webhooks?.[item.name];
42
- if (!pathItem)
43
- return;
44
- const operation = pathItem?.[item.method];
45
- if (!operation)
46
- return;
47
- return {
48
- pathItem,
49
- operation,
50
- get displayName() {
51
- return operation.summary || pathItem.summary || idToTitle(item.name);
52
- },
53
- };
54
- },
55
- fromExtractedOperation(item) {
56
- const pathItem = dereferenced.paths?.[item.path];
57
- if (!pathItem)
58
- return;
59
- const operation = pathItem?.[item.method];
60
- if (!operation)
61
- return;
62
- return {
63
- pathItem,
64
- operation,
65
- get displayName() {
66
- return (operation.summary ||
67
- pathItem.summary ||
68
- (operation.operationId
69
- ? idToTitle(operation.operationId)
70
- : item.path));
71
- },
72
- };
73
- },
74
- fromTag(tag) {
75
- return {
76
- get displayName() {
77
- return getTagDisplayName(tag);
78
- },
79
- };
80
- },
81
- fromTagName(name) {
82
- const tag = dereferenced.tags?.find((item) => item.name === name);
83
- if (!tag)
84
- return;
85
- return {
86
- info: tag,
87
- ...this.fromTag(tag),
88
- };
89
- },
90
- });
91
- return files;
13
+ function fromSchema(schemaId, processed, config) {
14
+ const files = [];
15
+ const { toPages } = config;
16
+ const { dereferenced } = processed;
17
+ toPages({
18
+ id: schemaId,
19
+ document: processed,
20
+ create(entry) {
21
+ files.push(entry);
22
+ },
23
+ extract: () => extractInfo(dereferenced),
24
+ routePathToFilePath(path) {
25
+ return path.toLowerCase().replaceAll(".", "-").split("/").flatMap((v) => {
26
+ if (v.startsWith("{") && v.endsWith("}")) return v.slice(1, -1);
27
+ if (v.length === 0) return [];
28
+ return v;
29
+ }).join("/");
30
+ },
31
+ fromExtractedWebhook(item) {
32
+ const pathItem = dereferenced.webhooks?.[item.name];
33
+ if (!pathItem) return;
34
+ const operation = pathItem?.[item.method];
35
+ if (!operation) return;
36
+ return {
37
+ pathItem,
38
+ operation,
39
+ get displayName() {
40
+ return operation.summary || pathItem.summary || idToTitle(item.name);
41
+ }
42
+ };
43
+ },
44
+ fromExtractedOperation(item) {
45
+ const pathItem = dereferenced.paths?.[item.path];
46
+ if (!pathItem) return;
47
+ const operation = pathItem?.[item.method];
48
+ if (!operation) return;
49
+ return {
50
+ pathItem,
51
+ operation,
52
+ get displayName() {
53
+ return operation.summary || pathItem.summary || (operation.operationId ? idToTitle(operation.operationId) : item.path);
54
+ }
55
+ };
56
+ },
57
+ fromTag(tag) {
58
+ return { get displayName() {
59
+ return getTagDisplayName(tag);
60
+ } };
61
+ },
62
+ fromTagName(name) {
63
+ const tag = dereferenced.tags?.find((item) => item.name === name);
64
+ if (!tag) return;
65
+ return {
66
+ info: tag,
67
+ ...this.fromTag(tag)
68
+ };
69
+ }
70
+ });
71
+ return files;
92
72
  }
93
73
  function extractInfo(document) {
94
- const result = { webhooks: [], operations: [] };
95
- for (const [path, pathItem] of Object.entries(document.paths ?? {})) {
96
- if (!pathItem)
97
- continue;
98
- for (const methodKey of methodKeys) {
99
- if (!pathItem[methodKey])
100
- continue;
101
- result.operations.push({
102
- method: methodKey,
103
- path,
104
- tags: pathItem[methodKey]?.tags,
105
- });
106
- }
107
- }
108
- for (const [name, pathItem] of Object.entries(document.webhooks ?? {})) {
109
- if (!pathItem)
110
- continue;
111
- for (const methodKey of methodKeys) {
112
- if (!pathItem[methodKey])
113
- continue;
114
- result.webhooks.push({
115
- method: methodKey,
116
- name,
117
- tags: pathItem[methodKey]?.tags,
118
- });
119
- }
120
- }
121
- return result;
74
+ const result = {
75
+ webhooks: [],
76
+ operations: []
77
+ };
78
+ for (const [path, pathItem] of Object.entries(document.paths ?? {})) {
79
+ if (!pathItem) continue;
80
+ for (const methodKey of methodKeys) {
81
+ if (!pathItem[methodKey]) continue;
82
+ result.operations.push({
83
+ method: methodKey,
84
+ path,
85
+ tags: pathItem[methodKey]?.tags
86
+ });
87
+ }
88
+ }
89
+ for (const [name, pathItem] of Object.entries(document.webhooks ?? {})) {
90
+ if (!pathItem) continue;
91
+ for (const methodKey of methodKeys) {
92
+ if (!pathItem[methodKey]) continue;
93
+ result.webhooks.push({
94
+ method: methodKey,
95
+ name,
96
+ tags: pathItem[methodKey]?.tags
97
+ });
98
+ }
99
+ }
100
+ return result;
122
101
  }
102
+
103
+ //#endregion
104
+ export { fromSchema, fromServer };
105
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.js","names":["generated: Record<string, OutputEntry[]>","files: OutputEntry[]","result: ExtractedInfo"],"sources":["../../../src/utils/pages/builder.ts"],"sourcesContent":["import type { ProcessedDocument } from '@/utils/process-document';\nimport type { OpenAPIServer } from '@/server';\nimport type { OperationItem, WebhookItem } from '@/ui/api-page';\nimport type { Document, OperationObject, PathItemObject, TagObject } from '@/types';\nimport { getTagDisplayName, methodKeys, type NoReference } from '@/utils/schema';\nimport type { OpenAPIV3_1 } from 'openapi-types';\nimport { idToTitle } from '@/utils/id-to-title';\n\ninterface BaseEntry {\n path: string;\n schemaId: string;\n info: {\n title: string;\n description?: string;\n };\n}\n\nexport interface OperationOutput extends BaseEntry {\n type: 'operation';\n item: OperationItem;\n}\n\nexport interface WebhookOutput extends BaseEntry {\n type: 'webhook';\n item: WebhookItem;\n}\n\nexport interface TagOutput extends BaseEntry {\n type: 'tag';\n tag: string;\n rawTag: TagObject;\n operations: OperationItem[];\n webhooks: WebhookItem[];\n}\n\nexport interface OutputGroup extends BaseEntry {\n type: 'group';\n operations: OperationItem[];\n webhooks: WebhookItem[];\n}\n\nexport type OutputEntry = TagOutput | OperationOutput | WebhookOutput | OutputGroup;\n\nexport interface PagesBuilderConfig {\n toPages: (builder: PagesBuilder) => void;\n}\n\nexport interface PagesBuilder {\n /**\n * the input ID in OpenAPI server\n */\n id: string;\n document: ProcessedDocument;\n /**\n * add output entry.\n *\n * When the `path` property is unspecified, it will generate one.\n */\n create: (entry: OutputEntry) => void;\n\n /**\n * get file path from operation path, useful for generating output paths.\n */\n routePathToFilePath: (path: string) => string;\n\n /**\n * Extract useful info for rendering\n */\n extract: () => ExtractedInfo;\n fromExtractedWebhook: (item: WebhookItem) =>\n | {\n get displayName(): string;\n pathItem: NoReference<PathItemObject>;\n operation: NoReference<OperationObject>;\n }\n | undefined;\n fromExtractedOperation: (item: OperationItem) =>\n | {\n get displayName(): string;\n pathItem: NoReference<PathItemObject>;\n operation: NoReference<OperationObject>;\n }\n | undefined;\n fromTag: (tag: TagObject) => {\n get displayName(): string;\n };\n fromTagName: (tag: string) =>\n | {\n info: TagObject;\n get displayName(): string;\n }\n | undefined;\n}\n\ninterface ExtractedInfo {\n webhooks: (WebhookItem & { tags?: string[] })[];\n operations: (OperationItem & {\n tags?: string[];\n })[];\n}\n\nexport async function fromServer(\n server: OpenAPIServer,\n config: PagesBuilderConfig,\n): Promise<Record<string, OutputEntry[]>> {\n const schemas = await server.getSchemas();\n const generated: Record<string, OutputEntry[]> = {};\n\n const entries = Object.entries(schemas);\n if (entries.length === 0) {\n throw new Error('No input files found.');\n }\n\n for (const [id, schema] of entries) {\n generated[id] = fromSchema(id, schema, config);\n }\n\n return generated;\n}\n\nexport function fromSchema(\n schemaId: string,\n processed: ProcessedDocument,\n config: PagesBuilderConfig,\n): OutputEntry[] {\n const files: OutputEntry[] = [];\n const { toPages } = config;\n const { dereferenced } = processed;\n\n toPages({\n id: schemaId,\n document: processed,\n create(entry) {\n files.push(entry);\n },\n extract: () => extractInfo(dereferenced),\n routePathToFilePath(path) {\n return path\n .toLowerCase()\n .replaceAll('.', '-')\n .split('/')\n .flatMap((v) => {\n if (v.startsWith('{') && v.endsWith('}')) return v.slice(1, -1);\n if (v.length === 0) return [];\n return v;\n })\n .join('/');\n },\n fromExtractedWebhook(item) {\n const pathItem = dereferenced.webhooks?.[item.name];\n if (!pathItem) return;\n const operation = pathItem?.[item.method];\n if (!operation) return;\n return {\n pathItem,\n operation,\n get displayName() {\n return operation.summary || pathItem.summary || idToTitle(item.name);\n },\n };\n },\n fromExtractedOperation(item) {\n const pathItem = dereferenced.paths?.[item.path];\n if (!pathItem) return;\n const operation = pathItem?.[item.method];\n if (!operation) return;\n return {\n pathItem,\n operation,\n get displayName() {\n return (\n operation.summary ||\n pathItem.summary ||\n (operation.operationId ? idToTitle(operation.operationId) : item.path)\n );\n },\n };\n },\n fromTag(tag) {\n return {\n get displayName() {\n return getTagDisplayName(tag);\n },\n };\n },\n fromTagName(name) {\n const tag = dereferenced.tags?.find((item) => item.name === name);\n if (!tag) return;\n\n return {\n info: tag,\n ...this.fromTag(tag),\n };\n },\n });\n\n return files;\n}\n\nfunction extractInfo(document: NoReference<Document>): ExtractedInfo {\n const result: ExtractedInfo = { webhooks: [], operations: [] };\n\n for (const [path, pathItem] of Object.entries(document.paths ?? {})) {\n if (!pathItem) continue;\n\n for (const methodKey of methodKeys) {\n if (!pathItem[methodKey]) continue;\n\n result.operations.push({\n method: methodKey as OpenAPIV3_1.HttpMethods,\n path,\n tags: pathItem[methodKey]?.tags,\n });\n }\n }\n\n for (const [name, pathItem] of Object.entries(document.webhooks ?? {})) {\n if (!pathItem) continue;\n\n for (const methodKey of methodKeys) {\n if (!pathItem[methodKey]) continue;\n\n result.webhooks.push({\n method: methodKey as OpenAPIV3_1.HttpMethods,\n name,\n tags: pathItem[methodKey]?.tags,\n });\n }\n }\n\n return result;\n}\n"],"mappings":";;;;AAqGA,eAAsB,WACpB,QACA,QACwC;CACxC,MAAM,UAAU,MAAM,OAAO,YAAY;CACzC,MAAMA,YAA2C,EAAE;CAEnD,MAAM,UAAU,OAAO,QAAQ,QAAQ;AACvC,KAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,wBAAwB;AAG1C,MAAK,MAAM,CAAC,IAAI,WAAW,QACzB,WAAU,MAAM,WAAW,IAAI,QAAQ,OAAO;AAGhD,QAAO;;AAGT,SAAgB,WACd,UACA,WACA,QACe;CACf,MAAMC,QAAuB,EAAE;CAC/B,MAAM,EAAE,YAAY;CACpB,MAAM,EAAE,iBAAiB;AAEzB,SAAQ;EACN,IAAI;EACJ,UAAU;EACV,OAAO,OAAO;AACZ,SAAM,KAAK,MAAM;;EAEnB,eAAe,YAAY,aAAa;EACxC,oBAAoB,MAAM;AACxB,UAAO,KACJ,aAAa,CACb,WAAW,KAAK,IAAI,CACpB,MAAM,IAAI,CACV,SAAS,MAAM;AACd,QAAI,EAAE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,YAAY;IAC5B,CAAC;;;AAIN,MAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,SAAS,YAAY,EAAE,CAAC,EAAE;AACtE,MAAI,CAAC,SAAU;AAEf,OAAK,MAAM,aAAa,YAAY;AAClC,OAAI,CAAC,SAAS,WAAY;AAE1B,UAAO,SAAS,KAAK;IACnB,QAAQ;IACR;IACA,MAAM,SAAS,YAAY;IAC5B,CAAC;;;AAIN,QAAO"}
@@ -1,68 +1,71 @@
1
- import type { ProcessedDocument } from '../../utils/process-document.js';
2
- import type { OperationOutput, OutputGroup, PagesBuilder, PagesBuilderConfig, TagOutput, WebhookOutput } from '../../utils/pages/builder.js';
1
+ import { OperationOutput, OutputGroup, PagesBuilder, PagesBuilderConfig, TagOutput, WebhookOutput } from "./builder.js";
2
+ import { ProcessedDocument } from "../process-document.js";
3
+
4
+ //#region src/utils/pages/preset-auto.d.ts
3
5
  interface OperationConfig extends BaseConfig {
4
- /**
5
- * Generate a page for each API endpoint/operation (default).
6
- */
7
- per?: 'operation';
8
- /**
9
- * Group output using folders (Only works on `operation` mode)
10
- * - tag: `{tag}/{file}`
11
- * - route: `{endpoint}/{method}` (it will ignore the `name` option)
12
- * - none: `{file}` (default)
13
- * - a function that aligns group name (folder path) to each entry
14
- *
15
- * @defaultValue 'none'
16
- */
17
- groupBy?: 'tag' | 'route' | 'none' | ((entry: OperationOutput | WebhookOutput) => string);
18
- /**
19
- * Specify name for output file
20
- */
21
- name?: NameFn<OperationOutput | WebhookOutput> | NameFnOptions;
6
+ /**
7
+ * Generate a page for each API endpoint/operation (default).
8
+ */
9
+ per?: 'operation';
10
+ /**
11
+ * Group output using folders (Only works on `operation` mode)
12
+ * - tag: `{tag}/{file}`
13
+ * - route: `{endpoint}/{method}` (it will ignore the `name` option)
14
+ * - none: `{file}` (default)
15
+ * - a function that aligns group name (folder path) to each entry
16
+ *
17
+ * @defaultValue 'none'
18
+ */
19
+ groupBy?: 'tag' | 'route' | 'none' | ((entry: OperationOutput | WebhookOutput) => string);
20
+ /**
21
+ * Specify name for output file
22
+ */
23
+ name?: NameFn<OperationOutput | WebhookOutput> | NameFnOptions;
22
24
  }
23
25
  interface TagConfig extends BaseConfig {
24
- /**
25
- * Generate a page for each tag.
26
- */
27
- per: 'tag';
28
- /**
29
- * Specify name for output file
30
- */
31
- name?: NameFn<TagOutput> | NameFnOptions;
26
+ /**
27
+ * Generate a page for each tag.
28
+ */
29
+ per: 'tag';
30
+ /**
31
+ * Specify name for output file
32
+ */
33
+ name?: NameFn<TagOutput> | NameFnOptions;
32
34
  }
33
35
  interface SchemaConfig extends BaseConfig {
34
- /**
35
- * Generate a page for each schema file.
36
- */
37
- per: 'file';
38
- /**
39
- * Specify name for output file
40
- */
41
- name?: NameFn<OutputGroup> | NameFnOptions;
36
+ /**
37
+ * Generate a page for each schema file.
38
+ */
39
+ per: 'file';
40
+ /**
41
+ * Specify name for output file
42
+ */
43
+ name?: NameFn<OutputGroup> | NameFnOptions;
42
44
  }
43
- export type SchemaToPagesOptions = SchemaConfig | TagConfig | OperationConfig | ({
44
- per: 'custom';
45
+ type SchemaToPagesOptions = SchemaConfig | TagConfig | OperationConfig | ({
46
+ per: 'custom';
45
47
  } & PagesBuilderConfig);
46
48
  type NameFn<Entry> = (this: PagesBuilder, output: Entry, document: ProcessedDocument['dereferenced']) => string;
47
49
  interface NameFnOptions {
48
- /**
49
- * The version of algorithm used to generate file paths.
50
- *
51
- * v1: Fumadocs OpenAPI v8
52
- * v2: Fumadocs OpenAPI v9
53
- *
54
- * @defaultValue v2
55
- */
56
- algorithm?: 'v2' | 'v1';
50
+ /**
51
+ * The version of algorithm used to generate file paths.
52
+ *
53
+ * v1: Fumadocs OpenAPI v8
54
+ * v2: Fumadocs OpenAPI v9
55
+ *
56
+ * @defaultValue v2
57
+ */
58
+ algorithm?: 'v2' | 'v1';
57
59
  }
58
60
  interface BaseConfig {
59
- /**
60
- * Custom function to convert names into file names.
61
- *
62
- * By default, it only escapes whitespaces and upper case (English) characters
63
- */
64
- slugify?: (name: string) => string;
61
+ /**
62
+ * Custom function to convert names into file names.
63
+ *
64
+ * By default, it only escapes whitespaces and upper case (English) characters
65
+ */
66
+ slugify?: (name: string) => string;
65
67
  }
66
- export declare function createAutoPreset(options: SchemaToPagesOptions): PagesBuilderConfig;
67
- export {};
68
+ declare function createAutoPreset(options: SchemaToPagesOptions): PagesBuilderConfig;
69
+ //#endregion
70
+ export { SchemaToPagesOptions, createAutoPreset };
68
71
  //# sourceMappingURL=preset-auto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"preset-auto.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/preset-auto.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EACV,eAAe,EAEf,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,SAAS,EACT,aAAa,EACd,MAAM,uBAAuB,CAAC;AAG/B,UAAU,eAAgB,SAAQ,UAAU;IAC1C;;OAEG;IACH,GAAG,CAAC,EAAE,WAAW,CAAC;IAElB;;;;;;;;OAQG;IACH,OAAO,CAAC,EACJ,KAAK,GACL,OAAO,GACP,MAAM,GACN,CAAC,CAAC,KAAK,EAAE,eAAe,GAAG,aAAa,KAAK,MAAM,CAAC,CAAC;IAEzD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,eAAe,GAAG,aAAa,CAAC,GAAG,aAAa,CAAC;CAChE;AAED,UAAU,SAAU,SAAQ,UAAU;IACpC;;OAEG;IACH,GAAG,EAAE,KAAK,CAAC;IAEX;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,GAAG,aAAa,CAAC;CAC1C;AAED,UAAU,YAAa,SAAQ,UAAU;IACvC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,aAAa,CAAC;C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