fumadocs-openapi 12.5.2 → 12.5.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 (62) hide show
  1. package/css/generated/shared.css +1 -1
  2. package/dist/.translations/index.d.ts +0 -32
  3. package/dist/.translations/keys.js +0 -32
  4. package/dist/_virtual/_rolldown/runtime.js +2 -11
  5. package/dist/generate-file.d.ts +2 -1
  6. package/dist/generate-file.js +15 -17
  7. package/dist/index.browser.d.ts +8 -3
  8. package/dist/index.browser.js +11 -1
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js +2 -1
  11. package/dist/node_modules/.pnpm/{fast-content-type-parse@4.0.0 → fast-content-type-parse@4.0.1}/node_modules/fast-content-type-parse/index.js +1 -1
  12. package/dist/packages/shared-api/dist/.translations/index.d.ts +34 -4
  13. package/dist/packages/shared-api/dist/.translations/keys.js +34 -4
  14. package/dist/packages/shared-api/dist/codegen.d.ts +2 -6
  15. package/dist/packages/shared-api/dist/codegen.js +63 -1
  16. package/dist/packages/shared-api/dist/components/collapsible.js +2 -2
  17. package/dist/packages/shared-api/dist/components/copy-typescript.js +31 -0
  18. package/dist/packages/shared-api/dist/components/dialog.js +15 -1
  19. package/dist/packages/shared-api/dist/components/example.js +90 -16
  20. package/dist/packages/shared-api/dist/components/playground/fields.js +7 -7
  21. package/dist/packages/shared-api/dist/components/playground/json-editor.js +54 -0
  22. package/dist/packages/shared-api/dist/components/playground/panels.js +88 -5
  23. package/dist/packages/shared-api/dist/components/playground/result.js +187 -0
  24. package/dist/packages/shared-api/dist/components/schema/client.js +22 -0
  25. package/dist/packages/shared-api/dist/components/select-tab.js +8 -3
  26. package/dist/packages/shared-api/dist/components/select.js +2 -2
  27. package/dist/packages/shared-api/dist/source.d.ts +11 -0
  28. package/dist/packages/shared-api/dist/source.js +50 -0
  29. package/dist/packages/shared-api/dist/utils/cn.js +1 -2
  30. package/dist/packages/shared-api/dist/utils/document-cache.js +16 -0
  31. package/dist/playground/auth.d.ts +2 -1
  32. package/dist/playground/fetcher.js +1 -1
  33. package/dist/requests/generators/curl.js +6 -9
  34. package/dist/requests/generators/go.js +5 -5
  35. package/dist/requests/generators/index.d.ts +1 -1
  36. package/dist/requests/generators/rust.js +3 -2
  37. package/dist/requests/media/adapter.d.ts +2 -1
  38. package/dist/requests/media/adapter.js +16 -7
  39. package/dist/requests/media/resolve-adapter.js +15 -12
  40. package/dist/requests/string-utils.js +4 -32
  41. package/dist/server/index.d.ts +7 -8
  42. package/dist/server/index.js +28 -66
  43. package/dist/server/proxy.d.ts +2 -1
  44. package/dist/ui/base.js +2 -2
  45. package/dist/ui/index.d.ts +2 -2
  46. package/dist/ui/operation/index.js +5 -36
  47. package/dist/ui/operation/usage-tabs.js +45 -56
  48. package/dist/ui/playground/client.js +18 -50
  49. package/dist/ui/playground/components/{oauth-panel.js → auth.js} +19 -7
  50. package/dist/ui/playground/components/request-panel.js +3 -65
  51. package/dist/ui/playground/components/response-panel.js +7 -18
  52. package/dist/ui/playground/components/result-display.js +45 -166
  53. package/dist/ui/playground/components/url-bar.js +2 -19
  54. package/dist/utils/cn.js +1 -2
  55. package/dist/utils/create-page.d.ts +4 -6
  56. package/dist/utils/create-page.js +12 -8
  57. package/dist/utils/pages/builder.d.ts +4 -2
  58. package/dist/utils/pages/preset-auto.d.ts +2 -1
  59. package/dist/utils/pages/preset-auto.js +139 -148
  60. package/dist/utils/use-server.d.ts +2 -1
  61. package/package.json +17 -17
  62. package/dist/ui/playground/status-info.js +0 -39
@@ -1,6 +1,6 @@
1
1
  import { getTagDisplayName } from "../schema.js";
2
2
  import { dereference } from "@fumadocs/json-schema";
3
- import * as path$1 from "node:path";
3
+ import * as path from "node:path";
4
4
  //#region src/utils/pages/preset-auto.ts
