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.
- package/css/generated/shared.css +1 -1
- package/dist/.translations/index.d.ts +0 -61
- package/dist/.translations/keys.js +1 -62
- package/dist/generate-file.js +19 -21
- 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 +52 -4
- package/dist/packages/shared-api/dist/.translations/keys.js +53 -5
- 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/defaults.js +13 -19
- package/dist/{ui → packages/shared-api/dist}/components/dialog.js +17 -3
- package/dist/packages/shared-api/dist/components/example.js +125 -0
- package/dist/{ui/playground/components → packages/shared-api/dist/components/playground}/fields.js +14 -11
- package/dist/packages/shared-api/dist/components/playground/json-editor.js +54 -0
- package/dist/packages/shared-api/dist/components/playground/panels.js +330 -0
- package/dist/packages/shared-api/dist/components/playground/param-input.js +54 -0
- package/dist/packages/shared-api/dist/components/playground/result.js +187 -0
- package/dist/packages/shared-api/dist/components/playground/schema.js +5 -3
- package/dist/packages/shared-api/dist/components/playground/server-select.js +130 -0
- package/dist/packages/shared-api/dist/components/schema/client.js +23 -1
- package/dist/{ui → packages/shared-api/dist}/components/segmented.js +2 -2
- 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 +7 -29
- 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 +7 -38
- package/dist/ui/operation/usage-tabs.js +49 -101
- package/dist/ui/playground/client.js +22 -51
- package/dist/ui/playground/components/{oauth-panel.js → auth.js} +20 -8
- package/dist/ui/playground/components/request-panel.js +14 -259
- package/dist/ui/playground/components/response-panel.js +11 -20
- package/dist/ui/playground/components/result-display.d.ts +0 -1
- package/dist/ui/playground/components/result-display.js +46 -182
- package/dist/ui/playground/components/server-select.js +24 -122
- package/dist/ui/playground/components/url-bar.js +8 -66
- package/dist/utils/create-page.d.ts +0 -4
- package/dist/utils/create-page.js +3 -5
- package/dist/utils/pages/builder.js +2 -2
- package/dist/utils/pages/preset-auto.js +139 -137
- package/dist/utils/pages/to-static-data.js +2 -7
- package/dist/utils/pages/to-text.js +2 -2
- package/package.json +6 -6
- package/dist/ui/playground/status-info.js +0 -39
|
@@ -1,66 +1,23 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { ClientCodeBlock } from "../../components/codeblock.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { iconButtonClassName, panelCodeBlock } from "../../../packages/shared-api/dist/components/playground/panels.js";
|
|
4
|
+
import { RequestError, ResponseView } from "../../../packages/shared-api/dist/components/playground/result.js";
|
|
5
|
+
import { useCallback, useMemo } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
7
|
import { useTranslations } from "@fuma-translate/react";
|
|
9
|
-
import { DownloadIcon, FileIcon
|
|
10
|
-
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
8
|
+
import { DownloadIcon, FileIcon } from "lucide-react";
|
|
11
9
|
//#region src/ui/playground/components/result-display.tsx
|
|
12
|
-
const iconButtonClassName = cn(buttonVariants({
|
|
13
|
-
variant: "ghost",
|
|
14
|
-
size: "icon-sm"
|
|
15
|
-
}), "text-fd-muted-foreground [&_svg]:size-3.5");
|
|
16
|
-
/** a code block filling its panel */
|
|
17
|
-
const panelCodeBlock = {
|
|
18
|
-
className: "h-full rounded-none border-0 bg-transparent shadow-none",
|
|
19
|
-
viewportProps: { className: "h-full max-h-none" }
|
|
20
|
-
};
|
|
21
|
-
function PanelHeader({ className, ...props }) {
|
|
22
|
-
return /* @__PURE__ */ jsx("div", {
|
|
23
|
-
...props,
|
|
24
|
-
className: cn("flex h-10 shrink-0 items-center gap-2.5 border-b ps-4 pe-1.5", className)
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
10
|
function DefaultResultDisplay({ data, reset, ...rest }) {
|
|
28
|
-
|
|
29
|
-
if (data.type === "client_error") return /* @__PURE__ */ jsxs("div", {
|
|
11
|
+
if (data.type === "client_error") return /* @__PURE__ */ jsx(RequestError, {
|
|
30
12
|
...rest,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/* @__PURE__ */ jsx("span", {
|
|
35
|
-
className: "text-[0.8125rem] font-medium",
|
|
36
|
-
children: t("Request Failed")
|
|
37
|
-
}),
|
|
38
|
-
/* @__PURE__ */ jsx("button", {
|
|
39
|
-
type: "button",
|
|
40
|
-
"aria-label": t("Clear"),
|
|
41
|
-
className: cn(iconButtonClassName, "ms-auto"),
|
|
42
|
-
onClick: reset,
|
|
43
|
-
children: /* @__PURE__ */ jsx(X, {})
|
|
44
|
-
})
|
|
45
|
-
] }), /* @__PURE__ */ jsxs("div", {
|
|
46
|
-
className: "flex flex-col gap-3 overflow-auto p-4 text-sm",
|
|
47
|
-
children: [
|
|
48
|
-
/* @__PURE__ */ jsx("p", { children: data.message }),
|
|
49
|
-
/* @__PURE__ */ jsx("p", {
|
|
50
|
-
className: "font-mono text-xs break-all text-fd-muted-foreground",
|
|
51
|
-
children: data.url
|
|
52
|
-
}),
|
|
53
|
-
/* @__PURE__ */ jsx("p", {
|
|
54
|
-
className: "rounded-lg border bg-fd-secondary p-3 text-xs text-fd-muted-foreground",
|
|
55
|
-
children: t("Check the server URL. If the API does not allow cross-origin requests from this site, a proxy is needed.")
|
|
56
|
-
})
|
|
57
|
-
]
|
|
58
|
-
})]
|
|
13
|
+
message: data.message,
|
|
14
|
+
url: data.url,
|
|
15
|
+
onClear: reset
|
|
59
16
|
});
|
|
60
17
|
return /* @__PURE__ */ jsx(ResponseResult, {
|
|
18
|
+
...rest,
|
|
61
19
|
data,
|
|
62
|
-
reset
|
|
63
|
-
...rest
|
|
20
|
+
reset
|
|
64
21
|
});
|
|
65
22
|
}
|
|
66
23
|
function getTextFormat(mime) {
|
|
@@ -78,21 +35,11 @@ function getTextFormat(mime) {
|
|
|
78
35
|
if (mime.startsWith("text/")) return "text";
|
|
79
36
|
return null;
|
|
80
37
|
}
|
|
81
|
-
function formatDuration(ms) {
|
|
82
|
-
return ms < 1e3 ? `${Math.round(ms)} ms` : `${(ms / 1e3).toFixed(2)} s`;
|
|
83
|
-
}
|
|
84
|
-
function formatSize(bytes) {
|
|
85
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
86
|
-
if (bytes < 1048576) return `${(bytes / 1024).toFixed(1)} kB`;
|
|
87
|
-
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
88
|
-
}
|
|
89
38
|
function ResponseResult({ data, reset, ...rest }) {
|
|
90
39
|
const t = useTranslations({ note: "playground result display" });
|
|
91
|
-
const statusInfo = useStatusInfo(data.status);
|
|
92
|
-
const [view, setView] = useState("body");
|
|
93
40
|
const type = data.mediaType ?? "text/plain";
|
|
94
|
-
const headers = Array.from(data.headers);
|
|
95
41
|
const size = data.body.byteLength;
|
|
42
|
+
const lang = getTextFormat(type);
|
|
96
43
|
const bodyUrlRef = useCallback((element) => {
|
|
97
44
|
if (!element) return;
|
|
98
45
|
const url = URL.createObjectURL(new Blob([data.body], { type }));
|
|
@@ -109,124 +56,41 @@ function ResponseResult({ data, reset, ...rest }) {
|
|
|
109
56
|
className: "max-w-full rounded-lg border"
|
|
110
57
|
})
|
|
111
58
|
});
|
|
112
|
-
else if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
type
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
})
|
|
130
|
-
]
|
|
131
|
-
});
|
|
132
|
-
} else body = /* @__PURE__ */ jsxs("div", {
|
|
133
|
-
className: "flex h-full flex-col items-center justify-center gap-1 p-6 text-center",
|
|
134
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
135
|
-
className: "text-4xl font-light tracking-tight tabular-nums",
|
|
136
|
-
children: data.status
|
|
137
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
138
|
-
className: "text-sm text-fd-muted-foreground",
|
|
139
|
-
children: t("Empty response body")
|
|
140
|
-
})]
|
|
59
|
+
else if (lang) body = /* @__PURE__ */ jsx(TextResult, {
|
|
60
|
+
lang,
|
|
61
|
+
data
|
|
62
|
+
});
|
|
63
|
+
else body = /* @__PURE__ */ jsxs("div", {
|
|
64
|
+
className: "flex h-full flex-col items-center justify-center gap-2 p-6 text-center",
|
|
65
|
+
children: [
|
|
66
|
+
/* @__PURE__ */ jsx(FileIcon, { className: "size-5 text-fd-muted-foreground" }),
|
|
67
|
+
/* @__PURE__ */ jsx("p", {
|
|
68
|
+
className: "text-sm font-medium",
|
|
69
|
+
children: t("Binary response body, {length} bytes", { variables: { length: String(size) } })
|
|
70
|
+
}),
|
|
71
|
+
type && /* @__PURE__ */ jsx("p", {
|
|
72
|
+
className: "font-mono text-xs text-fd-muted-foreground",
|
|
73
|
+
children: type
|
|
74
|
+
})
|
|
75
|
+
]
|
|
141
76
|
});
|
|
142
|
-
return /* @__PURE__ */ jsx(
|
|
77
|
+
return /* @__PURE__ */ jsx(ResponseView, {
|
|
143
78
|
...rest,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
" ",
|
|
160
|
-
/* @__PURE__ */ jsx("span", {
|
|
161
|
-
className: "font-normal text-fd-muted-foreground",
|
|
162
|
-
children: statusInfo.description
|
|
163
|
-
})
|
|
164
|
-
]
|
|
165
|
-
}),
|
|
166
|
-
/* @__PURE__ */ jsxs("p", {
|
|
167
|
-
className: "hidden shrink-0 text-xs text-fd-muted-foreground tabular-nums @md:block",
|
|
168
|
-
children: [
|
|
169
|
-
formatDuration(data.duration),
|
|
170
|
-
" · ",
|
|
171
|
-
formatSize(size)
|
|
172
|
-
]
|
|
173
|
-
}),
|
|
174
|
-
/* @__PURE__ */ jsx(SegmentedList, {
|
|
175
|
-
className: "ms-auto shrink-0",
|
|
176
|
-
items: [{
|
|
177
|
-
value: "body",
|
|
178
|
-
label: t("Body")
|
|
179
|
-
}, {
|
|
180
|
-
value: "headers",
|
|
181
|
-
label: /* @__PURE__ */ jsxs(Fragment$1, { children: [t("Headers"), /* @__PURE__ */ jsx("span", {
|
|
182
|
-
className: "text-fd-muted-foreground tabular-nums",
|
|
183
|
-
children: headers.length
|
|
184
|
-
})] })
|
|
185
|
-
}]
|
|
186
|
-
}),
|
|
187
|
-
/* @__PURE__ */ jsxs("div", {
|
|
188
|
-
className: "flex shrink-0 items-center",
|
|
189
|
-
children: [size > 0 && /* @__PURE__ */ jsx("a", {
|
|
190
|
-
ref: bodyUrlRef,
|
|
191
|
-
download: data.fileName ?? "response",
|
|
192
|
-
"aria-label": t("Download"),
|
|
193
|
-
title: t("Download"),
|
|
194
|
-
className: iconButtonClassName,
|
|
195
|
-
children: /* @__PURE__ */ jsx(DownloadIcon, {})
|
|
196
|
-
}), /* @__PURE__ */ jsx("button", {
|
|
197
|
-
type: "button",
|
|
198
|
-
"aria-label": t("Clear"),
|
|
199
|
-
title: t("Clear"),
|
|
200
|
-
className: iconButtonClassName,
|
|
201
|
-
onClick: reset,
|
|
202
|
-
children: /* @__PURE__ */ jsx(X, {})
|
|
203
|
-
})]
|
|
204
|
-
})
|
|
205
|
-
] }),
|
|
206
|
-
/* @__PURE__ */ jsx(SegmentedPanel, {
|
|
207
|
-
value: "body",
|
|
208
|
-
className: "min-h-0 flex-1 overflow-auto",
|
|
209
|
-
children: body
|
|
210
|
-
}),
|
|
211
|
-
/* @__PURE__ */ jsxs(SegmentedPanel, {
|
|
212
|
-
value: "headers",
|
|
213
|
-
className: "min-h-0 flex-1 overflow-auto",
|
|
214
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
215
|
-
className: "border-b px-4 py-2.5 font-mono text-xs break-all text-fd-muted-foreground",
|
|
216
|
-
children: data.url
|
|
217
|
-
}), /* @__PURE__ */ jsx("dl", {
|
|
218
|
-
className: "grid grid-cols-[minmax(0,2fr)_minmax(0,3fr)] font-mono text-xs",
|
|
219
|
-
children: headers.map(([name, value]) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
|
|
220
|
-
className: "truncate border-b py-2 ps-4 pe-2 text-fd-muted-foreground",
|
|
221
|
-
children: name
|
|
222
|
-
}), /* @__PURE__ */ jsx("dd", {
|
|
223
|
-
className: "border-b border-s px-3 py-2 break-all",
|
|
224
|
-
children: value
|
|
225
|
-
})] }, name))
|
|
226
|
-
})]
|
|
227
|
-
})
|
|
228
|
-
]
|
|
229
|
-
})
|
|
79
|
+
status: data.status,
|
|
80
|
+
duration: data.duration,
|
|
81
|
+
size,
|
|
82
|
+
url: data.url,
|
|
83
|
+
headers: Array.from(data.headers),
|
|
84
|
+
onClear: reset,
|
|
85
|
+
actions: size > 0 && /* @__PURE__ */ jsx("a", {
|
|
86
|
+
ref: bodyUrlRef,
|
|
87
|
+
download: data.fileName ?? "response",
|
|
88
|
+
"aria-label": t("Download"),
|
|
89
|
+
title: t("Download"),
|
|
90
|
+
className: iconButtonClassName,
|
|
91
|
+
children: /* @__PURE__ */ jsx(DownloadIcon, {})
|
|
92
|
+
}),
|
|
93
|
+
children: body
|
|
230
94
|
});
|
|
231
95
|
}
|
|
232
96
|
function TextResult({ lang, data }) {
|
|
@@ -246,4 +110,4 @@ function TextResult({ lang, data }) {
|
|
|
246
110
|
});
|
|
247
111
|
}
|
|
248
112
|
//#endregion
|
|
249
|
-
export { DefaultResultDisplay
|
|
113
|
+
export { DefaultResultDisplay };
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useServer } from "../../../utils/use-server.js";
|
|
3
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
4
3
|
import { cn } from "../../../utils/cn.js";
|
|
5
|
-
import {
|
|
6
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
import { StfProvider, useFieldValue, useListener, useStf } from "@fumari/stf";
|
|
4
|
+
import { ServerPopover, ServerVariables } from "../../../packages/shared-api/dist/components/playground/server-select.js";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
6
|
import { useTranslations } from "@fuma-translate/react";
|
|
9
|
-
import { Check, ChevronDown } from "lucide-react";
|
|
10
|
-
import { Popover } from "@base-ui/react/popover";
|
|
11
7
|
//#region src/ui/playground/components/server-select.tsx
|
|
12
8
|
/** the base URL of requests, selects the server and edits its variables */
|
|
13
9
|
function ServerSelect({ className }) {
|
|
14
10
|
const { servers, server, resolveUrl, setServer, setServerVariables } = useServer();
|
|
15
|
-
const [open, setOpen] = useState(false);
|
|
16
11
|
const t = useTranslations({ note: "playground server select" });
|
|
17
12
|
const base = resolveUrl().replace(/\/$/, "");
|
|
18
13
|
if (!servers || servers.length === 0) return /* @__PURE__ */ jsx("span", {
|
|
@@ -20,121 +15,28 @@ function ServerSelect({ className }) {
|
|
|
20
15
|
children: base
|
|
21
16
|
});
|
|
22
17
|
const serverSchema = server ? servers.find((item) => item.url === server.url) : void 0;
|
|
23
|
-
return /* @__PURE__ */
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const selected = item.url === server?.url;
|
|
46
|
-
return /* @__PURE__ */ jsxs("button", {
|
|
47
|
-
type: "button",
|
|
48
|
-
"aria-pressed": selected,
|
|
49
|
-
onClick: () => {
|
|
50
|
-
setServer(item.url);
|
|
51
|
-
if (!item.variables) setOpen(false);
|
|
52
|
-
},
|
|
53
|
-
className: "flex w-full items-start gap-2 rounded-lg px-2.5 py-2 text-start transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground focus-visible:bg-fd-accent focus-visible:outline-none",
|
|
54
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
55
|
-
className: "min-w-0 flex-1",
|
|
56
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
57
|
-
className: "block font-mono text-[0.8125rem] break-all",
|
|
58
|
-
children: item.url
|
|
59
|
-
}), item.description && /* @__PURE__ */ jsx("span", {
|
|
60
|
-
className: "mt-0.5 block text-xs text-fd-muted-foreground",
|
|
61
|
-
children: item.description
|
|
62
|
-
})]
|
|
63
|
-
}), selected && /* @__PURE__ */ jsx(Check, { className: "mt-0.5 size-3.5 shrink-0 text-fd-primary" })]
|
|
64
|
-
}, item.url);
|
|
65
|
-
}),
|
|
66
|
-
server?.variables && serverSchema?.variables && /* @__PURE__ */ jsx(ServerVariables, {
|
|
67
|
-
defaultValues: server.variables,
|
|
68
|
-
schema: serverSchema.variables,
|
|
69
|
-
onChange: setServerVariables
|
|
70
|
-
}, server.url)
|
|
71
|
-
]
|
|
72
|
-
})
|
|
73
|
-
}) })]
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function ServerVariables({ defaultValues, onChange, schema }) {
|
|
77
|
-
const t = useTranslations({ note: "playground server select" });
|
|
78
|
-
const stf = useStf({ defaultValues: () => structuredClone(defaultValues) });
|
|
79
|
-
const timerRef = useRef(null);
|
|
80
|
-
useListener({
|
|
81
|
-
stf,
|
|
82
|
-
onUpdate() {
|
|
83
|
-
if (timerRef.current !== null) window.clearTimeout(timerRef.current);
|
|
84
|
-
timerRef.current = window.setTimeout(() => onChange(stf.dataEngine.getData()), 300);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return /* @__PURE__ */ jsx(StfProvider, {
|
|
88
|
-
value: stf,
|
|
89
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
90
|
-
className: "mt-1 flex flex-col gap-2.5 border-t px-2.5 pt-2.5 pb-2",
|
|
91
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
92
|
-
className: "text-xs font-medium text-fd-muted-foreground",
|
|
93
|
-
children: t("Variables")
|
|
94
|
-
}), Object.entries(schema).map(([key, variable]) => /* @__PURE__ */ jsxs("div", {
|
|
95
|
-
className: "grid grid-cols-[minmax(0,2fr)_minmax(0,3fr)] items-center gap-3",
|
|
96
|
-
children: [/* @__PURE__ */ jsxs("label", {
|
|
97
|
-
htmlFor: `server-${key}`,
|
|
98
|
-
className: "min-w-0",
|
|
99
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
100
|
-
className: "block truncate font-mono text-[0.8125rem]",
|
|
101
|
-
children: key
|
|
102
|
-
}), variable.description && /* @__PURE__ */ jsx("span", {
|
|
103
|
-
className: "block text-xs text-fd-muted-foreground",
|
|
104
|
-
children: variable.description
|
|
105
|
-
})]
|
|
106
|
-
}), /* @__PURE__ */ jsx(VariableInput, {
|
|
107
|
-
fieldName: key,
|
|
108
|
-
variable
|
|
109
|
-
})]
|
|
110
|
-
}, key))]
|
|
111
|
-
})
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
function VariableInput({ fieldName, variable }) {
|
|
115
|
-
const t = useTranslations({ note: "playground server select" });
|
|
116
|
-
const id = `server-${fieldName}`;
|
|
117
|
-
const [value, setValue] = useFieldValue([fieldName], { compute(currentValue) {
|
|
118
|
-
return typeof currentValue === "string" ? currentValue : void 0;
|
|
119
|
-
} });
|
|
120
|
-
if (variable.enum) return /* @__PURE__ */ jsxs(Select, {
|
|
121
|
-
value: value ?? null,
|
|
122
|
-
onValueChange: (v) => v !== null && setValue(v),
|
|
123
|
-
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
124
|
-
id,
|
|
125
|
-
className: "h-8 py-1 text-[0.8125rem]",
|
|
126
|
-
children: /* @__PURE__ */ jsx(SelectValue, {})
|
|
127
|
-
}), /* @__PURE__ */ jsx(SelectContent, { children: variable.enum.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
128
|
-
value: item,
|
|
129
|
-
children: item
|
|
130
|
-
}, item)) })]
|
|
131
|
-
});
|
|
132
|
-
return /* @__PURE__ */ jsx("input", {
|
|
133
|
-
id,
|
|
134
|
-
value: value ?? "",
|
|
135
|
-
onChange: (e) => setValue(e.target.value),
|
|
136
|
-
placeholder: t("Enter Value"),
|
|
137
|
-
className: "h-8 w-full rounded-md border bg-fd-secondary px-2 font-mono text-[0.8125rem] text-fd-secondary-foreground outline-none placeholder:text-fd-muted-foreground focus-visible:ring-2 focus-visible:ring-fd-ring"
|
|
18
|
+
return /* @__PURE__ */ jsx(ServerPopover, {
|
|
19
|
+
label: base,
|
|
20
|
+
title: t("Server URL"),
|
|
21
|
+
value: server?.url,
|
|
22
|
+
onValueChange: setServer,
|
|
23
|
+
className,
|
|
24
|
+
options: servers.map((item) => ({
|
|
25
|
+
value: item.url,
|
|
26
|
+
hasVariables: item.variables !== void 0,
|
|
27
|
+
label: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
28
|
+
className: "block font-mono text-[0.8125rem] break-all",
|
|
29
|
+
children: item.url
|
|
30
|
+
}), item.description && /* @__PURE__ */ jsx("span", {
|
|
31
|
+
className: "mt-0.5 block text-xs text-fd-muted-foreground",
|
|
32
|
+
children: item.description
|
|
33
|
+
})] })
|
|
34
|
+
})),
|
|
35
|
+
children: server?.variables && serverSchema?.variables && /* @__PURE__ */ jsx(ServerVariables, {
|
|
36
|
+
defaultValues: server.variables,
|
|
37
|
+
variables: serverSchema.variables,
|
|
38
|
+
onChange: setServerVariables
|
|
39
|
+
}, server.url)
|
|
138
40
|
});
|
|
139
41
|
}
|
|
140
42
|
//#endregion
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { MethodLabel } from "../../components/method-label.js";
|
|
3
3
|
import { cn } from "../../../utils/cn.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { SendButton } from "../../../packages/shared-api/dist/components/playground/panels.js";
|
|
5
|
+
import { ParamInput } from "../../../packages/shared-api/dist/components/playground/param-input.js";
|
|
6
6
|
import ServerSelect from "./server-select.js";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import { useFieldValue } from "@fumari/stf";
|
|
9
|
-
import { useTranslations } from "@fuma-translate/react";
|
|
10
|
-
import { SendHorizontal } from "lucide-react";
|
|
11
|
-
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
12
8
|
//#region src/ui/playground/components/url-bar.tsx
|
|
13
9
|
function UrlBar({ method, route, parameters, deprecated = false, loading }) {
|
|
14
|
-
const t = useTranslations({ note: "playground" });
|
|
15
|
-
const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent);
|
|
16
10
|
return /* @__PURE__ */ jsxs("div", {
|
|
17
11
|
className: "flex items-center gap-2",
|
|
18
12
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
@@ -27,69 +21,17 @@ function UrlBar({ method, route, parameters, deprecated = false, loading }) {
|
|
|
27
21
|
children: route.split(/(\{[^}]+\})/).map((part, i) => {
|
|
28
22
|
if (!part.startsWith("{") || !part.endsWith("}")) return part;
|
|
29
23
|
const name = part.slice(1, -1);
|
|
30
|
-
|
|
24
|
+
const param = parameters.find((p) => p.name === name);
|
|
25
|
+
return /* @__PURE__ */ jsx(ParamInput, {
|
|
26
|
+
fieldName: ["path", name],
|
|
31
27
|
name,
|
|
32
|
-
|
|
28
|
+
schema: param?.schema,
|
|
29
|
+
description: param?.description
|
|
33
30
|
}, i);
|
|
34
31
|
})
|
|
35
32
|
})]
|
|
36
33
|
})]
|
|
37
|
-
}), /* @__PURE__ */
|
|
38
|
-
type: "submit",
|
|
39
|
-
disabled: loading,
|
|
40
|
-
className: cn(buttonVariants({ variant: "primary" }), "h-10 shrink-0 gap-2 rounded-xl px-4 transition-[background-color,scale] active:scale-[0.97] disabled:opacity-80 motion-reduce:transition-none"),
|
|
41
|
-
children: [
|
|
42
|
-
loading ? /* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }) : /* @__PURE__ */ jsx(SendHorizontal, { className: "size-3.5" }),
|
|
43
|
-
t("Send"),
|
|
44
|
-
/* @__PURE__ */ jsxs("kbd", {
|
|
45
|
-
className: "hidden font-sans text-xs text-fd-primary-foreground/60 sm:inline",
|
|
46
|
-
children: [isMac ? "⌘" : "Ctrl", " ↵"]
|
|
47
|
-
})
|
|
48
|
-
]
|
|
49
|
-
})]
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function PathParam({ name, param }) {
|
|
53
|
-
const schema = useResolvedSchema(param?.schema ?? true);
|
|
54
|
-
const [value, setValue] = useFieldValue(["path", name]);
|
|
55
|
-
const text = value == null ? "" : String(value);
|
|
56
|
-
const className = "mx-px rounded-md bg-fd-primary/10 px-1.5 py-0.5 text-fd-primary outline-none transition-colors placeholder:text-fd-primary/50 hover:bg-fd-primary/15 focus-visible:bg-fd-primary/15 focus-visible:ring-2 focus-visible:ring-fd-primary/30";
|
|
57
|
-
if (schema.enum && schema.enum.length > 0) {
|
|
58
|
-
const options = schema.enum;
|
|
59
|
-
return /* @__PURE__ */ jsxs("select", {
|
|
60
|
-
"aria-label": name,
|
|
61
|
-
title: param?.description,
|
|
62
|
-
value: String(options.indexOf(value)),
|
|
63
|
-
onChange: (e) => setValue(options[Number(e.target.value)]),
|
|
64
|
-
className: cn(className, "cursor-pointer appearance-none"),
|
|
65
|
-
children: [/* @__PURE__ */ jsx("option", {
|
|
66
|
-
value: "-1",
|
|
67
|
-
disabled: true,
|
|
68
|
-
className: "bg-fd-popover text-fd-popover-foreground",
|
|
69
|
-
children: name
|
|
70
|
-
}), options.map((item, i) => /* @__PURE__ */ jsx("option", {
|
|
71
|
-
value: i,
|
|
72
|
-
className: "bg-fd-popover text-fd-popover-foreground",
|
|
73
|
-
children: String(item)
|
|
74
|
-
}, i))]
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
const isNumber = schema.type === "integer" || schema.type === "number";
|
|
78
|
-
return /* @__PURE__ */ jsx("input", {
|
|
79
|
-
"aria-label": name,
|
|
80
|
-
title: param?.description,
|
|
81
|
-
value: text,
|
|
82
|
-
placeholder: name,
|
|
83
|
-
autoComplete: "off",
|
|
84
|
-
spellCheck: false,
|
|
85
|
-
inputMode: isNumber ? "decimal" : void 0,
|
|
86
|
-
onChange: (e) => {
|
|
87
|
-
const v = e.target.value;
|
|
88
|
-
if (v.length === 0) setValue(void 0);
|
|
89
|
-
else setValue(isNumber && !Number.isNaN(Number(v)) ? Number(v) : v);
|
|
90
|
-
},
|
|
91
|
-
style: { width: `calc(${Math.max(text.length, name.length, 1)}ch + 0.75rem)` },
|
|
92
|
-
className
|
|
34
|
+
}), /* @__PURE__ */ jsx(SendButton, { sending: loading })]
|
|
93
35
|
});
|
|
94
36
|
}
|
|
95
37
|
//#endregion
|
|
@@ -205,10 +205,6 @@ export declare function useRenderContext(): RenderContext;
|
|
|
205
205
|
* Generate TypeScript definitions of a JSON schema, `undefined` when disabled.
|
|
206
206
|
*/
|
|
207
207
|
export declare function useTypeScriptDefinitions(schema: JsonSchema | undefined, options: Pick<GenerateTypeScriptDefinitionsContext, 'name' | 'readOnly' | 'writeOnly'>): string | undefined;
|
|
208
|
-
/**
|
|
209
|
-
* Create `<OpenAPIPage />` from your own UI, it takes the props of generated pages.
|
|
210
|
-
*/
|
|
211
|
-
export declare function createOpenAPIRenderer(options: CreateOpenAPIRendererOptions): FC<OpenAPIPageProps>;
|
|
212
208
|
/**
|
|
213
209
|
* `createOpenAPIRenderer()` with nothing built in: it highlights through the `shiki` you pass, and
|
|
214
210
|
* generates code usages and TypeScript definitions only when you pass them.
|
|
@@ -9,7 +9,6 @@ import { PlaygroundAuthProvider } from "../playground/auth.js";
|
|
|
9
9
|
import { createContext, use, useMemo } from "react";
|
|
10
10
|
import { getRaw } from "@scalar/json-magic/magic-proxy";
|
|
11
11
|
import { generate } from "@fumari/json-schema-ts";
|
|
12
|
-
import { defaultShikiFactory } from "fumadocs-core/highlight/shiki/full";
|
|
13
12
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
14
13
|
//#region src/utils/create-page.tsx
|
|
15
14
|
const OpenAPIContext = createContext(null);
|
|
@@ -129,12 +128,11 @@ const defaultTypeScriptDefinitions = (schema, ctx) => {
|
|
|
129
128
|
}
|
|
130
129
|
};
|
|
131
130
|
/**
|
|
132
|
-
*
|
|
131
|
+
* `createOpenAPIRenderer()` without the full Shiki bundle.
|
|
133
132
|
*/
|
|
134
|
-
function
|
|
133
|
+
function createRenderer(options) {
|
|
135
134
|
return createOpenAPIBaseRenderer({
|
|
136
135
|
...options,
|
|
137
|
-
shiki: options.shiki ?? defaultShikiFactory,
|
|
138
136
|
codeUsages: options.codeUsages ?? (defaultCodeUsages ??= registerDefault(createCodeUsageGeneratorRegistry())),
|
|
139
137
|
generateTypeScriptDefinitions: options.generateTypeScriptDefinitions ?? defaultTypeScriptDefinitions
|
|
140
138
|
});
|
|
@@ -220,4 +218,4 @@ function DefaultLayout({ operations, webhooks }) {
|
|
|
220
218
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [operations?.map((item) => item.children), webhooks?.map((item) => item.children)] });
|
|
221
219
|
}
|
|
222
220
|
//#endregion
|
|
223
|
-
export { createOpenAPIBaseRenderer,
|
|
221
|
+
export { createOpenAPIBaseRenderer, createRenderer, useComponents, useOpenAPI, useRenderContext, useTypeScriptDefinitions };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { dereferenceBundledDocument } from "../document/dereference.js";
|
|
1
2
|
import { idToTitle } from "../../packages/shared-api/dist/utils/id-to-title.js";
|
|
2
3
|
import { getTagDisplayName, methodKeys } from "../schema.js";
|
|
3
|
-
import { createMagicProxy } from "@scalar/json-magic/magic-proxy";
|
|
4
4
|
import { dereference } from "@fumadocs/json-schema";
|
|
5
5
|
//#region src/utils/pages/builder.ts
|
|
6
6
|
function fromSchema(schemaId, bundled, config) {
|
|
7
7
|
const files = [];
|
|
8
8
|
const { toPages } = config;
|
|
9
|
-
const document =
|
|
9
|
+
const document = dereferenceBundledDocument(bundled).dereferenced;
|
|
10
10
|
toPages({
|
|
11
11
|
id: schemaId,
|
|
12
12
|
document,
|