fumadocs-openapi 12.5.2 → 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.
- package/css/generated/shared.css +1 -1
- package/dist/.translations/index.d.ts +0 -32
- package/dist/.translations/keys.js +0 -32
- package/dist/generate-file.js +15 -17
- package/dist/index.browser.d.ts +8 -3
- package/dist/index.browser.js +11 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/packages/shared-api/dist/.translations/index.d.ts +34 -4
- package/dist/packages/shared-api/dist/.translations/keys.js +34 -4
- package/dist/packages/shared-api/dist/codegen.d.ts +21 -1
- package/dist/packages/shared-api/dist/codegen.js +63 -1
- package/dist/packages/shared-api/dist/components/copy-typescript.js +31 -0
- package/dist/packages/shared-api/dist/components/dialog.js +15 -1
- package/dist/packages/shared-api/dist/components/example.js +90 -16
- package/dist/packages/shared-api/dist/components/playground/fields.js +3 -3
- package/dist/packages/shared-api/dist/components/playground/json-editor.js +54 -0
- package/dist/packages/shared-api/dist/components/playground/panels.js +88 -5
- package/dist/packages/shared-api/dist/components/playground/result.js +187 -0
- package/dist/packages/shared-api/dist/components/schema/client.js +22 -0
- package/dist/packages/shared-api/dist/components/select-tab.js +8 -3
- package/dist/packages/shared-api/dist/source.d.ts +11 -0
- package/dist/packages/shared-api/dist/source.js +50 -0
- package/dist/requests/generators/curl.js +6 -9
- package/dist/requests/generators/go.js +5 -5
- package/dist/requests/generators/rust.js +3 -2
- package/dist/requests/media/adapter.js +16 -7
- package/dist/requests/media/resolve-adapter.js +15 -12
- package/dist/requests/string-utils.js +4 -32
- package/dist/server/index.d.ts +2 -7
- package/dist/server/index.js +26 -64
- package/dist/ui/base.js +2 -2
- package/dist/ui/operation/index.js +5 -36
- package/dist/ui/operation/usage-tabs.js +45 -56
- package/dist/ui/playground/client.js +18 -50
- package/dist/ui/playground/components/{oauth-panel.js → auth.js} +19 -7
- package/dist/ui/playground/components/request-panel.js +3 -65
- package/dist/ui/playground/components/response-panel.js +7 -18
- package/dist/ui/playground/components/result-display.js +45 -166
- package/dist/ui/playground/components/url-bar.js +2 -19
- package/dist/utils/create-page.d.ts +0 -4
- package/dist/utils/create-page.js +3 -5
- package/dist/utils/pages/preset-auto.js +139 -148
- package/package.json +5 -5
- 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
|
|
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
|
|
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
|
|
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
|
-
|
|
31
|
-
const groups = /* @__PURE__ */ new Map();
|
|
32
|
-
const rest = [];
|
|
30
|
+
return { toPages(builder) {
|
|
33
31
|
const doc = builder.document;
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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 =
|
|
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 =
|
|
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
|
|
88
|
+
path: path.join(parent?.path ?? "", slugify(name))
|
|
60
89
|
};
|
|
61
|
-
|
|
62
|
-
(parent
|
|
90
|
+
groups.set(name, group);
|
|
91
|
+
(parent?.entries ?? root).push(group);
|
|
63
92
|
return group;
|
|
64
93
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
141
|
+
info: { title },
|
|
73
142
|
entries: [],
|
|
74
143
|
schemaId: builder.id,
|
|
75
|
-
path:
|
|
144
|
+
path: dir
|
|
76
145
|
};
|
|
77
|
-
groups.set(
|
|
146
|
+
groups.set(dir, group);
|
|
147
|
+
root.push(group);
|
|
78
148
|
}
|
|
79
|
-
group
|
|
80
|
-
...entry,
|
|
81
|
-
path: path$1.join(groupName, `${entry.item.method.toLowerCase()}.mdx`)
|
|
82
|
-
});
|
|
83
|
-
break;
|
|
149
|
+
return group;
|
|
84
150
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
157
|
+
path: path.join(dir, file)
|
|
105
158
|
});
|
|
159
|
+
return;
|
|
106
160
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
|
166
|
+
path: path.join(group.path, file)
|
|
128
167
|
});
|
|
129
|
-
break;
|
|
130
168
|
}
|
|
131
|
-
|
|
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:
|
|
178
|
+
path: file
|
|
134
179
|
});
|
|
135
180
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "12.5.
|
|
3
|
+
"version": "12.5.3",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -54,7 +54,7 @@
|
|
|
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.
|
|
57
|
+
"@fumadocs/json-schema": "^0.3.3",
|
|
58
58
|
"@fumari/json-schema-ts": "^1.0.2",
|
|
59
59
|
"@fumari/stf": "^1.1.2",
|
|
60
60
|
"@scalar/json-magic": "^0.15.4",
|
|
@@ -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.
|
|
83
|
-
"fumadocs-ui": "npm:@fumadocs/base-ui@16.17.
|
|
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.
|
|
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 };
|