5
5
  function createAutoPreset(options) {
6
6
  if (options.per === "custom") return options;
@@ -15,37 +15,66 @@ function createAutoPreset(options) {
15
15
  if (result.type === "page") {
16
16
  if (result.tag) return slugify(result.tag.name);
17
17
  const schemaId = result.schemaId;
18
- return schemaId.startsWith("http://") || schemaId.startsWith("https://") ? "index" : path$1.basename(schemaId, path$1.extname(schemaId));
18
+ return schemaId.startsWith("http://") || schemaId.startsWith("https://") ? "index" : path.basename(schemaId, path.extname(schemaId));
19
19
  }
20
20
  if (result.type === "operation") {
21
21
  const operation = this.document.paths[result.item.path][result.item.method];
22
22
  if (algorithm === "v2" && operation.operationId) return operation.operationId;
23
- return path$1.join(this.routePathToFilePath(result.item.path), result.item.method.toLowerCase());
23
+ return path.join(this.routePathToFilePath(result.item.path), result.item.method.toLowerCase());
24
24
  }
25
25
  const hook = dereference(this.document.webhooks[result.item.name])[result.item.method];
26
26
  if (algorithm === "v2" && hook.operationId) return hook.operationId;
27
27
  return slugify(result.item.name);
28
28
  };
29
29
  }
