fumadocs-openapi 12.4.2 → 12.5.1
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 +12 -1
- package/dist/.translations/keys.js +12 -1
- package/dist/generate-file.js +3 -1
- package/dist/index.browser.d.ts +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/operation.js +2 -2
- package/dist/packages/shared-api/dist/codegen.js +1 -3
- package/dist/packages/shared-api/dist/components/schema/client.js +1 -1
- package/dist/packages/shared-api/dist/components/select.js +6 -2
- package/dist/playground/auth.d.ts +84 -30
- package/dist/playground/auth.js +250 -150
- package/dist/playground/fetcher.js +11 -6
- package/dist/playground/index.d.ts +2 -2
- package/dist/playground/index.js +2 -2
- package/dist/playground/use-playground.d.ts +3 -3
- package/dist/playground/use-playground.js +46 -31
- package/dist/requests/generators/python.d.ts +0 -1
- package/dist/requests/generators/python.js +1 -1
- package/dist/server/index.d.ts +2 -9
- package/dist/server/index.js +2 -9
- package/dist/server/proxy.d.ts +5 -4
- package/dist/server/proxy.js +105 -25
- package/dist/types/openapi.d.ts +7 -2
- package/dist/types.d.ts +1 -0
- package/dist/ui/operation/index.js +66 -38
- package/dist/ui/operation/usage-tabs.js +272 -35
- package/dist/ui/playground/client.js +8 -4
- package/dist/ui/playground/components/fields.js +5 -7
- package/dist/ui/playground/components/oauth-panel.js +150 -39
- package/dist/ui/playground/components/request-panel.js +18 -3
- package/dist/ui/playground/components/response-panel.js +53 -90
- package/dist/utils/create-page.d.ts +2 -1
- package/dist/utils/pages/to-static-data.d.ts +12 -0
- package/dist/utils/use-server.js +1 -1
- package/package.json +8 -7
- package/dist/packages/shared-api/dist/components/accordion.js +0 -63
- package/dist/ui/operation/request-tabs.js +0 -92
- package/dist/ui/operation/response-tabs.js +0 -53
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useQuery } from "../../../packages/shared-api/dist/utils/use-query.js";
|
|
3
2
|
import { useServer } from "../../../utils/use-server.js";
|
|
4
|
-
import {
|
|
3
|
+
import { useQuery } from "../../../packages/shared-api/dist/utils/use-query.js";
|
|
4
|
+
import { finishOAuthFlow, requestOAuthToken, useAuthRedirect, useOpenIdConnectFlows } from "../../../playground/auth.js";
|
|
5
5
|
import { useOpenAPI } from "../../../utils/create-page.js";
|
|
6
6
|
import { Markdown } from "../../components/markdown.js";
|
|
7
7
|
import { cn } from "../../../utils/cn.js";
|
|
8
|
+
import { iconButtonClassName } from "./result-display.js";
|
|
8
9
|
import { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
|
|
9
10
|
import { CheckRow, SelectRow, TextRow, ValueRow } from "./fields.js";
|
|
10
|
-
import { useState } from "react";
|
|
11
|
+
import { Suspense, useEffect, useRef, useState } from "react";
|
|
11
12
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
12
13
|
import { StfProvider, useDataEngine, useStf } from "@fumari/stf";
|
|
13
14
|
import { useTranslations } from "@fuma-translate/react";
|
|
15
|
+
import { Check, Copy, ExternalLink } from "lucide-react";
|
|
14
16
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
17
|
+
import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
|
|
15
18
|
//#region src/ui/playground/components/oauth-panel.tsx
|
|
16
|
-
/** OAuth 2.0 schemes, authorized in a panel */
|
|
19
|
+
/** OAuth 2.0 and OpenID Connect schemes, authorized in a panel */
|
|
17
20
|
const oauthPanelProvider = {
|
|
18
|
-
on: ({ scheme }) => scheme.type === "oauth2",
|
|
21
|
+
on: ({ scheme }) => scheme.type === "oauth2" || scheme.type === "openIdConnect",
|
|
19
22
|
render: function OAuthRows({ field, Value, Panel }) {
|
|
20
23
|
const t = useTranslations({ note: "playground" });
|
|
21
24
|
const engine = useDataEngine();
|
|
@@ -53,19 +56,61 @@ const oauthPanelProvider = {
|
|
|
53
56
|
] });
|
|
54
57
|
}
|
|
55
58
|
};
|
|
56
|
-
/** obtain the access token of an OAuth 2.0 scheme */
|
|
59
|
+
/** obtain the access token of an OAuth 2.0 or OpenID Connect scheme */
|
|
57
60
|
function OAuthPanel({ field, close }) {
|
|
61
|
+
const t = useTranslations({ note: "OAuth dialog" });
|
|
62
|
+
const { scheme } = field;
|
|
63
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [scheme.description && /* @__PURE__ */ jsx("div", {
|
|
64
|
+
className: "border-b px-4 py-2.5 text-xs text-fd-muted-foreground [&_a]:underline",
|
|
65
|
+
children: /* @__PURE__ */ jsx(Markdown, { md: scheme.description })
|
|
66
|
+
}), scheme.type === "openIdConnect" ? /* @__PURE__ */ jsx(Suspense, {
|
|
67
|
+
fallback: /* @__PURE__ */ jsxs("p", {
|
|
68
|
+
className: "flex items-center gap-1.5 border-b px-4 py-2.5 text-xs text-fd-muted-foreground",
|
|
69
|
+
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3" }), t("Loading the OpenID Connect configuration...")]
|
|
70
|
+
}),
|
|
71
|
+
children: /* @__PURE__ */ jsx(OpenIdConnectForm, {
|
|
72
|
+
field,
|
|
73
|
+
configUrl: scheme.openIdConnectUrl,
|
|
74
|
+
close
|
|
75
|
+
})
|
|
76
|
+
}) : /* @__PURE__ */ jsx(OAuthForm, {
|
|
77
|
+
field,
|
|
78
|
+
flows: scheme.type === "oauth2" && scheme.flows || {},
|
|
79
|
+
close
|
|
80
|
+
})] });
|
|
81
|
+
}
|
|
82
|
+
/** the flows of OpenID Connect schemes come from their configuration */
|
|
83
|
+
function OpenIdConnectForm({ configUrl, ...props }) {
|
|
84
|
+
const t = useTranslations({ note: "OAuth dialog" });
|
|
85
|
+
const { flows, error } = useOpenIdConnectFlows(configUrl);
|
|
86
|
+
if (flows) return /* @__PURE__ */ jsx(OAuthForm, {
|
|
87
|
+
...props,
|
|
88
|
+
flows
|
|
89
|
+
});
|
|
90
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
91
|
+
className: "border-b px-4 py-2.5 text-xs",
|
|
92
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
93
|
+
className: "font-medium text-red-400",
|
|
94
|
+
children: t("Failed to load the OpenID Connect configuration")
|
|
95
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
96
|
+
className: "text-fd-muted-foreground",
|
|
97
|
+
children: String(error)
|
|
98
|
+
})]
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function OAuthForm({ field, flows, close }) {
|
|
58
102
|
const t = useTranslations({ note: "OAuth dialog" });
|
|
59
103
|
const engine = useDataEngine();
|
|
60
104
|
const redirect = useAuthRedirect(field);
|
|
61
|
-
const { oauthRedirectUrl } = useOpenAPI();
|
|
105
|
+
const { oauthRedirectUrl, proxyUrl, storageKeyPrefix } = useOpenAPI();
|
|
106
|
+
const storageKey = `${storageKeyPrefix}oauth-${field.schemeId}`;
|
|
62
107
|
const { resolveUrl } = useServer();
|
|
63
|
-
const scheme = field.scheme;
|
|
64
|
-
const flows = scheme.flows ?? {};
|
|
65
108
|
const [type, setType] = useState(() => Object.keys(flows)[0]);
|
|
66
109
|
const [clientAuth, setClientAuth] = useState("header");
|
|
67
110
|
const [scopes, setScopes] = useState(() => new Set(field.scopes));
|
|
68
|
-
const
|
|
111
|
+
const [userCode, setUserCode] = useState();
|
|
112
|
+
const controllerRef = useRef(null);
|
|
113
|
+
const stf = useStf({ defaultValues: () => JSON.parse(localStorage.getItem(storageKey) ?? "{}") });
|
|
69
114
|
const flowInfo = {
|
|
70
115
|
authorizationCode: {
|
|
71
116
|
name: t("Authorization code"),
|
|
@@ -89,30 +134,44 @@ function OAuthPanel({ field, close }) {
|
|
|
89
134
|
}
|
|
90
135
|
};
|
|
91
136
|
const flow = flows[type];
|
|
92
|
-
const supported = type !== "deviceAuthorization";
|
|
93
137
|
const redirects = type === "authorizationCode" || type === "implicit";
|
|
94
|
-
const hasSecret = type === "authorizationCode" || type === "clientCredentials" || type === "password";
|
|
95
138
|
const serverUrl = resolveUrl();
|
|
96
139
|
const scopeOptions = { ...flow?.scopes };
|
|
97
140
|
for (const scope of field.scopes) scopeOptions[scope] ??= "";
|
|
98
141
|
const query = useQuery(async () => {
|
|
99
142
|
const credentials = stf.dataEngine.getData();
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
143
|
+
localStorage.setItem(storageKey, JSON.stringify({ clientId: credentials.clientId }));
|
|
144
|
+
const controller = controllerRef.current = new AbortController();
|
|
145
|
+
try {
|
|
146
|
+
const token = await requestOAuthToken(field.scheme, type, {
|
|
147
|
+
...credentials,
|
|
148
|
+
schemeId: field.schemeId,
|
|
149
|
+
scopes: Array.from(scopes),
|
|
150
|
+
clientAuth,
|
|
151
|
+
serverUrl,
|
|
152
|
+
redirectUrl: oauthRedirectUrl,
|
|
153
|
+
proxyUrl,
|
|
154
|
+
redirect,
|
|
155
|
+
onUserCode: setUserCode,
|
|
156
|
+
signal: controller.signal
|
|
157
|
+
});
|
|
158
|
+
if (!token) return;
|
|
159
|
+
engine.update(field.fieldName, token);
|
|
160
|
+
close();
|
|
161
|
+
} catch (e) {
|
|
162
|
+
if (!controller.signal.aborted) throw e;
|
|
163
|
+
} finally {
|
|
164
|
+
setUserCode(void 0);
|
|
165
|
+
}
|
|
115
166
|
});
|
|
167
|
+
useEffect(() => () => controllerRef.current?.abort(), []);
|
|
168
|
+
if (userCode) return /* @__PURE__ */ jsx(DeviceVerification, {
|
|
169
|
+
code: userCode,
|
|
170
|
+
onCancel: () => controllerRef.current?.abort()
|
|
171
|
+
});
|
|
172
|
+
let note;
|
|
173
|
+
if (redirects) note = t("You will be redirected to authorize, then back to this page.");
|
|
174
|
+
else if (type === "deviceAuthorization") note = t("You will get a code to enter on the verification page.");
|
|
116
175
|
return /* @__PURE__ */ jsx(StfProvider, {
|
|
117
176
|
value: stf,
|
|
118
177
|
children: /* @__PURE__ */ jsxs("form", {
|
|
@@ -122,10 +181,6 @@ function OAuthPanel({ field, close }) {
|
|
|
122
181
|
query.start();
|
|
123
182
|
},
|
|
124
183
|
children: [
|
|
125
|
-
scheme.description && /* @__PURE__ */ jsx("div", {
|
|
126
|
-
className: "border-b px-4 py-2.5 text-xs text-fd-muted-foreground [&_a]:underline",
|
|
127
|
-
children: /* @__PURE__ */ jsx(Markdown, { md: scheme.description })
|
|
128
|
-
}),
|
|
129
184
|
/* @__PURE__ */ jsx(SelectRow, {
|
|
130
185
|
name: "flow",
|
|
131
186
|
value: type,
|
|
@@ -136,18 +191,18 @@ function OAuthPanel({ field, close }) {
|
|
|
136
191
|
description: flowInfo[key].description
|
|
137
192
|
}))
|
|
138
193
|
}),
|
|
139
|
-
|
|
194
|
+
/* @__PURE__ */ jsx(ValueRow, {
|
|
140
195
|
name: "client_id",
|
|
141
196
|
required: type !== "password",
|
|
142
197
|
description: t("The client ID of your OAuth application."),
|
|
143
|
-
fieldName: ["
|
|
198
|
+
fieldName: ["clientId"],
|
|
144
199
|
field: { type: "string" }
|
|
145
200
|
}),
|
|
146
|
-
|
|
201
|
+
type !== "implicit" && /* @__PURE__ */ jsx(ValueRow, {
|
|
147
202
|
name: "client_secret",
|
|
148
|
-
required: type
|
|
203
|
+
required: type === "clientCredentials",
|
|
149
204
|
description: t("The client secret of your OAuth application."),
|
|
150
|
-
fieldName: ["
|
|
205
|
+
fieldName: ["clientSecret"],
|
|
151
206
|
field: {
|
|
152
207
|
type: "string",
|
|
153
208
|
format: "password"
|
|
@@ -167,7 +222,7 @@ function OAuthPanel({ field, close }) {
|
|
|
167
222
|
format: "password"
|
|
168
223
|
}
|
|
169
224
|
})] }),
|
|
170
|
-
|
|
225
|
+
type !== "implicit" && /* @__PURE__ */ jsx(SelectRow, {
|
|
171
226
|
name: "client_auth",
|
|
172
227
|
value: clientAuth,
|
|
173
228
|
onValueChange: (v) => setClientAuth(v),
|
|
@@ -185,6 +240,10 @@ function OAuthPanel({ field, close }) {
|
|
|
185
240
|
name: "authorization_url",
|
|
186
241
|
children: new URL(flow.authorizationUrl, serverUrl).href
|
|
187
242
|
}),
|
|
243
|
+
flow && "deviceAuthorizationUrl" in flow && flow.deviceAuthorizationUrl && /* @__PURE__ */ jsx(TextRow, {
|
|
244
|
+
name: "device_authorization_url",
|
|
245
|
+
children: new URL(flow.deviceAuthorizationUrl, serverUrl).href
|
|
246
|
+
}),
|
|
188
247
|
flow && "tokenUrl" in flow && flow.tokenUrl && /* @__PURE__ */ jsx(TextRow, {
|
|
189
248
|
name: "token_url",
|
|
190
249
|
children: new URL(flow.tokenUrl, serverUrl).href
|
|
@@ -213,10 +272,10 @@ function OAuthPanel({ field, close }) {
|
|
|
213
272
|
className: "flex items-center gap-3 px-4 py-3",
|
|
214
273
|
children: [/* @__PURE__ */ jsx("p", {
|
|
215
274
|
className: cn("min-w-0 flex-1 text-xs", query.error ? "text-red-400" : "text-fd-muted-foreground"),
|
|
216
|
-
children: query.error ? String(query.error) :
|
|
275
|
+
children: query.error ? String(query.error) : note
|
|
217
276
|
}), /* @__PURE__ */ jsxs("button", {
|
|
218
277
|
type: "submit",
|
|
219
|
-
disabled:
|
|
278
|
+
disabled: query.isLoading,
|
|
220
279
|
className: cn(buttonVariants({
|
|
221
280
|
variant: "primary",
|
|
222
281
|
size: "sm"
|
|
@@ -228,5 +287,57 @@ function OAuthPanel({ field, close }) {
|
|
|
228
287
|
})
|
|
229
288
|
});
|
|
230
289
|
}
|
|
290
|
+
/** the code of a device authorization, until users enter it */
|
|
291
|
+
function DeviceVerification({ code, onCancel }) {
|
|
292
|
+
const t = useTranslations({ note: "OAuth dialog" });
|
|
293
|
+
const tPlayground = useTranslations({ note: "playground" });
|
|
294
|
+
const [isCopied, onCopy] = useCopyButton(() => navigator.clipboard.writeText(code.userCode));
|
|
295
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("div", {
|
|
296
|
+
className: "flex flex-col items-center gap-4 border-b px-4 py-8 text-center starting:opacity-0 motion-safe:transition-[opacity,translate] motion-safe:duration-300 motion-safe:starting:translate-y-1",
|
|
297
|
+
children: [
|
|
298
|
+
/* @__PURE__ */ jsx("p", {
|
|
299
|
+
className: "text-xs text-fd-muted-foreground",
|
|
300
|
+
children: t("Enter this code on the verification page.")
|
|
301
|
+
}),
|
|
302
|
+
/* @__PURE__ */ jsxs("div", {
|
|
303
|
+
className: "flex items-center gap-1 rounded-lg border bg-fd-secondary py-1 ps-4 pe-1",
|
|
304
|
+
children: [/* @__PURE__ */ jsx("code", {
|
|
305
|
+
className: "font-mono text-xl font-medium tracking-widest select-all",
|
|
306
|
+
children: code.userCode
|
|
307
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
308
|
+
type: "button",
|
|
309
|
+
"aria-label": isCopied ? tPlayground("Copied", { note: "aria-label" }) : tPlayground("Copy", { note: "aria-label" }),
|
|
310
|
+
onClick: onCopy,
|
|
311
|
+
className: iconButtonClassName,
|
|
312
|
+
children: isCopied ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(Copy, {})
|
|
313
|
+
})]
|
|
314
|
+
}),
|
|
315
|
+
/* @__PURE__ */ jsxs("a", {
|
|
316
|
+
href: code.verificationUriComplete ?? code.verificationUri,
|
|
317
|
+
target: "_blank",
|
|
318
|
+
rel: "noreferrer",
|
|
319
|
+
className: cn(buttonVariants({
|
|
320
|
+
variant: "primary",
|
|
321
|
+
size: "sm"
|
|
322
|
+
}), "gap-1.5 px-3"),
|
|
323
|
+
children: [t("Open verification page"), /* @__PURE__ */ jsx(ExternalLink, { className: "size-3.5" })]
|
|
324
|
+
})
|
|
325
|
+
]
|
|
326
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
327
|
+
className: "flex items-center gap-3 px-4 py-3",
|
|
328
|
+
children: [/* @__PURE__ */ jsxs("p", {
|
|
329
|
+
className: "flex min-w-0 flex-1 items-center gap-1.5 text-xs text-fd-muted-foreground",
|
|
330
|
+
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3" }), t("Waiting for authorization...")]
|
|
331
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
332
|
+
type: "button",
|
|
333
|
+
onClick: onCancel,
|
|
334
|
+
className: cn(buttonVariants({
|
|
335
|
+
variant: "secondary",
|
|
336
|
+
size: "sm"
|
|
337
|
+
}), "shrink-0 px-3"),
|
|
338
|
+
children: t("Cancel")
|
|
339
|
+
})]
|
|
340
|
+
})] });
|
|
341
|
+
}
|
|
231
342
|
//#endregion
|
|
232
343
|
export { oauthPanelProvider };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useOperation } from "../../../operation.js";
|
|
3
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
4
|
+
import { Markdown } from "../../components/markdown.js";
|
|
4
5
|
import { cn } from "../../../utils/cn.js";
|
|
5
6
|
import { Segmented, SegmentedList } from "../../components/segmented.js";
|
|
6
7
|
import { anyFields, useResolvedSchema, useSchemaUtils } from "../../../packages/shared-api/dist/components/playground/schema.js";
|
|
@@ -10,7 +11,7 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
|
10
11
|
import { useDataEngine, useFieldValue } from "@fumari/stf";
|
|
11
12
|
import { stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
12
13
|
import { useTranslations } from "@fuma-translate/react";
|
|
13
|
-
import { ArrowLeft, Braces, ChevronRight, Cookie, KeyRound, PlusIcon, Route, Rows3, SlidersHorizontal } from "lucide-react";
|
|
14
|
+
import { ArrowLeft, Braces, ChevronRight, Cookie, KeyRound, PlusIcon, Route, Rows3, ShieldCheck, SlidersHorizontal } from "lucide-react";
|
|
14
15
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
15
16
|
//#region src/ui/playground/components/request-panel.tsx
|
|
16
17
|
const sectionIcons = {
|
|
@@ -283,7 +284,7 @@ function Section({ icon: Icon, title, count, actions, children }) {
|
|
|
283
284
|
return /* @__PURE__ */ jsxs("section", {
|
|
284
285
|
className: "border-b last:border-b-0",
|
|
285
286
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
286
|
-
className: "sticky top-0 z-10 flex h-
|
|
287
|
+
className: "sticky top-0 z-10 flex h-10 items-center gap-2 border-b bg-fd-card ps-4 pe-2 @sm:pe-7.5",
|
|
287
288
|
children: [
|
|
288
289
|
/* @__PURE__ */ jsx(Icon, { className: "size-3.5 shrink-0 text-fd-primary" }),
|
|
289
290
|
/* @__PURE__ */ jsx("h3", {
|
|
@@ -374,6 +375,20 @@ function AuthPanelRow({ title, component }) {
|
|
|
374
375
|
children: title
|
|
375
376
|
});
|
|
376
377
|
}
|
|
378
|
+
/** mutual TLS schemes, they have no value */
|
|
379
|
+
const mutualTLSProvider = {
|
|
380
|
+
on: ({ scheme }) => scheme.type === "mutualTLS",
|
|
381
|
+
render: function MutualTLSNote({ field }) {
|
|
382
|
+
const t = useTranslations({ note: "playground" });
|
|
383
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
384
|
+
className: "flex gap-2 border-b px-4 py-2.5 text-xs text-fd-muted-foreground last:border-b-0",
|
|
385
|
+
children: [/* @__PURE__ */ jsx(ShieldCheck, { className: "mt-px size-3.5 shrink-0" }), /* @__PURE__ */ jsxs("div", {
|
|
386
|
+
className: "min-w-0 flex-1 [&_a]:underline",
|
|
387
|
+
children: [/* @__PURE__ */ jsx("p", { children: t("Requires a client certificate installed in your browser.") }), field.scheme.description && /* @__PURE__ */ jsx(Markdown, { md: field.scheme.description })]
|
|
388
|
+
})]
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
};
|
|
377
392
|
function BodySection({ body, renderBodyField, onNavigate }) {
|
|
378
393
|
const t = useTranslations({ note: "playground" });
|
|
379
394
|
const [mode, setMode] = useState("form");
|
|
@@ -463,4 +478,4 @@ function formatJson(value) {
|
|
|
463
478
|
return JSON.stringify(value ?? {}, null, 2);
|
|
464
479
|
}
|
|
465
480
|
//#endregion
|
|
466
|
-
export { RequestPanel };
|
|
481
|
+
export { RequestPanel, mutualTLSProvider };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
4
|
-
import { Markdown } from "../../components/markdown.js";
|
|
2
|
+
import { useResponseExamples } from "../../../operation.js";
|
|
5
3
|
import { ClientCodeBlock } from "../../components/codeblock.js";
|
|
4
|
+
import { Markdown } from "../../components/markdown.js";
|
|
6
5
|
import { cn } from "../../../utils/cn.js";
|
|
6
|
+
import { CodeUsages, ExampleSelect } from "../../operation/usage-tabs.js";
|
|
7
7
|
import { Segmented, SegmentedList, SegmentedPanel } from "../../components/segmented.js";
|
|
8
8
|
import { DefaultResultDisplay, PanelHeader, panelCodeBlock } from "./result-display.js";
|
|
9
9
|
import { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
|
|
@@ -11,14 +11,16 @@ import { useState } from "react";
|
|
|
11
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
import { useTranslations } from "@fuma-translate/react";
|
|
13
13
|
import { SendHorizontal } from "lucide-react";
|
|
14
|
-
import { CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger } from "fumadocs-ui/components/codeblock";
|
|
15
14
|
//#region src/ui/playground/components/response-panel.tsx
|
|
16
|
-
/** the code usages of the request, above its response or the documented examples */
|
|
17
15
|
function ResponsePanel({ response, loading, onReset, ResultDisplay = DefaultResultDisplay, className }) {
|
|
18
16
|
const t = useTranslations({ note: "playground" });
|
|
19
17
|
return /* @__PURE__ */ jsxs("div", {
|
|
20
18
|
className: cn("@container flex min-h-0 flex-col", className),
|
|
21
|
-
children: [/* @__PURE__ */ jsx(
|
|
19
|
+
children: [/* @__PURE__ */ jsx(CodeUsages, {
|
|
20
|
+
title: t("Request"),
|
|
21
|
+
className: "shrink-0 border-b",
|
|
22
|
+
viewportClassName: "max-h-[min(18rem,30vh)]"
|
|
23
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
22
24
|
className: "relative flex min-h-0 flex-1 flex-col",
|
|
23
25
|
children: [response ? /* @__PURE__ */ jsx(ResultDisplay, {
|
|
24
26
|
data: response.result,
|
|
@@ -31,40 +33,6 @@ function ResponsePanel({ response, loading, onReset, ResultDisplay = DefaultResu
|
|
|
31
33
|
})]
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
|
-
function RequestExample() {
|
|
35
|
-
const items = Array.from(useOperation().codeUsages.map());
|
|
36
|
-
if (items.length === 0) return null;
|
|
37
|
-
return /* @__PURE__ */ jsxs(CodeBlockTabs, {
|
|
38
|
-
groupId: "fumadocs_openapi_requests",
|
|
39
|
-
defaultValue: items[0][0],
|
|
40
|
-
className: "my-0 shrink-0 rounded-none border-0 border-b bg-transparent",
|
|
41
|
-
children: [/* @__PURE__ */ jsx(CodeBlockTabsList, {
|
|
42
|
-
className: "h-10 items-stretch border-b [scrollbar-width:none]",
|
|
43
|
-
children: items.map(([id, item]) => /* @__PURE__ */ jsx(CodeBlockTabsTrigger, {
|
|
44
|
-
value: id,
|
|
45
|
-
children: item.label ?? item.lang
|
|
46
|
-
}, id))
|
|
47
|
-
}), items.map(([id, item]) => /* @__PURE__ */ jsx(CodeBlockTab, {
|
|
48
|
-
value: id,
|
|
49
|
-
children: /* @__PURE__ */ jsx(UsageCode, {
|
|
50
|
-
id,
|
|
51
|
-
lang: item.lang
|
|
52
|
-
})
|
|
53
|
-
}, id))]
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function UsageCode({ id, lang }) {
|
|
57
|
-
const code = useCodeUsage(id);
|
|
58
|
-
if (!code) return null;
|
|
59
|
-
return /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
60
|
-
lang,
|
|
61
|
-
code,
|
|
62
|
-
codeblock: {
|
|
63
|
-
className: "rounded-none border-0 bg-transparent shadow-none",
|
|
64
|
-
viewportProps: { className: "max-h-[min(18rem,30vh)]" }
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
36
|
function ResponseExamples() {
|
|
69
37
|
const t = useTranslations({ note: "playground" });
|
|
70
38
|
const tabs = useResponseExamples();
|
|
@@ -90,60 +58,55 @@ function ResponseExamples() {
|
|
|
90
58
|
setSelected(0);
|
|
91
59
|
},
|
|
92
60
|
className: "flex min-h-0 flex-1 flex-col",
|
|
93
|
-
children: [
|
|
94
|
-
/* @__PURE__ */
|
|
95
|
-
className: "
|
|
96
|
-
children:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
61
|
+
children: [
|
|
62
|
+
/* @__PURE__ */ jsxs(PanelHeader, {
|
|
63
|
+
className: "border-b-0",
|
|
64
|
+
children: [
|
|
65
|
+
/* @__PURE__ */ jsx("span", {
|
|
66
|
+
className: "me-auto text-[0.8125rem] font-medium",
|
|
67
|
+
children: t("Response")
|
|
68
|
+
}),
|
|
69
|
+
examples.length > 1 && /* @__PURE__ */ jsx(ExampleSelect, {
|
|
70
|
+
items: examples.map((item, i) => ({
|
|
71
|
+
value: String(i),
|
|
72
|
+
label: item.label
|
|
73
|
+
})),
|
|
74
|
+
value: String(selected),
|
|
75
|
+
onValueChange: (v) => setSelected(Number(v)),
|
|
76
|
+
className: "max-w-40"
|
|
77
|
+
}),
|
|
78
|
+
/* @__PURE__ */ jsx(SegmentedList, {
|
|
79
|
+
className: "max-w-1/2 shrink-0 overflow-x-auto [scrollbar-width:none]",
|
|
80
|
+
items: tabs.map((item) => ({
|
|
81
|
+
value: item.code,
|
|
82
|
+
label: /* @__PURE__ */ jsx("span", {
|
|
83
|
+
className: "font-mono",
|
|
84
|
+
children: item.code
|
|
85
|
+
})
|
|
86
|
+
}))
|
|
87
|
+
})
|
|
88
|
+
]
|
|
102
89
|
}),
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
label: item.label
|
|
107
|
-
})),
|
|
108
|
-
value: String(selected),
|
|
109
|
-
onValueChange: (v) => v !== null && setSelected(Number(v)),
|
|
110
|
-
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
111
|
-
className: "h-7 w-auto max-w-40 shrink-0 gap-1.5 border-0 bg-transparent px-2 text-xs hover:bg-fd-accent focus:ring-0 focus-visible:ring-2",
|
|
112
|
-
children: /* @__PURE__ */ jsx(SelectValue, { className: "truncate" })
|
|
113
|
-
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
114
|
-
align: "end",
|
|
115
|
-
children: examples.map((item, i) => /* @__PURE__ */ jsx(SelectItem, {
|
|
116
|
-
value: String(i),
|
|
117
|
-
className: "text-xs",
|
|
118
|
-
children: item.label
|
|
119
|
-
}, i))
|
|
120
|
-
})]
|
|
90
|
+
tab.response.description && /* @__PURE__ */ jsx("div", {
|
|
91
|
+
className: "prose prose-xs prose-no-margin -mt-1 px-4 pb-2.5 text-fd-muted-foreground",
|
|
92
|
+
children: /* @__PURE__ */ jsx(Markdown, { md: tab.response.description })
|
|
121
93
|
}),
|
|
122
|
-
/* @__PURE__ */ jsx(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
94
|
+
/* @__PURE__ */ jsx(SegmentedPanel, {
|
|
95
|
+
value: tab.code,
|
|
96
|
+
className: "flex min-h-0 flex-1 flex-col overflow-auto border-t",
|
|
97
|
+
children: example ? /* @__PURE__ */ jsx("div", {
|
|
98
|
+
className: "min-h-0 flex-1",
|
|
99
|
+
children: /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
100
|
+
lang: "json",
|
|
101
|
+
code: JSON.stringify(example.sample, null, 2),
|
|
102
|
+
codeblock: panelCodeBlock
|
|
129
103
|
})
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
value: tab.code,
|
|
134
|
-
className: "flex min-h-0 flex-1 flex-col overflow-auto",
|
|
135
|
-
children: example ? /* @__PURE__ */ jsx("div", {
|
|
136
|
-
className: "min-h-0 flex-1",
|
|
137
|
-
children: /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
138
|
-
lang: "json",
|
|
139
|
-
code: JSON.stringify(example.sample, null, 2),
|
|
140
|
-
codeblock: panelCodeBlock
|
|
104
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
105
|
+
className: "p-4 text-sm text-fd-muted-foreground",
|
|
106
|
+
children: t("No example available.")
|
|
141
107
|
})
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
children: t("No example available.")
|
|
145
|
-
})
|
|
146
|
-
}, tab.code)]
|
|
108
|
+
}, tab.code)
|
|
109
|
+
]
|
|
147
110
|
});
|
|
148
111
|
}
|
|
149
112
|
//#endregion
|
|
@@ -27,7 +27,7 @@ export interface OpenAPIRuntimeOptions {
|
|
|
27
27
|
*/
|
|
28
28
|
mediaAdapters?: Record<string, MediaAdapter>;
|
|
29
29
|
/**
|
|
30
|
-
* Set a prefix for
|
|
30
|
+
* Set a prefix for storage keys.
|
|
31
31
|
*
|
|
32
32
|
* Useful when using multiple OpenAPI instances to prevent state conflicts.
|
|
33
33
|
*
|
|
@@ -119,6 +119,7 @@ export interface OpenAPIRenderOptions {
|
|
|
119
119
|
operation: OperationObject;
|
|
120
120
|
}, ctx: RenderContext) => ReactNode;
|
|
121
121
|
renderAPIExampleLayout?: (slots: {
|
|
122
|
+
/** the select of example requests, only with `renderAPIExampleUsageTabs`, default usage tabs have it in their title */
|
|
122
123
|
selector: ReactNode;
|
|
123
124
|
usageTabs: ReactNode;
|
|
124
125
|
responseTabs: ReactNode;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "./builder.js";
|
|
2
|
+
import { TOCItemType } from "fumadocs-core/toc";
|
|
3
|
+
import "fumadocs-core/mdx-plugins";
|
|
4
|
+
//#region src/utils/pages/to-static-data.d.ts
|
|
5
|
+
/** the `_openapi` data of pages */
|
|
6
|
+
export interface InternalOpenAPIMeta {
|
|
7
|
+
method?: string;
|
|
8
|
+
webhook?: boolean;
|
|
9
|
+
deprecated?: boolean;
|
|
10
|
+
preload?: string[];
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
package/dist/utils/use-server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { joinURL, resolveServerUrl } from "../packages/shared-api/dist/utils/url.js";
|
|
3
2
|
import { useServerStore } from "../packages/shared-api/dist/utils/use-server-store.js";
|
|
3
|
+
import { joinURL, resolveServerUrl } from "../packages/shared-api/dist/utils/url.js";
|
|
4
4
|
import { createContext, use, useCallback, useMemo, useSyncExternalStore } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/utils/use-server.tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.5.1",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"./ui/playground/client": "./dist/ui/playground/client.js",
|
|
47
47
|
"./ui/scalar": "./dist/ui/scalar/index.js",
|
|
48
48
|
"./package.json": "./package.json",
|
|
49
|
-
"./css
|
|
49
|
+
"./css/preset.css": "./css/preset.css"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
@@ -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.
|
|
57
|
+
"@fumadocs/json-schema": "^0.3.1",
|
|
58
58
|
"@fumari/json-schema-ts": "^1.0.2",
|
|
59
|
-
"@fumari/stf": "1.1.1",
|
|
59
|
+
"@fumari/stf": "^1.1.1",
|
|
60
60
|
"@scalar/json-magic": "^0.15.4",
|
|
61
61
|
"@scalar/openapi-upgrader": "^0.4.1",
|
|
62
62
|
"chokidar": "^5.0.0",
|
|
@@ -68,6 +68,7 @@
|
|
|
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
72
|
"yaml": "^2.9.1"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
@@ -78,10 +79,10 @@
|
|
|
78
79
|
"@types/react-dom": "^19.3.0",
|
|
79
80
|
"fast-content-type-parse": "^4.0.0",
|
|
80
81
|
"fuma-cli": "^0.3.1",
|
|
81
|
-
"fumadocs-core": "16.17.
|
|
82
|
-
"fumadocs-ui": "npm:@fumadocs/base-ui@16.17.
|
|
82
|
+
"fumadocs-core": "16.17.5",
|
|
83
|
+
"fumadocs-ui": "npm:@fumadocs/base-ui@16.17.5",
|
|
83
84
|
"json-schema-typed": "^8.0.2",
|
|
84
|
-
"shared-api": "0.2.
|
|
85
|
+
"shared-api": "0.2.12",
|
|
85
86
|
"tsconfig": "0.0.0",
|
|
86
87
|
"tsdown": "0.23.0",
|
|
87
88
|
"xml-js": "^1.6.11"
|