fumadocs-openapi 12.5.1 → 12.5.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 (55) hide show
  1. package/css/generated/shared.css +1 -1
  2. package/dist/.translations/index.d.ts +0 -61
  3. package/dist/.translations/keys.js +1 -62
  4. package/dist/generate-file.js +19 -21
  5. package/dist/index.browser.d.ts +8 -3
  6. package/dist/index.browser.js +11 -1
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +2 -1
  9. package/dist/packages/shared-api/dist/.translations/index.d.ts +52 -4
  10. package/dist/packages/shared-api/dist/.translations/keys.js +53 -5
  11. package/dist/packages/shared-api/dist/codegen.d.ts +21 -1
  12. package/dist/packages/shared-api/dist/codegen.js +63 -1
  13. package/dist/packages/shared-api/dist/components/copy-typescript.js +31 -0
  14. package/dist/packages/shared-api/dist/components/defaults.js +13 -19
  15. package/dist/{ui → packages/shared-api/dist}/components/dialog.js +17 -3
  16. package/dist/packages/shared-api/dist/components/example.js +125 -0
  17. package/dist/{ui/playground/components → packages/shared-api/dist/components/playground}/fields.js +14 -11
  18. package/dist/packages/shared-api/dist/components/playground/json-editor.js +54 -0
  19. package/dist/packages/shared-api/dist/components/playground/panels.js +330 -0
  20. package/dist/packages/shared-api/dist/components/playground/param-input.js +54 -0
  21. package/dist/packages/shared-api/dist/components/playground/result.js +187 -0
  22. package/dist/packages/shared-api/dist/components/playground/schema.js +5 -3
  23. package/dist/packages/shared-api/dist/components/playground/server-select.js +130 -0
  24. package/dist/packages/shared-api/dist/components/schema/client.js +23 -1
  25. package/dist/{ui → packages/shared-api/dist}/components/segmented.js +2 -2
  26. package/dist/packages/shared-api/dist/components/select-tab.js +8 -3
  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/requests/generators/curl.js +6 -9
  30. package/dist/requests/generators/go.js +5 -5
  31. package/dist/requests/generators/rust.js +3 -2
  32. package/dist/requests/media/adapter.js +16 -7
  33. package/dist/requests/media/resolve-adapter.js +15 -12
  34. package/dist/requests/string-utils.js +7 -29
  35. package/dist/server/index.d.ts +2 -7
  36. package/dist/server/index.js +26 -64
  37. package/dist/ui/base.js +2 -2
  38. package/dist/ui/operation/index.js +7 -38
  39. package/dist/ui/operation/usage-tabs.js +49 -101
  40. package/dist/ui/playground/client.js +22 -51
  41. package/dist/ui/playground/components/{oauth-panel.js → auth.js} +20 -8
  42. package/dist/ui/playground/components/request-panel.js +14 -259
  43. package/dist/ui/playground/components/response-panel.js +11 -20
  44. package/dist/ui/playground/components/result-display.d.ts +0 -1
  45. package/dist/ui/playground/components/result-display.js +46 -182
  46. package/dist/ui/playground/components/server-select.js +24 -122
  47. package/dist/ui/playground/components/url-bar.js +8 -66
  48. package/dist/utils/create-page.d.ts +0 -4
  49. package/dist/utils/create-page.js +3 -5
  50. package/dist/utils/pages/builder.js +2 -2
  51. package/dist/utils/pages/preset-auto.js +139 -137
  52. package/dist/utils/pages/to-static-data.js +2 -7
  53. package/dist/utils/pages/to-text.js +2 -2
  54. package/package.json +6 -6
  55. 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,154 +85,127 @@ 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 tags = doc.tags ?? [];