30
- function group(builder, entries) {
31
- const groups = /* @__PURE__ */ new Map();
32
- const rest = [];
30
+ return { toPages(builder) {
33
31
  const doc = builder.document;
34
- const { groupBy = "none" } = options;
35
- const docTags = /* @__PURE__ */ new Map();
36
- if (groupBy === "tag") {
37
- for (const tag of doc.tags ?? []) if (tag.name) docTags.set(tag.name, tag);
32
+ const items = builder.extract();
33
+ if (options.per === "file") {
34
+ const entry = {
35
+ type: "page",
36
+ schemaId: builder.id,
37
+ path: "",
38
+ info: {
39
+ title: doc.info?.title ?? "Unknown",
40
+ description: doc.info?.description
41
+ },
42
+ ...items
43
+ };
44
+ entry.path = `${nameFn.call(builder, entry)}.mdx`;
45
+ builder.create(entry);
46
+ return;
47
+ }
48
+ const root = [];
49
+ const groups = /* @__PURE__ */ new Map();
50
+ const tags = /* @__PURE__ */ new Map();
51
+ const hidden = /* @__PURE__ */ new Set();
52
+ for (const tag of doc.tags ?? []) {
53
+ if (!tag.name) continue;
54
+ tags.set(tag.name, tag);
55
+ if (tag.kind && tag.kind !== "nav") hidden.add(tag.name);
38
56
  }
39
- const tagGroups = /* @__PURE__ */ new Map();
40
57
  let warnedUntagged = false;
41
- function tagGroup(name, seen) {
42
- let group = tagGroups.get(name);
58
+ /** the navigation tags of an operation, `unknown` if none */
59
+ function navTags(names = []) {
60
+ const out = [];
61
+ for (const name of names) if (!hidden.has(name) && !out.includes(name)) out.push(name);
62
+ if (out.length > 0) return out;
63
+ if (!warnedUntagged) {
64
+ warnedUntagged = true;
65
+ console.warn("[Fumadocs OpenAPI] found operations without tags, they will be grouped under \"unknown\".");
66
+ }
67
+ return ["unknown"];
68
+ }
69
+ /** the folder of a tag, nested in the folder of its `parent` */
70
+ function tagFolder(name, seen) {
71
+ let group = groups.get(name);
43
72
  if (group) return group;
44
- const tag = docTags.get(name);
73
+ const tag = tags.get(name);
45
74
  let parent;
46
75
  if (tag?.parent) {
47
76
  (seen ??= /* @__PURE__ */ new Set()).add(name);
48
- if (!seen.has(tag.parent)) parent = tagGroup(tag.parent, seen);
77
+ if (!seen.has(tag.parent)) parent = tagFolder(tag.parent, seen);
49
78
  }
50
79
  group = {
51
80
  type: "group",
@@ -56,166 +85,128 @@ function createAutoPreset(options) {
56
85
  tag,
57
86
  entries: [],
58
87
  schemaId: builder.id,
59
- path: path$1.join(parent?.path ?? "", slugify(name))
88
+ path: path.join(parent?.path ?? "", slugify(name))
60
89
  };
61
- tagGroups.set(name, group);
62
- (parent ? parent.entries : rest).push(group);
90
+ groups.set(name, group);
91
+ (parent?.entries ?? root).push(group);
63
92
  return group;
64
93
  }
65
- for (const entry of entries) switch (groupBy) {
66
- case "route": {
67
- const groupName = builder.routePathToFilePath(entry.type === "operation" ? entry.item.path : entry.item.name);
68
- let group = groups.get(groupName);
94
+ if (options.per === "tag") {
95
+ const pages = /* @__PURE__ */ new Map();
96
+ const parents = /* @__PURE__ */ new Set();
97
+ for (const [name, tag] of tags) {
98
+ pages.set(name, {
99
+ operations: [],
100
+ webhooks: []
101
+ });
102
+ if (tag.parent) parents.add(tag.parent);
103
+ }
104
+ function tagItems(name) {
105
+ let out = pages.get(name);
106
+ if (!out) pages.set(name, out = {
107
+ operations: [],
108
+ webhooks: []
109
+ });
110
+ return out;
111
+ }
112
+ for (const item of items.operations) for (const name of navTags(item.tags)) tagItems(name).operations.push(item);
113
+ for (const item of items.webhooks) for (const name of navTags(item.tags)) tagItems(name).webhooks.push(item);
114
+ for (const [name, { operations, webhooks }] of pages) {
115
+ if (operations.length === 0 && webhooks.length === 0) continue;
116
+ const tag = tags.get(name) ?? { name };
117
+ const page = {
118
+ type: "page",
119
+ path: "",
120
+ schemaId: builder.id,
121
+ info: {
122
+ title: getTagDisplayName(tag),
123
+ description: tag.description
124
+ },
125
+ operations,
126
+ webhooks,
127
+ tag
128
+ };
129
+ const folder = parents.has(name) ? name : tag.parent;
130
+ const group = folder ? tagFolder(folder) : void 0;
131
+ page.path = path.join(group?.path ?? "", `${nameFn.call(builder, page)}.mdx`);
132
+ (group?.entries ?? root).push(page);
133
+ }
134
+ } else {
135
+ const { groupBy = "none" } = options;
136
+ function folder(dir, title) {
137
+ let group = groups.get(dir);
69
138
  if (!group) {
70
139
  group = {
71
140
  type: "group",
72
- info: { title: groupName },
141
+ info: { title },
73
142
  entries: [],
74
143
  schemaId: builder.id,
75
- path: groupName
144
+ path: dir
76
145
  };
77
- groups.set(groupName, group);
146
+ groups.set(dir, group);
147
+ root.push(group);
78
148
  }
79
- group.entries.push({
80
- ...entry,
81
- path: path$1.join(groupName, `${entry.item.method.toLowerCase()}.mdx`)
82
- });
83
- break;
149
+ return group;
84
150
  }
85
- case "tag": {
86
- const operation = entry.type === "operation" ? dereference(doc.paths?.[entry.item.path])?.[entry.item.method] : dereference(doc.webhooks?.[entry.item.name])?.[entry.item.method];
87
- const tags = [];
88
- for (const name of operation?.tags ?? []) {
89
- const kind = docTags.get(name)?.kind;
90
- if (!kind || kind === "nav") tags.push(name);
91
- }
92
- if (tags.length === 0) {
93
- if (!warnedUntagged) {
94
- warnedUntagged = true;
95
- console.warn("[Fumadocs OpenAPI] found operations without tags, they will be grouped under \"unknown\".");
96
- }
97
- tags.push("unknown");
98
- }
99
- const fileName = `${nameFn.call(builder, entry)}.mdx`;
100
- for (const name of tags) {
101
- const group = tagGroup(name);
102
- group.entries.push({
151
+ function add(entry, tagNames) {
152
+ if (groupBy === "route") {
153
+ const dir = builder.routePathToFilePath(entry.type === "operation" ? entry.item.path : entry.item.name);
154
+ const file = `${entry.item.method.toLowerCase()}.mdx`;
155
+ folder(dir, dir).entries.push({
103
156
  ...entry,
104
- path: path$1.join(group.path, fileName)
157
+ path: path.join(dir, file)
105
158
  });
159
+ return;
106
160
  }
107
- break;
108
- }
109
- default: {
110
- const fileName = `${nameFn.call(builder, entry)}.mdx`;
111
- if (typeof groupBy === "function") {
112
- const groupDisplayName = groupBy(entry);
113
- const groupName = slugify(groupDisplayName);
114
- let group = groups.get(groupName);
115
- if (!group) {
116
- group = {
117
- type: "group",
118
- info: { title: groupDisplayName },
119
- entries: [],
120
- schemaId: builder.id,
121
- path: groupName
122
- };
123
- groups.set(groupName, group);
124
- }
161
+ const file = `${nameFn.call(builder, entry)}.mdx`;
162
+ if (groupBy === "tag") for (const name of navTags(tagNames)) {
163
+ const group = tagFolder(name);
125
164
  group.entries.push({
126
165
  ...entry,
127
- path: path$1.join(groupName, fileName)
166
+ path: path.join(group.path, file)
128
167
  });
129
- break;
130
168
  }
131
- rest.push({
169
+ else if (typeof groupBy === "function") {
170
+ const title = groupBy(entry);
171
+ const dir = slugify(title);
172
+ folder(dir, title).entries.push({
173
+ ...entry,
174
+ path: path.join(dir, file)
175
+ });
176
+ } else root.push({
132
177
  ...entry,
133
- path: fileName
178
+ path: file
134
179
  });
135
180
  }
136
- }
137
- rest.push(...groups.values());
138
- return rest;
139
- }
140
- return { toPages(builder) {
141
- const doc = builder.document;
142
- const items = builder.extract();
143
- if (options.per === "file") {
144
- const entry = {
145
- type: "page",
146
- schemaId: builder.id,
147
- path: "",
148
- info: {
149
- title: doc.info?.title ?? "Unknown",
150
- description: doc.info?.description
151
- },
152
- ...items
153
- };
154
- entry.path = `${nameFn.call(builder, entry)}.mdx`;
155
- builder.create(entry);
156
- return;
157
- }
158
- if (options.per === "tag") {
159
- const operations = groupByTag(items.operations);
160
- const webhooks = groupByTag(items.webhooks);
161
- for (const tag of doc.tags ?? []) {
162
- const { displayName } = builder.fromTag(tag);
163
- const entry = {
164
- type: "page",
165
- path: "",
181
+ for (const item of items.operations) {
182
+ const { pathItem, operation, displayName } = builder.fromExtractedOperation(item);
183
+ add({
184
+ type: "operation",
166
185
  schemaId: builder.id,
186
+ item,
167
187
  info: {
168
188
  title: displayName,
169
- description: tag.description
170
- },
171
- webhooks: webhooks.get(tag.name) ?? [],
172
- operations: operations.get(tag.name) ?? [],
173
- tag
174
- };
175
- entry.path = `${nameFn.call(builder, entry)}.mdx`;
176
- builder.create(entry);
189
+ description: operation.description ?? pathItem.description,
190
+ deprecated: operation.deprecated
191
+ }
192
+ }, item.tags);
193
+ }
194
+ for (const item of items.webhooks) {
195
+ const { pathItem, operation, displayName } = builder.fromExtractedWebhook(item);
196
+ add({
197
+ type: "webhook",
198
+ schemaId: builder.id,
199
+ item,
200
+ info: {
201
+ title: displayName,
202
+ description: operation.description ?? pathItem.description,
203
+ deprecated: operation.deprecated
204
+ }
205
+ }, item.tags);
177
206
  }
178
- return;
179
- }
180
- const entries = [];
181
- for (const op of items.operations) {
182
- const { pathItem, operation, displayName } = builder.fromExtractedOperation(op);
183
- entries.push({
184
- type: "operation",
185
- schemaId: builder.id,
186
- item: op,
187
- info: {
188
- title: displayName,
189
- description: operation.description ?? pathItem.description,
190
- deprecated: operation.deprecated
191
- }
192
- });
193
- }
194
- for (const webhook of items.webhooks) {
195
- const { pathItem, operation, displayName } = builder.fromExtractedWebhook(webhook);
196
- entries.push({
197
- type: "webhook",
198
- schemaId: builder.id,
199
- info: {
200
- title: displayName,
201
- description: operation.description ?? pathItem.description,
202
- deprecated: operation.deprecated
203
- },
204
- item: webhook
205
- });
206
207
  }
207
- for (const entry of group(builder, entries)) builder.create(entry);
208
+ for (const entry of root) builder.create(entry);
208
209
  } };
209
210
  }
210
- /** items by the names of their tags, in their order */
211
- function groupByTag(items) {
212
- const out = /* @__PURE__ */ new Map();
213
- for (const item of items) for (const name of item.tags ?? []) {
214
- const list = out.get(name);
215
- if (!list) out.set(name, [item]);
216
- else if (list.at(-1) !== item) list.push(item);
217
- }
218
- return out;
219
- }
220
211
  //#endregion
221
212
  export { createAutoPreset };
@@ -21,4 +21,5 @@ interface ServerContextType {
21
21
  setServerVariables: (value: Record<string, string>) => void;
22
22
  }
23
23
  export declare function useServer(): ServerContextType;
24
- //#endregion
24
+ //#endregion
25
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "12.5.2",
3
+ "version": "12.5.4",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "Docs",
@@ -52,39 +52,39 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "@base-ui/react": "^1.8.0",
55
+ "@base-ui/react": "^1.9.0",
56
56
  "@fuma-translate/react": "^1.0.2",
57
- "@fumadocs/json-schema": "^0.3.2",
57
+ "@fumadocs/json-schema": "^0.3.4",
58
58
  "@fumari/json-schema-ts": "^1.0.2",
59
59
  "@fumari/stf": "^1.1.2",
60
- "@scalar/json-magic": "^0.15.4",
61
- "@scalar/openapi-upgrader": "^0.4.1",
60
+ "@scalar/json-magic": "^0.16.0",
61
+ "@scalar/openapi-upgrader": "^0.4.5",
62
62
  "chokidar": "^5.0.0",
63
63
  "class-variance-authority": "^0.7.1",
64
- "cn": "^0.4.0",
64
+ "cn": "^0.5.0",
65
65
  "github-slugger": "^2.0.0",
66
66
  "hast-util-to-jsx-runtime": "^2.3.6",
67
- "lucide-react": "^1.50.0",
67
+ "lucide-react": "^1.59.0",
68
68
  "remark": "^15.0.1",
69
69
  "remark-rehype": "^11.1.2",
70
70
  "shiki": "^4.5.0",
71
- "undici": "^7.29.1",
71
+ "undici": "^8.12.2",
72
72
  "yaml": "^2.9.1"
73
73
  },
74
74
  "devDependencies": {
75
- "@scalar/api-client-react": "^2.0.54",
75
+ "@scalar/api-client-react": "^2.0.58",
76
76
  "@tailwindcss/oxide": "^4.3.3",
77
- "@types/node": "26.6.4",
77
+ "@types/node": "26.6.5",
78
78
  "@types/react": "^19.3.0",
79
79
  "@types/react-dom": "^19.3.0",
80
- "fast-content-type-parse": "^4.0.0",
80
+ "fast-content-type-parse": "^4.0.1",
81
81
  "fuma-cli": "^0.3.1",
82
- "fumadocs-core": "16.17.5",
83
- "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.5",
84
- "json-schema-typed": "^8.0.2",
85
- "shared-api": "0.2.13",
82
+ "fumadocs-core": "16.17.7",
83
+ "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.7",
84
+ "json-schema-typed": "^9.0.0",
85
+ "shared-api": "0.2.15",
86
86
  "tsconfig": "0.0.0",
87
- "tsdown": "0.23.0",
87
+ "tsdown": "0.23.1",
88
88
  "xml-js": "^1.6.11"
89
89
  },
90
90
  "peerDependencies": {
@@ -108,7 +108,7 @@
108
108
  }
109
109
  },
110
110
  "inlinedDependencies": {
111
- "fast-content-type-parse": "4.0.0",
111
+ "fast-content-type-parse": "4.0.1",
112
112
  "xml-js": "1.6.11"
113
113
  },
114
114
  "scripts": {
@@ -1,39 +0,0 @@
1
- import { useTranslations } from "@fuma-translate/react";
2
- //#region src/ui/playground/status-info.tsx
3
- function useStatusInfo(status) {
4
- const t = useTranslations({ note: "playground status info" });
5
- const descriptions = {
6
- 200: t("OK"),
7
- 201: t("Created"),
8
- 202: t("Accepted"),
9
- 204: t("No Content"),
10
- 301: t("Moved Permanently"),
11
- 302: t("Found"),
12
- 304: t("Not Modified"),
13
- 400: t("Bad Request"),
14
- 401: t("Unauthorized"),
15
- 403: t("Forbidden"),
16
- 404: t("Not Found"),
17
- 405: t("Method Not Allowed"),
18
- 409: t("Conflict"),
19
- 422: t("Unprocessable Content"),
20
- 429: t("Too Many Requests"),
21
- 500: t("Internal Server Error"),
22
- 502: t("Bad Gateway"),
23
- 503: t("Service Unavailable")
24
- };
25
- if (status >= 200 && status < 300) return {
26
- color: "bg-green-500",
27
- description: descriptions[status] ?? t("Successful")
28
- };
29
- if (status >= 300 && status < 400) return {
30
- color: "bg-blue-500",
31
- description: descriptions[status] ?? t("Redirect")
32
- };
33
- return {
34
- color: status >= 400 && status < 500 ? "bg-amber-500" : "bg-red-500",
35
- description: descriptions[status] ?? t("Error")
36
- };
37
- }
38
- //#endregion
39
- export { useStatusInfo };