fumadocs-openapi 12.2.0 → 12.4.0
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 +4 -4
- package/dist/.translations/keys.js +4 -4
- package/dist/operation.js +4 -4
- package/dist/packages/shared-api/dist/.translations/index.d.ts +1 -0
- package/dist/packages/shared-api/dist/.translations/keys.js +1 -0
- package/dist/packages/shared-api/dist/auto-anchor/index.js +54 -10
- package/dist/packages/shared-api/dist/components/accordion.js +3 -11
- package/dist/packages/shared-api/dist/components/collapsible.js +16 -0
- package/dist/packages/shared-api/dist/components/defaults.js +1 -1
- package/dist/packages/shared-api/dist/components/schema/client.d.ts +5 -0
- package/dist/packages/shared-api/dist/components/schema/client.js +408 -455
- package/dist/packages/shared-api/dist/components/select-tab.js +7 -12
- package/dist/playground/auth.d.ts +61 -7
- package/dist/playground/auth.js +192 -95
- package/dist/playground/fetcher.d.ts +1 -1
- package/dist/playground/index.d.ts +2 -2
- package/dist/playground/index.js +2 -2
- package/dist/playground/use-playground.d.ts +5 -3
- package/dist/playground/use-playground.js +22 -10
- package/dist/requests/generators/csharp.js +11 -21
- package/dist/requests/generators/curl.js +12 -14
- package/dist/requests/generators/go.js +22 -33
- package/dist/requests/generators/index.d.ts +1 -1
- package/dist/requests/generators/java.js +33 -37
- package/dist/requests/generators/javascript.js +13 -20
- package/dist/requests/generators/python.js +12 -17
- package/dist/requests/generators/rust.js +15 -20
- package/dist/requests/index.d.ts +1 -1
- package/dist/requests/media/adapter.d.ts +0 -1
- package/dist/requests/media/adapter.js +50 -42
- package/dist/requests/media/encode.d.ts +1 -1
- package/dist/requests/media/encode.js +1 -1
- package/dist/requests/string-utils.js +14 -6
- package/dist/ui/components/dialog.js +14 -0
- package/dist/ui/components/endpoint.js +11 -8
- package/dist/ui/components/heading.js +1 -1
- package/dist/ui/components/schema.js +1 -1
- package/dist/ui/{playground/components → components}/segmented.js +2 -2
- package/dist/ui/operation/index.js +262 -237
- package/dist/ui/operation/request-tabs.js +1 -1
- package/dist/ui/operation/response-tabs.js +1 -1
- package/dist/ui/operation/usage-tabs.js +1 -1
- package/dist/ui/playground/client.d.ts +1 -1
- package/dist/ui/playground/client.js +23 -19
- package/dist/ui/playground/components/fields.js +36 -15
- package/dist/ui/playground/components/oauth-panel.js +71 -21
- package/dist/ui/playground/components/request-panel.js +80 -94
- package/dist/ui/playground/components/response-panel.js +1 -1
- package/dist/ui/playground/components/result-display.js +1 -1
- package/dist/ui/playground/components/server-select.js +1 -1
- package/dist/utils/create-page.js +2 -2
- package/dist/utils/get-example-requests.js +1 -1
- package/dist/utils/use-server.d.ts +3 -3
- package/dist/utils/use-server.js +2 -2
- package/package.json +5 -5
- package/dist/packages/shared-api/dist/auto-anchor/client.js +0 -20
- package/dist/packages/shared-api/dist/components/popover.js +0 -23
- package/dist/packages/shared-api/dist/utils/merge-refs.js +0 -11
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useOpenAPI } from "../../utils/create-page.js";
|
|
3
2
|
import { useExampleRequests, useOperation } from "../../operation.js";
|
|
3
|
+
import { useOpenAPI } from "../../utils/create-page.js";
|
|
4
4
|
import { usePlayground } from "../../playground/use-playground.js";
|
|
5
5
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../packages/shared-api/dist/components/select.js";
|
|
6
6
|
import { cn } from "../../utils/cn.js";
|
|
7
|
-
import { Segmented, SegmentedList } from "
|
|
7
|
+
import { Segmented, SegmentedList } from "../components/segmented.js";
|
|
8
8
|
import { DefaultResultDisplay, iconButtonClassName } from "./components/result-display.js";
|
|
9
9
|
import { EndpointBar } from "../components/endpoint.js";
|
|
10
|
+
import { DialogPopup } from "../components/dialog.js";
|
|
10
11
|
import { SchemaProvider } from "../../packages/shared-api/dist/components/playground/schema.js";
|
|
11
12
|
import { UrlBar } from "./components/url-bar.js";
|
|
12
13
|
import { RequestPanel } from "./components/request-panel.js";
|
|
14
|
+
import { oauthPanelProvider } from "./components/oauth-panel.js";
|
|
13
15
|
import { ResponsePanel } from "./components/response-panel.js";
|
|
14
|
-
import { useState } from "react";
|
|
16
|
+
import { useMemo, useState } from "react";
|
|
15
17
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
18
|
import { StfProvider, useFieldValue } from "@fumari/stf";
|
|
17
19
|
import { useTranslations } from "@fuma-translate/react";
|
|
20
|
+
import { useOnChange } from "fumadocs-core/utils/use-on-change";
|
|
18
21
|
import { Play, X } from "lucide-react";
|
|
19
22
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
20
23
|
import { Dialog } from "@base-ui/react/dialog";
|
|
21
|
-
import { useOnChange } from "fumadocs-core/utils/use-on-change";
|
|
22
24
|
//#region src/ui/playground/client.tsx
|
|
23
|
-
function PlaygroundClient({ writeOnly = true, readOnly = false, transformAuthInputs, fetchOptions, components, renderParameterField, renderBodyField, ...rest }) {
|
|
25
|
+
function PlaygroundClient({ writeOnly = true, readOnly = false, authProviders, transformAuthInputs, fetchOptions, components, renderParameterField, renderBodyField, ...rest }) {
|
|
24
26
|
const t = useTranslations({ note: "playground" });
|
|
25
27
|
const { doc } = useOpenAPI();
|
|
26
28
|
const { path, method, operation } = useOperation();
|
|
29
|
+
const providers = useMemo(() => [...authProviders ?? [], oauthPanelProvider], [authProviders]);
|
|
27
30
|
const playground = usePlayground({
|
|
31
|
+
authProviders: providers,
|
|
28
32
|
transformAuthInputs,
|
|
29
33
|
fetchOptions
|
|
30
34
|
});
|
|
@@ -53,15 +57,15 @@ function PlaygroundClient({ writeOnly = true, readOnly = false, transformAuthInp
|
|
|
53
57
|
}), "group shrink-0 gap-1.5 rounded-lg px-3 transition-[background-color,scale] active:scale-[0.97] motion-reduce:transition-none"),
|
|
54
58
|
children: [/* @__PURE__ */ jsx(Play, { className: "size-3 fill-current transition-transform duration-200 group-hover:translate-x-px motion-reduce:transition-none" }), t("Try in Playground")]
|
|
55
59
|
})
|
|
56
|
-
}), /* @__PURE__ */
|
|
57
|
-
className: "
|
|
60
|
+
}), /* @__PURE__ */ jsx(DialogPopup, {
|
|
61
|
+
className: "sm:h-[min(52rem,calc(100dvh-3rem))] sm:w-[min(80rem,calc(100vw-3rem))]",
|
|
58
62
|
children: /* @__PURE__ */ jsx(PlaygroundDialog, {
|
|
59
63
|
playground,
|
|
60
64
|
renderParameterField,
|
|
61
65
|
renderBodyField,
|
|
62
66
|
ResultDisplay: components?.ResultDisplay
|
|
63
67
|
})
|
|
64
|
-
})]
|
|
68
|
+
})]
|
|
65
69
|
})
|
|
66
70
|
})
|
|
67
71
|
});
|
|
@@ -71,18 +75,15 @@ function PlaygroundDialog({ playground, renderParameterField, renderBodyField, R
|
|
|
71
75
|
const { title, method, path, operation, parameters } = useOperation();
|
|
72
76
|
const { response, isSending, send, clearResponse } = playground;
|
|
73
77
|
const [view, setView] = useState("request");
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
const onSubmit = (e) => {
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
send();
|
|
81
|
+
setView("response");
|
|
82
|
+
};
|
|
83
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
76
84
|
className: "flex min-h-0 flex-1 flex-col",
|
|
77
|
-
onSubmit: (e) => {
|
|
78
|
-
e.preventDefault();
|
|
79
|
-
send();
|
|
80
|
-
setView("response");
|
|
81
|
-
},
|
|
82
85
|
onKeyDown: (e) => {
|
|
83
|
-
if (e.key
|
|
84
|
-
e.preventDefault();
|
|
85
|
-
e.currentTarget.requestSubmit();
|
|
86
|
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) onSubmit(e);
|
|
86
87
|
},
|
|
87
88
|
children: [
|
|
88
89
|
/* @__PURE__ */ jsxs("div", {
|
|
@@ -106,8 +107,10 @@ function PlaygroundDialog({ playground, renderParameterField, renderBodyField, R
|
|
|
106
107
|
})
|
|
107
108
|
]
|
|
108
109
|
}),
|
|
109
|
-
/* @__PURE__ */ jsx("
|
|
110
|
+
/* @__PURE__ */ jsx("form", {
|
|
111
|
+
noValidate: true,
|
|
110
112
|
className: "shrink-0 px-3 pb-3 sm:px-4",
|
|
113
|
+
onSubmit,
|
|
111
114
|
children: /* @__PURE__ */ jsx(UrlBar, {
|
|
112
115
|
method,
|
|
113
116
|
route: path,
|
|
@@ -135,6 +138,7 @@ function PlaygroundDialog({ playground, renderParameterField, renderBodyField, R
|
|
|
135
138
|
className: "mx-3 mb-3 grid min-h-0 flex-1 overflow-hidden rounded-xl border bg-fd-card sm:mx-4 sm:mb-4 md:grid-cols-[minmax(0,11fr)_minmax(0,9fr)]",
|
|
136
139
|
children: [/* @__PURE__ */ jsx(RequestPanel, {
|
|
137
140
|
playground,
|
|
141
|
+
onSubmit,
|
|
138
142
|
renderParameterField,
|
|
139
143
|
renderBodyField,
|
|
140
144
|
className: cn(view !== "request" && "max-md:hidden")
|
|
@@ -9,10 +9,11 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
|
9
9
|
import { useArray, useDataEngine, useFieldValue, useObject } from "@fumari/stf";
|
|
10
10
|
import { isPlainObject, stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
11
11
|
import { useTranslations } from "@fuma-translate/react";
|
|
12
|
-
import {
|
|
13
|
-
import { Check, ChevronRight, ChevronsUpDown, Info, Plus, Trash2, Upload, X } from "lucide-react";
|
|
12
|
+
import { Check, ChevronRight, ChevronsUpDown, Copy, Info, Plus, Trash2, Upload, X } from "lucide-react";
|
|
14
13
|
import { Select } from "@base-ui/react/select";
|
|
15
14
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
15
|
+
import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
|
|
16
|
+
import { Popover } from "@base-ui/react/popover";
|
|
16
17
|
//#region src/ui/playground/components/fields.tsx
|
|
17
18
|
/** the type of a field, at the end of its cell like a unit */
|
|
18
19
|
const typeClassName = "flex shrink-0 items-center pe-1 font-mono text-xs text-fd-muted-foreground";
|
|
@@ -450,33 +451,53 @@ function SelectRow({ name, ...props }) {
|
|
|
450
451
|
});
|
|
451
452
|
}
|
|
452
453
|
/** a row of read-only text */
|
|
453
|
-
function TextRow({ name, children }) {
|
|
454
|
+
function TextRow({ name, description, copyable = false, children }) {
|
|
454
455
|
return /* @__PURE__ */ jsxs(Row, {
|
|
455
456
|
name,
|
|
456
457
|
readOnly: true,
|
|
458
|
+
info: /* @__PURE__ */ jsx(FieldInfo, {
|
|
459
|
+
name,
|
|
460
|
+
field: { type: "string" },
|
|
461
|
+
description
|
|
462
|
+
}),
|
|
457
463
|
children: [/* @__PURE__ */ jsx("span", {
|
|
458
464
|
className: "flex min-w-0 flex-1 items-center px-3 text-fd-muted-foreground",
|
|
459
465
|
children: /* @__PURE__ */ jsx("span", {
|
|
460
466
|
className: "truncate",
|
|
461
467
|
children
|
|
462
468
|
})
|
|
463
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
469
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
470
|
+
className: slotClassName,
|
|
471
|
+
children: copyable && /* @__PURE__ */ jsx(CopyButton, { text: children })
|
|
472
|
+
})]
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
function CopyButton({ text }) {
|
|
476
|
+
const t = useTranslations({ note: "playground" });
|
|
477
|
+
const [isChecked, onCopy] = useCopyButton(() => navigator.clipboard.writeText(text));
|
|
478
|
+
return /* @__PURE__ */ jsx(SlotButton, {
|
|
479
|
+
label: isChecked ? t("Copied", { note: "aria-label" }) : t("Copy", { note: "aria-label" }),
|
|
480
|
+
onClick: onCopy,
|
|
481
|
+
children: isChecked ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(Copy, {})
|
|
464
482
|
});
|
|
465
483
|
}
|
|
466
484
|
/** a row opening something else, like a panel */
|
|
467
485
|
function LinkRow({ name, onClick, children }) {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
children:
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
children: /* @__PURE__ */ jsx("span", {
|
|
476
|
-
className: "text-fd-muted-foreground",
|
|
486
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
487
|
+
type: "button",
|
|
488
|
+
onClick,
|
|
489
|
+
className: cn(rowButtonClassName, "group/nav border-b last:border-b-0"),
|
|
490
|
+
children: [
|
|
491
|
+
/* @__PURE__ */ jsx("span", {
|
|
492
|
+
className: "min-w-0 flex-1 truncate text-start",
|
|
477
493
|
children
|
|
478
|
-
})
|
|
479
|
-
|
|
494
|
+
}),
|
|
495
|
+
/* @__PURE__ */ jsx("span", {
|
|
496
|
+
className: typeClassName,
|
|
497
|
+
children: name
|
|
498
|
+
}),
|
|
499
|
+
/* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 transition-transform duration-200 group-hover/nav:translate-x-0.5 motion-reduce:transition-none" })
|
|
500
|
+
]
|
|
480
501
|
});
|
|
481
502
|
}
|
|
482
503
|
/** a row toggled on click, its check box takes the slot */
|
|
@@ -1,31 +1,71 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useQuery } from "../../../packages/shared-api/dist/utils/use-query.js";
|
|
3
|
-
import { usePlaygroundAuth } from "../../../playground/auth.js";
|
|
4
3
|
import { useServer } from "../../../utils/use-server.js";
|
|
4
|
+
import { finishOAuthFlow, requestOAuthToken, useAuthRedirect } from "../../../playground/auth.js";
|
|
5
|
+
import { useOpenAPI } from "../../../utils/create-page.js";
|
|
5
6
|
import { Markdown } from "../../components/markdown.js";
|
|
6
7
|
import { cn } from "../../../utils/cn.js";
|
|
7
8
|
import { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
|
|
8
9
|
import { CheckRow, SelectRow, TextRow, ValueRow } from "./fields.js";
|
|
9
10
|
import { useState } from "react";
|
|
10
11
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { StfProvider, useStf } from "@fumari/stf";
|
|
12
|
+
import { StfProvider, useDataEngine, useStf } from "@fumari/stf";
|
|
12
13
|
import { useTranslations } from "@fuma-translate/react";
|
|
13
14
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
14
15
|
//#region src/ui/playground/components/oauth-panel.tsx
|
|
16
|
+
/** OAuth 2.0 schemes, authorized in a panel */
|
|
17
|
+
const oauthPanelProvider = {
|
|
18
|
+
on: ({ scheme }) => scheme.type === "oauth2",
|
|
19
|
+
render: function OAuthRows({ field, Value, Panel }) {
|
|
20
|
+
const t = useTranslations({ note: "playground" });
|
|
21
|
+
const engine = useDataEngine();
|
|
22
|
+
const query = useQuery(async (token) => {
|
|
23
|
+
engine.update(field.fieldName, await token);
|
|
24
|
+
});
|
|
25
|
+
useAuthRedirect(field, (url, data) => {
|
|
26
|
+
const token = finishOAuthFlow(url, data);
|
|
27
|
+
if (token !== void 0) query.start(token);
|
|
28
|
+
});
|
|
29
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
30
|
+
/* @__PURE__ */ jsx(Value, {
|
|
31
|
+
name: "Authorization",
|
|
32
|
+
type: "header",
|
|
33
|
+
description: field.scheme.description
|
|
34
|
+
}),
|
|
35
|
+
query.isLoading && /* @__PURE__ */ jsxs("p", {
|
|
36
|
+
className: "flex items-center gap-1.5 border-b px-4 py-2.5 text-xs text-fd-muted-foreground",
|
|
37
|
+
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3" }), t("Fetching token...")]
|
|
38
|
+
}),
|
|
39
|
+
query.error != null && /* @__PURE__ */ jsxs("div", {
|
|
40
|
+
className: "border-b px-4 py-2.5 text-xs",
|
|
41
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
42
|
+
className: "font-medium text-red-400",
|
|
43
|
+
children: t("Failed to fetch token")
|
|
44
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
45
|
+
className: "text-fd-muted-foreground",
|
|
46
|
+
children: String(query.error)
|
|
47
|
+
})]
|
|
48
|
+
}),
|
|
49
|
+
/* @__PURE__ */ jsx(Panel, {
|
|
50
|
+
title: t("Authorize"),
|
|
51
|
+
component: OAuthPanel
|
|
52
|
+
})
|
|
53
|
+
] });
|
|
54
|
+
}
|
|
55
|
+
};
|
|
15
56
|
/** obtain the access token of an OAuth 2.0 scheme */
|
|
16
|
-
function OAuthPanel({ field,
|
|
57
|
+
function OAuthPanel({ field, close }) {
|
|
17
58
|
const t = useTranslations({ note: "OAuth dialog" });
|
|
59
|
+
const engine = useDataEngine();
|
|
60
|
+
const redirect = useAuthRedirect(field);
|
|
61
|
+
const { oauthRedirectUrl } = useOpenAPI();
|
|
18
62
|
const { resolveUrl } = useServer();
|
|
19
|
-
const tokenInfo = usePlaygroundAuth().store[field.schemeId];
|
|
20
63
|
const scheme = field.scheme;
|
|
21
64
|
const flows = scheme.flows ?? {};
|
|
22
65
|
const [type, setType] = useState(() => Object.keys(flows)[0]);
|
|
23
|
-
const [clientAuth, setClientAuth] = useState(
|
|
66
|
+
const [clientAuth, setClientAuth] = useState("header");
|
|
24
67
|
const [scopes, setScopes] = useState(() => new Set(field.scopes));
|
|
25
|
-
const stf = useStf({
|
|
26
|
-
client_id: tokenInfo?.client_id,
|
|
27
|
-
client_secret: tokenInfo?.type === "authorization_code" ? tokenInfo.client_secret : void 0
|
|
28
|
-
}) });
|
|
68
|
+
const stf = useStf({});
|
|
29
69
|
const flowInfo = {
|
|
30
70
|
authorizationCode: {
|
|
31
71
|
name: t("Authorization code"),
|
|
@@ -57,24 +97,29 @@ function OAuthPanel({ field, authorize, onAuthorized }) {
|
|
|
57
97
|
for (const scope of field.scopes) scopeOptions[scope] ??= "";
|
|
58
98
|
const query = useQuery(async () => {
|
|
59
99
|
const credentials = stf.dataEngine.getData();
|
|
60
|
-
|
|
61
|
-
|
|
100
|
+
const token = await requestOAuthToken(scheme, type, {
|
|
101
|
+
schemeId: field.schemeId,
|
|
62
102
|
scopes: Array.from(scopes),
|
|
63
103
|
clientId: credentials.client_id ?? "",
|
|
64
104
|
clientSecret: credentials.client_secret ?? "",
|
|
65
105
|
username: credentials.username ?? "",
|
|
66
106
|
password: credentials.password ?? "",
|
|
67
|
-
clientAuth
|
|
68
|
-
|
|
107
|
+
clientAuth,
|
|
108
|
+
serverUrl,
|
|
109
|
+
redirectUrl: oauthRedirectUrl,
|
|
110
|
+
redirect
|
|
111
|
+
});
|
|
112
|
+
if (!token) return;
|
|
113
|
+
engine.update(field.fieldName, token);
|
|
114
|
+
close();
|
|
69
115
|
});
|
|
70
116
|
return /* @__PURE__ */ jsx(StfProvider, {
|
|
71
117
|
value: stf,
|
|
72
|
-
children: /* @__PURE__ */ jsxs("
|
|
73
|
-
|
|
74
|
-
|
|
118
|
+
children: /* @__PURE__ */ jsxs("form", {
|
|
119
|
+
noValidate: true,
|
|
120
|
+
onSubmit: (e) => {
|
|
75
121
|
e.preventDefault();
|
|
76
|
-
|
|
77
|
-
if (supported && !query.isLoading) query.start();
|
|
122
|
+
query.start();
|
|
78
123
|
},
|
|
79
124
|
children: [
|
|
80
125
|
scheme.description && /* @__PURE__ */ jsx("div", {
|
|
@@ -144,6 +189,12 @@ function OAuthPanel({ field, authorize, onAuthorized }) {
|
|
|
144
189
|
name: "token_url",
|
|
145
190
|
children: new URL(flow.tokenUrl, serverUrl).href
|
|
146
191
|
}),
|
|
192
|
+
redirects && /* @__PURE__ */ jsx(TextRow, {
|
|
193
|
+
name: "redirect_uri",
|
|
194
|
+
description: t("Add this to the allowed redirect URIs of your OAuth application."),
|
|
195
|
+
copyable: true,
|
|
196
|
+
children: new URL(oauthRedirectUrl ?? window.location.pathname, window.location.origin).href
|
|
197
|
+
}),
|
|
147
198
|
Object.keys(scopeOptions).length > 0 && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("p", {
|
|
148
199
|
className: "flex h-9 items-center border-b px-4 text-xs font-medium text-fd-muted-foreground",
|
|
149
200
|
children: t("Scopes")
|
|
@@ -164,9 +215,8 @@ function OAuthPanel({ field, authorize, onAuthorized }) {
|
|
|
164
215
|
className: cn("min-w-0 flex-1 text-xs", query.error ? "text-red-400" : "text-fd-muted-foreground"),
|
|
165
216
|
children: query.error ? String(query.error) : !supported ? t("Unsupported") : redirects && t("You will be redirected to authorize, then back to this page.")
|
|
166
217
|
}), /* @__PURE__ */ jsxs("button", {
|
|
167
|
-
type: "
|
|
218
|
+
type: "submit",
|
|
168
219
|
disabled: !supported || query.isLoading,
|
|
169
|
-
onClick: () => void query.start(),
|
|
170
220
|
className: cn(buttonVariants({
|
|
171
221
|
variant: "primary",
|
|
172
222
|
size: "sm"
|
|
@@ -179,4 +229,4 @@ function OAuthPanel({ field, authorize, onAuthorized }) {
|
|
|
179
229
|
});
|
|
180
230
|
}
|
|
181
231
|
//#endregion
|
|
182
|
-
export {
|
|
232
|
+
export { oauthPanelProvider };
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { usePlaygroundAuth } from "../../../playground/auth.js";
|
|
3
2
|
import { useOperation } from "../../../operation.js";
|
|
4
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
5
4
|
import { cn } from "../../../utils/cn.js";
|
|
6
|
-
import { Segmented, SegmentedList } from "
|
|
5
|
+
import { Segmented, SegmentedList } from "../../components/segmented.js";
|
|
7
6
|
import { anyFields, useResolvedSchema, useSchemaUtils } from "../../../packages/shared-api/dist/components/playground/schema.js";
|
|
8
|
-
import { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
|
|
9
7
|
import { FieldRow, FieldRows, LinkRow, ValueRow, getNestedFields, getRemoval, resolveField } from "./fields.js";
|
|
10
|
-
import {
|
|
11
|
-
import { Fragment, useState } from "react";
|
|
8
|
+
import { Fragment, createContext, use, useState } from "react";
|
|
12
9
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
10
|
import { useDataEngine, useFieldValue } from "@fumari/stf";
|
|
14
11
|
import { stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
@@ -30,12 +27,12 @@ const motionClassNames = {
|
|
|
30
27
|
};
|
|
31
28
|
const transitionClassName = "motion-safe:transition-[opacity,translate] motion-safe:duration-300 motion-safe:ease-[cubic-bezier(0.16,1,0.3,1)]";
|
|
32
29
|
/** the overview of all request inputs, nested fields open in their own panel */
|
|
33
|
-
function RequestPanel({ playground: { auth, body }, className, ...options }) {
|
|
30
|
+
function RequestPanel({ playground: { auth, body }, onSubmit, className, ...options }) {
|
|
34
31
|
const t = useTranslations({ note: "playground" });
|
|
35
32
|
const engine = useDataEngine();
|
|
36
33
|
const { generateDefault } = useSchemaUtils();
|
|
37
34
|
const [stack, setStack] = useState([]);
|
|
38
|
-
const [
|
|
35
|
+
const [authorizing, setAuthorizing] = useState(null);
|
|
39
36
|
const [motion, setMotion] = useState("forward");
|
|
40
37
|
const current = stack.at(-1);
|
|
41
38
|
const sectionNames = {
|
|
@@ -61,26 +58,28 @@ function RequestPanel({ playground: { auth, body }, className, ...options }) {
|
|
|
61
58
|
}]);
|
|
62
59
|
}
|
|
63
60
|
let panel = null;
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
children:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
61
|
+
if (authorizing) {
|
|
62
|
+
const { field, component: Component } = authorizing;
|
|
63
|
+
const close = () => setAuthorizing(null);
|
|
64
|
+
panel = /* @__PURE__ */ jsx(Panel, {
|
|
65
|
+
id: "auth",
|
|
66
|
+
motion: "forward",
|
|
67
|
+
nav: /* @__PURE__ */ jsx(PanelNav, {
|
|
68
|
+
root: t("Authorization"),
|
|
69
|
+
onRoot: close,
|
|
70
|
+
onBack: close,
|
|
71
|
+
children: /* @__PURE__ */ jsx(Crumb, { children: /* @__PURE__ */ jsx("span", {
|
|
72
|
+
"aria-current": "page",
|
|
73
|
+
className: "truncate px-1.5 py-1 font-mono font-medium",
|
|
74
|
+
children: field.schemeId
|
|
75
|
+
}) })
|
|
76
|
+
}),
|
|
77
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
78
|
+
field,
|
|
79
|
+
close
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
} else if (current) panel = /* @__PURE__ */ jsx(Panel, {
|
|
84
83
|
id: stringifyFieldKey(current.fieldName),
|
|
85
84
|
motion,
|
|
86
85
|
nav: /* @__PURE__ */ jsx(Breadcrumbs, {
|
|
@@ -96,17 +95,22 @@ function RequestPanel({ playground: { auth, body }, className, ...options }) {
|
|
|
96
95
|
});
|
|
97
96
|
return /* @__PURE__ */ jsxs("div", {
|
|
98
97
|
className: cn("@container grid min-h-0", className),
|
|
99
|
-
children: [/* @__PURE__ */
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
children: [/* @__PURE__ */ jsxs("form", {
|
|
99
|
+
noValidate: true,
|
|
100
|
+
className: "contents",
|
|
101
|
+
onSubmit,
|
|
102
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
103
|
+
className: cn("fd-scroll-container min-h-0 overflow-y-auto [grid-area:1/1]", transitionClassName, panel && "invisible opacity-0 motion-safe:-translate-x-6"),
|
|
104
|
+
children: /* @__PURE__ */ jsx(Overview, {
|
|
105
|
+
...options,
|
|
106
|
+
auth,
|
|
107
|
+
body,
|
|
108
|
+
sectionNames,
|
|
109
|
+
onNavigate: openNested([]),
|
|
110
|
+
onAuthorize: setAuthorizing
|
|
111
|
+
})
|
|
112
|
+
}), !authorizing && panel]
|
|
113
|
+
}), authorizing && panel]
|
|
110
114
|
});
|
|
111
115
|
}
|
|
112
116
|
/** a panel over the overview, its content animates in when `id` changes */
|
|
@@ -233,7 +237,7 @@ function SiblingSelect({ entry, siblings, onSelect }) {
|
|
|
233
237
|
}, item.value)) })]
|
|
234
238
|
});
|
|
235
239
|
}
|
|
236
|
-
function Overview({ auth, body, sectionNames, onNavigate,
|
|
240
|
+
function Overview({ auth, body, sectionNames, onNavigate, onAuthorize, renderParameterField, renderBodyField }) {
|
|
237
241
|
const t = useTranslations({ note: "playground" });
|
|
238
242
|
const { parameters } = useOperation();
|
|
239
243
|
if (auth.requirements.length === 0 && parameters.length === 0 && !body) return /* @__PURE__ */ jsx("p", {
|
|
@@ -243,7 +247,7 @@ function Overview({ auth, body, sectionNames, onNavigate, onOAuth, renderParamet
|
|
|
243
247
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
244
248
|
auth.requirements.length > 0 && /* @__PURE__ */ jsx(AuthSection, {
|
|
245
249
|
auth,
|
|
246
|
-
|
|
250
|
+
onAuthorize
|
|
247
251
|
}),
|
|
248
252
|
parameters.map(({ in: type, items }) => {
|
|
249
253
|
const entries = items.map((param) => ({
|
|
@@ -298,9 +302,8 @@ function Section({ icon: Icon, title, count, actions, children }) {
|
|
|
298
302
|
}), children]
|
|
299
303
|
});
|
|
300
304
|
}
|
|
301
|
-
function AuthSection({ auth,
|
|
305
|
+
function AuthSection({ auth, onAuthorize }) {
|
|
302
306
|
const t = useTranslations({ note: "playground" });
|
|
303
|
-
const { isLoading, error } = usePlaygroundAuth();
|
|
304
307
|
const { requirements, selected, select, fields } = auth;
|
|
305
308
|
const items = requirements.map((requirement, i) => ({
|
|
306
309
|
value: i,
|
|
@@ -312,13 +315,10 @@ function AuthSection({ auth, onOAuth }) {
|
|
|
312
315
|
})] }, item.id))
|
|
313
316
|
})
|
|
314
317
|
}));
|
|
315
|
-
return /* @__PURE__ */
|
|
318
|
+
return /* @__PURE__ */ jsx(Section, {
|
|
316
319
|
icon: KeyRound,
|
|
317
320
|
title: t("Authorization"),
|
|
318
|
-
actions:
|
|
319
|
-
className: "inline-flex items-center gap-1.5 text-xs text-fd-muted-foreground",
|
|
320
|
-
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3" }), t("Fetching token...")]
|
|
321
|
-
}), items.length > 1 ? /* @__PURE__ */ jsxs(Select, {
|
|
321
|
+
actions: items.length > 1 ? /* @__PURE__ */ jsxs(Select, {
|
|
322
322
|
items,
|
|
323
323
|
value: selected,
|
|
324
324
|
onValueChange: (v) => v !== null && select(v),
|
|
@@ -336,57 +336,43 @@ function AuthSection({ auth, onOAuth }) {
|
|
|
336
336
|
}) : /* @__PURE__ */ jsx("span", {
|
|
337
337
|
className: "truncate text-xs text-fd-muted-foreground",
|
|
338
338
|
children: items[0]?.label
|
|
339
|
-
})
|
|
340
|
-
children:
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
children:
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
339
|
+
}),
|
|
340
|
+
children: fields.map((field) => {
|
|
341
|
+
const Render = field.provider.render;
|
|
342
|
+
return /* @__PURE__ */ jsx(AuthFieldContext, {
|
|
343
|
+
value: {
|
|
344
|
+
field,
|
|
345
|
+
onAuthorize
|
|
346
|
+
},
|
|
347
|
+
children: /* @__PURE__ */ jsx(Render, {
|
|
348
|
+
field,
|
|
349
|
+
Value: AuthValue,
|
|
350
|
+
Panel: AuthPanelRow
|
|
351
|
+
})
|
|
352
|
+
}, stringifyFieldKey(field.fieldName));
|
|
353
|
+
})
|
|
353
354
|
});
|
|
354
355
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
field: { type: "string" }
|
|
364
|
-
}), /* @__PURE__ */ jsx(ValueRow, {
|
|
365
|
-
name: "password",
|
|
366
|
-
fieldName: [...fieldName, "password"],
|
|
367
|
-
field: {
|
|
368
|
-
type: "string",
|
|
369
|
-
format: "password"
|
|
370
|
-
}
|
|
371
|
-
})] });
|
|
372
|
-
if (scheme.type === "apiKey") return /* @__PURE__ */ jsx(ValueRow, {
|
|
373
|
-
name: scheme.name,
|
|
374
|
-
type: scheme.in,
|
|
375
|
-
description: scheme.description,
|
|
376
|
-
fieldName,
|
|
377
|
-
field: { type: "string" }
|
|
356
|
+
const AuthFieldContext = createContext(null);
|
|
357
|
+
const stringSchema = { type: "string" };
|
|
358
|
+
function AuthValue({ path, schema = stringSchema, ...props }) {
|
|
359
|
+
const { field } = use(AuthFieldContext);
|
|
360
|
+
return /* @__PURE__ */ jsx(ValueRow, {
|
|
361
|
+
...props,
|
|
362
|
+
fieldName: path ? [...field.fieldName, path] : field.fieldName,
|
|
363
|
+
field: schema
|
|
378
364
|
});
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
fieldName,
|
|
384
|
-
field: { type: "string" }
|
|
385
|
-
}), scheme.type === "oauth2" && /* @__PURE__ */ jsx(LinkRow, {
|
|
365
|
+
}
|
|
366
|
+
function AuthPanelRow({ title, component }) {
|
|
367
|
+
const { field, onAuthorize } = use(AuthFieldContext);
|
|
368
|
+
return /* @__PURE__ */ jsx(LinkRow, {
|
|
386
369
|
name: field.schemeId,
|
|
387
|
-
onClick: () =>
|
|
388
|
-
|
|
389
|
-
|
|
370
|
+
onClick: () => onAuthorize({
|
|
371
|
+
field,
|
|
372
|
+
component
|
|
373
|
+
}),
|
|
374
|
+
children: title
|
|
375
|
+
});
|
|
390
376
|
}
|
|
391
377
|
function BodySection({ body, renderBodyField, onNavigate }) {
|
|
392
378
|
const t = useTranslations({ note: "playground" });
|
|
@@ -4,7 +4,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from ".
|
|
|
4
4
|
import { Markdown } from "../../components/markdown.js";
|
|
5
5
|
import { ClientCodeBlock } from "../../components/codeblock.js";
|
|
6
6
|
import { cn } from "../../../utils/cn.js";
|
|
7
|
-
import { Segmented, SegmentedList, SegmentedPanel } from "
|
|
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";
|
|
10
10
|
import { useState } from "react";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ClientCodeBlock } from "../../components/codeblock.js";
|
|
3
3
|
import { cn } from "../../../utils/cn.js";
|
|
4
4
|
import { useStatusInfo } from "../status-info.js";
|
|
5
|
-
import { Segmented, SegmentedList, SegmentedPanel } from "
|
|
5
|
+
import { Segmented, SegmentedList, SegmentedPanel } from "../../components/segmented.js";
|
|
6
6
|
import { Fragment, useCallback, useMemo, useState } from "react";
|
|
7
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { useTranslations } from "@fuma-translate/react";
|
|
@@ -6,8 +6,8 @@ import { useRef, useState } from "react";
|
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { StfProvider, useFieldValue, useListener, useStf } from "@fumari/stf";
|
|
8
8
|
import { useTranslations } from "@fuma-translate/react";
|
|
9
|
-
import { Popover } from "@base-ui/react/popover";
|
|
10
9
|
import { Check, ChevronDown } from "lucide-react";
|
|
10
|
+
import { Popover } from "@base-ui/react/popover";
|
|
11
11
|
//#region src/ui/playground/components/server-select.tsx
|
|
12
12
|
/** the base URL of requests, selects the server and edits its variables */
|
|
13
13
|
function ServerSelect({ className }) {
|
|
@@ -4,8 +4,8 @@ import { defaultAdapters } from "../requests/media/adapter.js";
|
|
|
4
4
|
import { createCodeUsageGeneratorRegistry } from "../requests/generators/index.js";
|
|
5
5
|
import { registerDefault } from "../requests/generators/all.js";
|
|
6
6
|
import { createPageComponents, defaultShikiOptions } from "../packages/shared-api/dist/components/defaults.js";
|
|
7
|
-
import { AuthProvider } from "../playground/auth.js";
|
|
8
7
|
import { ServerProvider } from "./use-server.js";
|
|
8
|
+
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";
|
|
@@ -106,7 +106,7 @@ function OpenAPIProvider({ document, mediaAdapters, codeUsages, generateCodeSamp
|
|
|
106
106
|
children: /* @__PURE__ */ jsx(ServerProvider, {
|
|
107
107
|
servers: runtime.doc.dereferenced.servers,
|
|
108
108
|
storageKeyPrefix: runtime.storageKeyPrefix,
|
|
109
|
-
children: /* @__PURE__ */ jsx(
|
|
109
|
+
children: /* @__PURE__ */ jsx(PlaygroundAuthProvider, { children })
|
|
110
110
|
})
|
|
111
111
|
})
|
|
112
112
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getExampleValue, getPreferredType, pickExample } from "./schema.js";
|
|
2
1
|
import { encodeRequestData } from "../requests/media/encode.js";
|
|
2
|
+
import { getExampleValue, getPreferredType, pickExample } from "./schema.js";
|
|
3
3
|
import { getRaw } from "@scalar/json-magic/magic-proxy";
|
|
4
4
|
import { dereference, sample } from "@fumadocs/json-schema";
|
|
5
5
|
//#region src/utils/get-example-requests.ts
|