160
- for (const tag of tags) {
161
- const { displayName } = builder.fromTag(tag);
162
- const entry = {
163
- type: "page",
164
- path: "",
181
+ for (const item of items.operations) {
182
+ const { pathItem, operation, displayName } = builder.fromExtractedOperation(item);
183
+ add({
184
+ type: "operation",
165
185
  schemaId: builder.id,
186
+ item,
166
187
  info: {
167
188
  title: displayName,
168
- description: tag.description
169
- },
170
- webhooks: items.webhooks.filter((webhook) => webhook.tags?.includes(tag.name)),
171
- operations: items.operations.filter((op) => op.tags?.includes(tag.name)),
172
- tag
173
- };
174
- entry.path = `${nameFn.call(builder, entry)}.mdx`;
175
- 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);
176
206
  }
177
- return;
178
- }
179
- const entries = [];
180
- for (const op of items.operations) {
181
- const { pathItem, operation, displayName } = builder.fromExtractedOperation(op);
182
- entries.push({
183
- type: "operation",
184
- schemaId: builder.id,
185
- item: op,
186
- info: {
187
- title: displayName,
188
- description: operation.description ?? pathItem.description,
189
- deprecated: operation.deprecated
190
- }
191
- });
192
- }
193
- for (const webhook of items.webhooks) {
194
- const { pathItem, operation, displayName } = builder.fromExtractedWebhook(webhook);
195
- entries.push({
196
- type: "webhook",
197
- schemaId: builder.id,
198
- info: {
199
- title: displayName,
200
- description: operation.description ?? pathItem.description,
201
- deprecated: operation.deprecated
202
- },
203
- item: webhook
204
- });
205
207
  }
206
- for (const entry of group(builder, entries)) builder.create(entry);
208
+ for (const entry of root) builder.create(entry);
207
209
  } };
208
210
  }
209
211
  //#endregion
@@ -1,15 +1,10 @@
1
+ import { dereferenceBundledDocument } from "../document/dereference.js";
1
2
  import { idToTitle } from "../../packages/shared-api/dist/utils/id-to-title.js";
2
- import { createMagicProxy } from "@scalar/json-magic/magic-proxy";
3
3
  import { dereference } from "@fumadocs/json-schema";
4
4
  import Slugger from "github-slugger";
5
5
  //#region src/utils/pages/to-static-data.ts
6
- const proxyCache = /* @__PURE__ */ new WeakMap();
7
6
  function toStaticData(page, doc) {
8
- let proxied = proxyCache.get(doc);
9
- if (!proxied) {
10
- proxied = createMagicProxy(doc);
11
- proxyCache.set(doc, proxied);
12
- }
7
+ const proxied = dereferenceBundledDocument(doc).dereferenced;
13
8
  const slugger = new Slugger();
14
9
  const toc = [];
15
10
  const structuredData = {
@@ -1,4 +1,4 @@
1
- import { doubleQuote } from "../../requests/string-utils.js";
1
+ import { doubleQuote, jsxString } from "../../requests/string-utils.js";
2
2
  import { getPageProps } from "./builder.js";
3
3
  import { toStaticData } from "./to-static-data.js";
4
4
  import { stringify } from "yaml";
@@ -49,7 +49,7 @@ function generateDocument(frontmatter, content, options) {
49
49
  return out.join("\n\n");
50
50
  }
51
51
  function pageContent({ showTitle, showDescription, document, webhooks, operations }) {
52
- const propStrs = [`document=${doubleQuote(document)}`];
52
+ const propStrs = [`document=${jsxString(document)}`];
53
53
  if (webhooks) propStrs.push(`webhooks={${JSON.stringify(webhooks.map((item) => ({
54
54
  name: item.name,
55
55
  method: item.method
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "12.5.1",
3
+ "version": "12.5.3",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "Docs",
@@ -54,9 +54,9 @@
54
54
  "dependencies": {
55
55
  "@base-ui/react": "^1.8.0",
56
56
  "@fuma-translate/react": "^1.0.2",
57
- "@fumadocs/json-schema": "^0.3.1",
57
+ "@fumadocs/json-schema": "^0.3.3",
58
58
  "@fumari/json-schema-ts": "^1.0.2",
59
- "@fumari/stf": "^1.1.1",
59
+ "@fumari/stf": "^1.1.2",
60
60
  "@scalar/json-magic": "^0.15.4",
61
61
  "@scalar/openapi-upgrader": "^0.4.1",
62
62
  "chokidar": "^5.0.0",
@@ -79,10 +79,10 @@
79
79
  "@types/react-dom": "^19.3.0",
80
80
  "fast-content-type-parse": "^4.0.0",
81
81
  "fuma-cli": "^0.3.1",
82
- "fumadocs-core": "16.17.5",
83
- "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.5",
82
+ "fumadocs-core": "16.17.6",
83
+ "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.6",
84
84
  "json-schema-typed": "^8.0.2",
85
- "shared-api": "0.2.12",
85
+ "shared-api": "0.2.14",
86
86
  "tsconfig": "0.0.0",
87
87
  "tsdown": "0.23.0",
88
88
  "xml-js": "^1.6.11"
@@ -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 };