fumadocs-openapi 10.6.4 → 10.6.6
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 +34 -7
- package/dist/_openapi/types.d.ts +1 -2
- package/dist/generate-file.d.ts +1 -2
- package/dist/generate-file.js +3 -4
- package/dist/i18n.d.ts +2 -2
- package/dist/i18n.js +1 -2
- package/dist/playground/auth.js +92 -0
- package/dist/playground/client.d.ts +5 -10
- package/dist/playground/client.js +280 -199
- package/dist/playground/components/inputs.js +0 -2
- package/dist/playground/components/oauth-dialog.js +125 -164
- package/dist/playground/components/server-select.js +0 -2
- package/dist/playground/components/spinner.js +14 -0
- package/dist/playground/fetcher.d.ts +1 -2
- package/dist/playground/fetcher.js +0 -2
- package/dist/playground/schema.d.ts +1 -2
- package/dist/playground/schema.js +24 -15
- package/dist/playground/status-info.js +0 -2
- package/dist/requests/generators/all.d.ts +1 -2
- package/dist/requests/generators/all.js +0 -2
- package/dist/requests/generators/csharp.d.ts +1 -2
- package/dist/requests/generators/csharp.js +2 -3
- package/dist/requests/generators/curl.d.ts +1 -2
- package/dist/requests/generators/curl.js +5 -7
- package/dist/requests/generators/go.d.ts +1 -2
- package/dist/requests/generators/go.js +5 -7
- package/dist/requests/generators/index.d.ts +1 -2
- package/dist/requests/generators/index.js +0 -2
- package/dist/requests/generators/java.d.ts +1 -2
- package/dist/requests/generators/java.js +4 -6
- package/dist/requests/generators/javascript.d.ts +1 -2
- package/dist/requests/generators/javascript.js +3 -5
- package/dist/requests/generators/python.d.ts +1 -2
- package/dist/requests/generators/python.js +5 -6
- package/dist/requests/media/adapter.d.ts +1 -2
- package/dist/requests/media/adapter.js +7 -9
- package/dist/requests/media/encode.d.ts +1 -2
- package/dist/requests/media/encode.js +0 -2
- package/dist/requests/media/resolve-adapter.js +0 -2
- package/dist/requests/string-utils.js +25 -6
- package/dist/requests/types.d.ts +4 -4
- package/dist/scalar/client.js +0 -2
- package/dist/scalar/index.d.ts +1 -2
- package/dist/scalar/index.js +0 -2
- package/dist/server/create.d.ts +2 -3
- package/dist/server/create.js +0 -2
- package/dist/server/proxy.d.ts +1 -2
- package/dist/server/proxy.js +0 -2
- package/dist/server/source-api.d.ts +1 -2
- package/dist/server/source-api.js +0 -2
- package/dist/types.d.ts +1 -2
- package/dist/ui/api-page.d.ts +1 -2
- package/dist/ui/api-page.js +3 -3
- package/dist/ui/base.d.ts +9 -6
- package/dist/ui/base.js +8 -5
- package/dist/ui/client/boundary.d.ts +1 -2
- package/dist/ui/client/boundary.js +0 -2
- package/dist/ui/client/boundary.lazy.js +2 -3
- package/dist/ui/client/full.js +0 -2
- package/dist/ui/client/i18n.js +0 -2
- package/dist/ui/client/index.d.ts +1 -2
- package/dist/ui/client/index.js +0 -2
- package/dist/ui/client/storage-key.js +1 -3
- package/dist/ui/components/accordion.js +0 -2
- package/dist/ui/components/codeblock.d.ts +1 -2
- package/dist/ui/components/codeblock.js +0 -2
- package/dist/ui/components/dialog.js +0 -2
- package/dist/ui/components/input.js +0 -2
- package/dist/ui/components/method-label.js +0 -2
- package/dist/ui/components/select-tab.js +0 -2
- package/dist/ui/components/select.js +0 -2
- package/dist/ui/contexts/api.d.ts +7 -5
- package/dist/ui/contexts/api.js +7 -4
- package/dist/ui/create-client.d.ts +1 -2
- package/dist/ui/create-client.js +6 -3
- package/dist/ui/index.d.ts +1 -2
- package/dist/ui/index.js +0 -2
- package/dist/ui/operation/client.js +0 -2
- package/dist/ui/operation/get-example-requests.d.ts +1 -2
- package/dist/ui/operation/get-example-requests.js +0 -2
- package/dist/ui/operation/index.js +0 -2
- package/dist/ui/operation/request-tabs.d.ts +10 -0
- package/dist/ui/operation/request-tabs.js +43 -39
- package/dist/ui/operation/response-tabs.d.ts +1 -2
- package/dist/ui/operation/response-tabs.js +0 -2
- package/dist/ui/operation/usage-tabs/client.d.ts +1 -2
- package/dist/ui/operation/usage-tabs/client.js +0 -2
- package/dist/ui/operation/usage-tabs/index.js +0 -2
- package/dist/ui/schema/client.d.ts +1 -2
- package/dist/ui/schema/client.js +0 -2
- package/dist/ui/schema/index.d.ts +3 -4
- package/dist/ui/schema/index.js +1 -3
- package/dist/utils/deep-equal.js +0 -2
- package/dist/utils/document/dereference.d.ts +1 -2
- package/dist/utils/document/dereference.js +0 -2
- package/dist/utils/document/process.d.ts +1 -2
- package/dist/utils/document/process.js +0 -2
- package/dist/utils/id-to-title.js +0 -2
- package/dist/utils/is-plain-object.js +0 -2
- package/dist/utils/pages/builder.d.ts +1 -2
- package/dist/utils/pages/builder.js +0 -2
- package/dist/utils/pages/preset-auto.d.ts +1 -2
- package/dist/utils/pages/preset-auto.js +0 -2
- package/dist/utils/pages/to-static-data.js +0 -2
- package/dist/utils/pages/to-text.d.ts +1 -2
- package/dist/utils/pages/to-text.js +5 -6
- package/dist/utils/remove-undefined.js +0 -2
- package/dist/utils/schema/dereference.js +22 -14
- package/dist/utils/schema/index.d.ts +4 -10
- package/dist/utils/schema/index.js +4 -11
- package/dist/utils/{merge-schema.js → schema/merge.js} +2 -4
- package/dist/utils/schema/pick.js +0 -2
- package/dist/utils/schema/ref.js +0 -2
- package/dist/utils/schema/resolve-ref.js +0 -2
- package/dist/utils/schema/to-string.js +4 -7
- package/dist/utils/url.js +0 -2
- package/dist/utils/use-query.js +2 -3
- package/package.json +2 -2
- package/dist/_openapi/types.d.ts.map +0 -1
- package/dist/generate-file.d.ts.map +0 -1
- package/dist/generate-file.js.map +0 -1
- package/dist/i18n.d.ts.map +0 -1
- package/dist/i18n.js.map +0 -1
- package/dist/playground/client.d.ts.map +0 -1
- package/dist/playground/client.js.map +0 -1
- package/dist/playground/components/inputs.js.map +0 -1
- package/dist/playground/components/oauth-dialog.js.map +0 -1
- package/dist/playground/components/server-select.js.map +0 -1
- package/dist/playground/fetcher.d.ts.map +0 -1
- package/dist/playground/fetcher.js.map +0 -1
- package/dist/playground/schema.d.ts.map +0 -1
- package/dist/playground/schema.js.map +0 -1
- package/dist/playground/status-info.js.map +0 -1
- package/dist/requests/generators/all.d.ts.map +0 -1
- package/dist/requests/generators/all.js.map +0 -1
- package/dist/requests/generators/csharp.d.ts.map +0 -1
- package/dist/requests/generators/csharp.js.map +0 -1
- package/dist/requests/generators/curl.d.ts.map +0 -1
- package/dist/requests/generators/curl.js.map +0 -1
- package/dist/requests/generators/go.d.ts.map +0 -1
- package/dist/requests/generators/go.js.map +0 -1
- package/dist/requests/generators/index.d.ts.map +0 -1
- package/dist/requests/generators/index.js.map +0 -1
- package/dist/requests/generators/java.d.ts.map +0 -1
- package/dist/requests/generators/java.js.map +0 -1
- package/dist/requests/generators/javascript.d.ts.map +0 -1
- package/dist/requests/generators/javascript.js.map +0 -1
- package/dist/requests/generators/python.d.ts.map +0 -1
- package/dist/requests/generators/python.js.map +0 -1
- package/dist/requests/media/adapter.d.ts.map +0 -1
- package/dist/requests/media/adapter.js.map +0 -1
- package/dist/requests/media/encode.d.ts.map +0 -1
- package/dist/requests/media/encode.js.map +0 -1
- package/dist/requests/media/resolve-adapter.js.map +0 -1
- package/dist/requests/string-utils.js.map +0 -1
- package/dist/requests/types.d.ts.map +0 -1
- package/dist/scalar/client.js.map +0 -1
- package/dist/scalar/index.d.ts.map +0 -1
- package/dist/scalar/index.js.map +0 -1
- package/dist/server/create.d.ts.map +0 -1
- package/dist/server/create.js.map +0 -1
- package/dist/server/proxy.d.ts.map +0 -1
- package/dist/server/proxy.js.map +0 -1
- package/dist/server/source-api.d.ts.map +0 -1
- package/dist/server/source-api.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/ui/api-page.d.ts.map +0 -1
- package/dist/ui/api-page.js.map +0 -1
- package/dist/ui/base.d.ts.map +0 -1
- package/dist/ui/base.js.map +0 -1
- package/dist/ui/client/boundary.d.ts.map +0 -1
- package/dist/ui/client/boundary.js.map +0 -1
- package/dist/ui/client/boundary.lazy.js.map +0 -1
- package/dist/ui/client/full.js.map +0 -1
- package/dist/ui/client/i18n.js.map +0 -1
- package/dist/ui/client/index.d.ts.map +0 -1
- package/dist/ui/client/index.js.map +0 -1
- package/dist/ui/client/storage-key.js.map +0 -1
- package/dist/ui/components/accordion.js.map +0 -1
- package/dist/ui/components/codeblock.d.ts.map +0 -1
- package/dist/ui/components/codeblock.js.map +0 -1
- package/dist/ui/components/dialog.js.map +0 -1
- package/dist/ui/components/input.js.map +0 -1
- package/dist/ui/components/method-label.js.map +0 -1
- package/dist/ui/components/select-tab.js.map +0 -1
- package/dist/ui/components/select.js.map +0 -1
- package/dist/ui/contexts/api.d.ts.map +0 -1
- package/dist/ui/contexts/api.js.map +0 -1
- package/dist/ui/create-client.d.ts.map +0 -1
- package/dist/ui/create-client.js.map +0 -1
- package/dist/ui/index.d.ts.map +0 -1
- package/dist/ui/index.js.map +0 -1
- package/dist/ui/operation/client.js.map +0 -1
- package/dist/ui/operation/get-example-requests.d.ts.map +0 -1
- package/dist/ui/operation/get-example-requests.js.map +0 -1
- package/dist/ui/operation/index.js.map +0 -1
- package/dist/ui/operation/request-tabs.js.map +0 -1
- package/dist/ui/operation/response-tabs.d.ts.map +0 -1
- package/dist/ui/operation/response-tabs.js.map +0 -1
- package/dist/ui/operation/usage-tabs/client.d.ts.map +0 -1
- package/dist/ui/operation/usage-tabs/client.js.map +0 -1
- package/dist/ui/operation/usage-tabs/index.js.map +0 -1
- package/dist/ui/schema/client.d.ts.map +0 -1
- package/dist/ui/schema/client.js.map +0 -1
- package/dist/ui/schema/index.d.ts.map +0 -1
- package/dist/ui/schema/index.js.map +0 -1
- package/dist/utils/deep-equal.js.map +0 -1
- package/dist/utils/document/dereference.d.ts.map +0 -1
- package/dist/utils/document/dereference.js.map +0 -1
- package/dist/utils/document/process.d.ts.map +0 -1
- package/dist/utils/document/process.js.map +0 -1
- package/dist/utils/id-to-title.js.map +0 -1
- package/dist/utils/is-plain-object.js.map +0 -1
- package/dist/utils/merge-schema.js.map +0 -1
- package/dist/utils/pages/builder.d.ts.map +0 -1
- package/dist/utils/pages/builder.js.map +0 -1
- package/dist/utils/pages/preset-auto.d.ts.map +0 -1
- package/dist/utils/pages/preset-auto.js.map +0 -1
- package/dist/utils/pages/to-static-data.js.map +0 -1
- package/dist/utils/pages/to-text.d.ts.map +0 -1
- package/dist/utils/pages/to-text.js.map +0 -1
- package/dist/utils/remove-undefined.js.map +0 -1
- package/dist/utils/schema/dereference.js.map +0 -1
- package/dist/utils/schema/index.d.ts.map +0 -1
- package/dist/utils/schema/index.js.map +0 -1
- package/dist/utils/schema/pick.js.map +0 -1
- package/dist/utils/schema/ref.js.map +0 -1
- package/dist/utils/schema/resolve-ref.js.map +0 -1
- package/dist/utils/schema/to-string.js.map +0 -1
- package/dist/utils/url.js.map +0 -1
- package/dist/utils/use-query.js.map +0 -1
|
@@ -1,15 +1,26 @@
|
|
|
1
|
+
import { useApiContext } from "../../ui/contexts/api.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
3
|
import { useQuery } from "../../utils/use-query.js";
|
|
3
4
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../ui/components/select.js";
|
|
4
5
|
import { Input, labelVariants } from "../../ui/components/input.js";
|
|
5
6
|
import { useTranslations } from "../../ui/client/i18n.js";
|
|
6
7
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "../../ui/components/dialog.js";
|
|
7
|
-
import {
|
|
8
|
+
import { useAuth } from "../auth.js";
|
|
9
|
+
import { useMemo, useState } from "react";
|
|
8
10
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
11
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
10
12
|
import { useForm } from "react-hook-form";
|
|
11
13
|
//#region src/playground/components/oauth-dialog.tsx
|
|
12
|
-
|
|
14
|
+
const OAuthDialog = Dialog;
|
|
15
|
+
function OAuthDialogContent(props) {
|
|
16
|
+
const t = useTranslations();
|
|
17
|
+
return /* @__PURE__ */ jsxs(DialogContent, { children: [/* @__PURE__ */ jsxs(DialogHeader, { children: [/* @__PURE__ */ jsx(DialogTitle, { children: t.authorization }), /* @__PURE__ */ jsx(DialogDescription, { children: t.obtainAccessToken })] }), /* @__PURE__ */ jsx(Content, { ...props })] });
|
|
18
|
+
}
|
|
19
|
+
function Content({ schemeId, scopes, setToken, setOpen }) {
|
|
20
|
+
const { schemes } = useApiContext();
|
|
21
|
+
const tokenInfo = useAuth().store[schemeId];
|
|
22
|
+
const scheme = schemes[schemeId];
|
|
23
|
+
if (!scheme || scheme.type !== "oauth2") throw new Error("unexpected schemaId: must be type oauth2");
|
|
13
24
|
const [type, setType] = useState(() => {
|
|
14
25
|
return Object.keys(scheme.flows)[0];
|
|
15
26
|
});
|
|
@@ -41,58 +52,14 @@ function OauthDialog({ scheme, scopes, setToken, children, open, setOpen }) {
|
|
|
41
52
|
supported: false
|
|
42
53
|
}
|
|
43
54
|
}), [t]);
|
|
44
|
-
const form = useForm({ defaultValues: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const res = await fetch(value.tokenUrl, {
|
|
53
|
-
method: "POST",
|
|
54
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
55
|
-
body: new URLSearchParams({
|
|
56
|
-
grant_type: "authorization_code",
|
|
57
|
-
code,
|
|
58
|
-
redirect_uri: state.redirect_uri,
|
|
59
|
-
client_id: state.client_id,
|
|
60
|
-
client_secret: state.client_secret
|
|
61
|
-
})
|
|
62
|
-
});
|
|
63
|
-
if (!res.ok) throw new Error(await res.text());
|
|
64
|
-
const { access_token, token_type = "Bearer" } = await res.json();
|
|
65
|
-
setToken(`${token_type} ${access_token}`);
|
|
66
|
-
setOpen(false);
|
|
67
|
-
});
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
if (scheme.flows.authorizationCode) {
|
|
70
|
-
const params = new URLSearchParams(window.location.search);
|
|
71
|
-
const state = params.get("state");
|
|
72
|
-
const code = params.get("code");
|
|
73
|
-
if (state && code) {
|
|
74
|
-
const parsedState = JSON.parse(state);
|
|
75
|
-
setOpen(true);
|
|
76
|
-
form.setValue("clientId", parsedState.client_id);
|
|
77
|
-
form.setValue("clientSecret", parsedState.client_secret);
|
|
78
|
-
authCodeCallback.start(code, parsedState);
|
|
79
|
-
window.history.replaceState(null, "", window.location.pathname);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (scheme.flows.implicit && window.location.hash.length > 1) {
|
|
84
|
-
const params = new URLSearchParams(window.location.hash.slice(1));
|
|
85
|
-
const state = params.get("state");
|
|
86
|
-
const token = params.get("access_token");
|
|
87
|
-
const type = params.get("token_type") ?? "Bearer";
|
|
88
|
-
if (state && token) {
|
|
89
|
-
const parsedState = JSON.parse(state);
|
|
90
|
-
form.setValue("clientId", parsedState.client_id);
|
|
91
|
-
setToken(`${type} ${token}`);
|
|
92
|
-
window.history.replaceState(null, "", window.location.pathname);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}, []);
|
|
55
|
+
const form = useForm({ defaultValues: useMemo(() => {
|
|
56
|
+
return {
|
|
57
|
+
clientId: tokenInfo?.client_id ?? "",
|
|
58
|
+
clientSecret: tokenInfo?.type === "authorization_code" ? tokenInfo.client_secret : "",
|
|
59
|
+
username: "",
|
|
60
|
+
password: ""
|
|
61
|
+
};
|
|
62
|
+
}, [tokenInfo]) });
|
|
96
63
|
const authorize = useQuery(async (values) => {
|
|
97
64
|
if (type === "implicit") {
|
|
98
65
|
const value = scheme.flows[type];
|
|
@@ -102,6 +69,7 @@ function OauthDialog({ scheme, scopes, setToken, children, open, setOpen }) {
|
|
|
102
69
|
params.set("redirect_uri", window.location.href);
|
|
103
70
|
params.set("scope", scopes.join("+"));
|
|
104
71
|
params.set("state", JSON.stringify({
|
|
72
|
+
scheme: schemeId,
|
|
105
73
|
client_id: values.clientId,
|
|
106
74
|
redirect_uri: window.location.href
|
|
107
75
|
}));
|
|
@@ -118,7 +86,8 @@ function OauthDialog({ scheme, scopes, setToken, children, open, setOpen }) {
|
|
|
118
86
|
params.set("state", JSON.stringify({
|
|
119
87
|
client_id: values.clientId,
|
|
120
88
|
client_secret: values.clientSecret,
|
|
121
|
-
redirect_uri: window.location.href
|
|
89
|
+
redirect_uri: window.location.href,
|
|
90
|
+
scheme: schemeId
|
|
122
91
|
}));
|
|
123
92
|
window.location.replace(`${value.authorizationUrl}?${params.toString()}`);
|
|
124
93
|
return;
|
|
@@ -157,129 +126,121 @@ function OauthDialog({ scheme, scopes, setToken, children, open, setOpen }) {
|
|
|
157
126
|
setOpen(false);
|
|
158
127
|
}
|
|
159
128
|
});
|
|
129
|
+
const isLoading = authorize.isLoading;
|
|
160
130
|
const onSubmit = form.handleSubmit((values) => {
|
|
161
131
|
return authorize.start(values);
|
|
162
132
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
children:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
(type === "authorizationCode" || type === "clientCredentials" || type === "implicit") && /* @__PURE__ */ jsxs("fieldset", {
|
|
193
|
-
className: "flex flex-col gap-1.5",
|
|
194
|
-
children: [
|
|
195
|
-
/* @__PURE__ */ jsx("label", {
|
|
196
|
-
htmlFor: "client_id",
|
|
197
|
-
className: cn(labelVariants()),
|
|
198
|
-
children: t.clientId
|
|
199
|
-
}),
|
|
200
|
-
/* @__PURE__ */ jsx("p", {
|
|
201
|
-
className: "text-fd-muted-foreground text-sm",
|
|
202
|
-
children: t.clientIdHint
|
|
203
|
-
}),
|
|
204
|
-
/* @__PURE__ */ jsx(Input, {
|
|
205
|
-
id: "client_id",
|
|
206
|
-
placeholder: t.inputPlaceholder,
|
|
207
|
-
type: "text",
|
|
208
|
-
autoComplete: "off",
|
|
209
|
-
disabled: isLoading,
|
|
210
|
-
...form.register("clientId", { required: true })
|
|
211
|
-
})
|
|
212
|
-
]
|
|
213
|
-
}),
|
|
214
|
-
(type === "authorizationCode" || type === "clientCredentials") && /* @__PURE__ */ jsxs("fieldset", {
|
|
215
|
-
className: "flex flex-col gap-1.5",
|
|
216
|
-
children: [
|
|
217
|
-
/* @__PURE__ */ jsx("label", {
|
|
218
|
-
htmlFor: "client_secret",
|
|
219
|
-
className: cn(labelVariants()),
|
|
220
|
-
children: t.clientSecret
|
|
221
|
-
}),
|
|
222
|
-
/* @__PURE__ */ jsx("p", {
|
|
223
|
-
className: "text-fd-muted-foreground text-sm",
|
|
224
|
-
children: t.clientSecretHint
|
|
225
|
-
}),
|
|
226
|
-
/* @__PURE__ */ jsx(Input, {
|
|
227
|
-
id: "client_secret",
|
|
228
|
-
placeholder: t.inputPlaceholder,
|
|
229
|
-
type: "password",
|
|
230
|
-
autoComplete: "off",
|
|
231
|
-
disabled: isLoading,
|
|
232
|
-
...form.register("clientSecret", { required: true })
|
|
233
|
-
})
|
|
234
|
-
]
|
|
235
|
-
}),
|
|
236
|
-
type === "password" && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("fieldset", {
|
|
237
|
-
className: "flex flex-col gap-1.5",
|
|
238
|
-
children: [/* @__PURE__ */ jsx("label", {
|
|
239
|
-
htmlFor: "username",
|
|
133
|
+
return /* @__PURE__ */ jsxs("form", {
|
|
134
|
+
className: "flex flex-col gap-6",
|
|
135
|
+
onSubmit: (e) => {
|
|
136
|
+
onSubmit(e);
|
|
137
|
+
e.stopPropagation();
|
|
138
|
+
},
|
|
139
|
+
children: [
|
|
140
|
+
/* @__PURE__ */ jsxs(Select, {
|
|
141
|
+
value: type ?? "",
|
|
142
|
+
onValueChange: setType,
|
|
143
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Select a flow" }) }), /* @__PURE__ */ jsx(SelectContent, { children: Object.keys(scheme.flows).map((key) => {
|
|
144
|
+
const { name, description } = allFlows[key];
|
|
145
|
+
return /* @__PURE__ */ jsxs(SelectItem, {
|
|
146
|
+
value: key,
|
|
147
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
148
|
+
className: "font-medium",
|
|
149
|
+
children: name
|
|
150
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
151
|
+
className: "text-fd-muted-foreground",
|
|
152
|
+
children: description
|
|
153
|
+
})]
|
|
154
|
+
}, key);
|
|
155
|
+
}) })]
|
|
156
|
+
}),
|
|
157
|
+
(type === "authorizationCode" || type === "clientCredentials" || type === "implicit") && /* @__PURE__ */ jsxs("fieldset", {
|
|
158
|
+
className: "flex flex-col gap-1.5",
|
|
159
|
+
children: [
|
|
160
|
+
/* @__PURE__ */ jsx("label", {
|
|
161
|
+
htmlFor: "client_id",
|
|
240
162
|
className: cn(labelVariants()),
|
|
241
|
-
children: t.
|
|
242
|
-
}),
|
|
243
|
-
|
|
163
|
+
children: t.clientId
|
|
164
|
+
}),
|
|
165
|
+
/* @__PURE__ */ jsx("p", {
|
|
166
|
+
className: "text-fd-muted-foreground text-sm",
|
|
167
|
+
children: t.clientIdHint
|
|
168
|
+
}),
|
|
169
|
+
/* @__PURE__ */ jsx(Input, {
|
|
170
|
+
id: "client_id",
|
|
244
171
|
placeholder: t.inputPlaceholder,
|
|
245
172
|
type: "text",
|
|
246
|
-
disabled: isLoading,
|
|
247
173
|
autoComplete: "off",
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
174
|
+
disabled: isLoading,
|
|
175
|
+
...form.register("clientId", { required: true })
|
|
176
|
+
})
|
|
177
|
+
]
|
|
178
|
+
}),
|
|
179
|
+
(type === "authorizationCode" || type === "clientCredentials") && /* @__PURE__ */ jsxs("fieldset", {
|
|
180
|
+
className: "flex flex-col gap-1.5",
|
|
181
|
+
children: [
|
|
182
|
+
/* @__PURE__ */ jsx("label", {
|
|
183
|
+
htmlFor: "client_secret",
|
|
254
184
|
className: cn(labelVariants()),
|
|
255
185
|
children: t.clientSecret
|
|
256
|
-
}),
|
|
257
|
-
|
|
186
|
+
}),
|
|
187
|
+
/* @__PURE__ */ jsx("p", {
|
|
188
|
+
className: "text-fd-muted-foreground text-sm",
|
|
189
|
+
children: t.clientSecretHint
|
|
190
|
+
}),
|
|
191
|
+
/* @__PURE__ */ jsx(Input, {
|
|
192
|
+
id: "client_secret",
|
|
258
193
|
placeholder: t.inputPlaceholder,
|
|
259
194
|
type: "password",
|
|
260
195
|
autoComplete: "off",
|
|
261
196
|
disabled: isLoading,
|
|
262
|
-
...form.register("
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
197
|
+
...form.register("clientSecret", { required: true })
|
|
198
|
+
})
|
|
199
|
+
]
|
|
200
|
+
}),
|
|
201
|
+
type === "password" && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("fieldset", {
|
|
202
|
+
className: "flex flex-col gap-1.5",
|
|
203
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
204
|
+
htmlFor: "username",
|
|
205
|
+
className: cn(labelVariants()),
|
|
206
|
+
children: t.usernameField
|
|
207
|
+
}), /* @__PURE__ */ jsx(Input, {
|
|
208
|
+
id: "username",
|
|
209
|
+
placeholder: t.inputPlaceholder,
|
|
210
|
+
type: "text",
|
|
211
|
+
autoComplete: "off",
|
|
270
212
|
disabled: isLoading,
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
213
|
+
...form.register("username", { required: true })
|
|
214
|
+
})]
|
|
215
|
+
}), /* @__PURE__ */ jsxs("fieldset", {
|
|
216
|
+
className: "flex flex-col gap-1.5",
|
|
217
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
218
|
+
htmlFor: "password",
|
|
219
|
+
className: cn(labelVariants()),
|
|
220
|
+
children: t.clientSecret
|
|
221
|
+
}), /* @__PURE__ */ jsx(Input, {
|
|
222
|
+
id: "password",
|
|
223
|
+
placeholder: t.inputPlaceholder,
|
|
224
|
+
type: "password",
|
|
225
|
+
autoComplete: "off",
|
|
226
|
+
disabled: isLoading,
|
|
227
|
+
...form.register("password", { required: true })
|
|
228
|
+
})]
|
|
229
|
+
})] }),
|
|
230
|
+
type && allFlows[type].supported ? /* @__PURE__ */ jsxs(Fragment$1, { children: [authorize.error ? /* @__PURE__ */ jsx("p", {
|
|
231
|
+
className: "text-red-400 font-medium text-sm",
|
|
232
|
+
children: String(authorize.error)
|
|
233
|
+
}) : null, /* @__PURE__ */ jsx("button", {
|
|
234
|
+
type: "submit",
|
|
235
|
+
className: cn(buttonVariants({ color: "primary" })),
|
|
236
|
+
children: t.submit
|
|
237
|
+
})] }) : /* @__PURE__ */ jsx("p", {
|
|
238
|
+
className: "text-fd-muted-foreground bg-fd-muted p-2 rounded-lg border",
|
|
239
|
+
children: t.unsupported
|
|
240
|
+
})
|
|
241
|
+
]
|
|
279
242
|
});
|
|
280
243
|
}
|
|
281
|
-
const
|
|
244
|
+
const OAuthDialogTrigger = DialogTrigger;
|
|
282
245
|
//#endregion
|
|
283
|
-
export {
|
|
284
|
-
|
|
285
|
-
//# sourceMappingURL=oauth-dialog.js.map
|
|
246
|
+
export { OAuthDialog, OAuthDialogContent, OAuthDialogTrigger };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Loader2Icon } from "lucide-react";
|
|
4
|
+
//#region src/playground/components/spinner.tsx
|
|
5
|
+
function Spinner({ className, ...props }) {
|
|
6
|
+
return /* @__PURE__ */ jsx(Loader2Icon, {
|
|
7
|
+
role: "status",
|
|
8
|
+
"aria-label": "Loading",
|
|
9
|
+
className: cn("size-4 animate-spin", className),
|
|
10
|
+
...props
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { Spinner };
|
|
@@ -24,5 +24,4 @@ interface BrowserFetcherOptions {
|
|
|
24
24
|
onRequestInit?: (requestInit: RequestInit) => Awaitable<RequestInit>;
|
|
25
25
|
}
|
|
26
26
|
//#endregion
|
|
27
|
-
export { BrowserFetcherOptions, FetchResult };
|
|
28
|
-
//# sourceMappingURL=fetcher.d.ts.map
|
|
27
|
+
export { BrowserFetcherOptions, FetchResult };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { mergeAllOf } from "../utils/merge
|
|
1
|
+
import { mergeAllOf } from "../utils/schema/merge.js";
|
|
2
2
|
import { schemaToString } from "../utils/schema/to-string.js";
|
|
3
|
+
import { dereferenceSwallow } from "../utils/schema/dereference.js";
|
|
3
4
|
import { createContext, use, useMemo } from "react";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
@@ -19,7 +20,7 @@ const anyFields = {
|
|
|
19
20
|
items: true,
|
|
20
21
|
additionalProperties: true
|
|
21
22
|
};
|
|
22
|
-
function SchemaProvider({
|
|
23
|
+
function SchemaProvider({ doc, readOnly, writeOnly, children }) {
|
|
23
24
|
const ajv = useMemo(() => new Ajv2020({
|
|
24
25
|
strict: false,
|
|
25
26
|
validateSchema: false,
|
|
@@ -27,12 +28,12 @@ function SchemaProvider({ schema, readOnly, writeOnly, children }) {
|
|
|
27
28
|
}), []);
|
|
28
29
|
return /* @__PURE__ */ jsx(SchemaContext.Provider, {
|
|
29
30
|
value: useMemo(() => ({
|
|
30
|
-
|
|
31
|
+
doc,
|
|
31
32
|
ajv,
|
|
32
33
|
readOnly,
|
|
33
34
|
writeOnly
|
|
34
35
|
}), [
|
|
35
|
-
|
|
36
|
+
doc,
|
|
36
37
|
ajv,
|
|
37
38
|
readOnly,
|
|
38
39
|
writeOnly
|
|
@@ -51,7 +52,7 @@ function useSchemaScope() {
|
|
|
51
52
|
* @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).
|
|
52
53
|
*/
|
|
53
54
|
function useFieldInfo(fieldName, schema, depth = 0) {
|
|
54
|
-
const { ajv } = use(SchemaContext);
|
|
55
|
+
const { ajv, doc } = use(SchemaContext);
|
|
55
56
|
const engine = useDataEngine();
|
|
56
57
|
const { generateDefault } = useSchemaUtils();
|
|
57
58
|
const [info, setInfo] = useFieldValue([], { stf: useNamespace({
|
|
@@ -62,7 +63,10 @@ function useFieldInfo(fieldName, schema, depth = 0) {
|
|
|
62
63
|
const union = getUnion(schema);
|
|
63
64
|
if (union) {
|
|
64
65
|
const [members, field] = union;
|
|
65
|
-
out.oneOf = members.findIndex((item) => ajv.validate(
|
|
66
|
+
out.oneOf = members.findIndex((item) => typeof item === "object" && ajv.validate({
|
|
67
|
+
...doc,
|
|
68
|
+
...item
|
|
69
|
+
}, value));
|
|
66
70
|
if (out.oneOf === -1) out.oneOf = 0;
|
|
67
71
|
out.unionField = field;
|
|
68
72
|
}
|
|
@@ -70,6 +74,7 @@ function useFieldInfo(fieldName, schema, depth = 0) {
|
|
|
70
74
|
const types = schema.type;
|
|
71
75
|
out.selectedType = types.find((type) => {
|
|
72
76
|
return ajv.validate({
|
|
77
|
+
...doc,
|
|
73
78
|
...schema,
|
|
74
79
|
type
|
|
75
80
|
}, value);
|
|
@@ -100,29 +105,35 @@ function useFieldInfo(fieldName, schema, depth = 0) {
|
|
|
100
105
|
};
|
|
101
106
|
}
|
|
102
107
|
function useSchemaUtils() {
|
|
103
|
-
const {
|
|
108
|
+
const { doc, readOnly } = use(SchemaContext);
|
|
104
109
|
return {
|
|
105
110
|
generateDefault(schema) {
|
|
106
111
|
return sample(schema, {
|
|
107
112
|
skipNonRequired: true,
|
|
108
113
|
skipReadOnly: !readOnly,
|
|
109
114
|
quiet: true
|
|
110
|
-
});
|
|
115
|
+
}, doc);
|
|
111
116
|
},
|
|
112
117
|
schemaToString(value, flags) {
|
|
113
|
-
return schemaToString(value,
|
|
118
|
+
return schemaToString(value, (raw) => ({
|
|
119
|
+
raw,
|
|
120
|
+
dereferenced: dereferenceSwallow(raw, doc)
|
|
121
|
+
}), flags);
|
|
114
122
|
}
|
|
115
123
|
};
|
|
116
124
|
}
|
|
117
125
|
/**
|
|
118
|
-
* merge `allOf`.
|
|
126
|
+
* dereference & merge `allOf`.
|
|
119
127
|
*/
|
|
120
128
|
function useResolvedSchema(raw) {
|
|
129
|
+
const { doc } = use(SchemaContext);
|
|
121
130
|
return useMemo(() => {
|
|
122
|
-
let out = raw;
|
|
123
|
-
if (typeof out === "object" && out.allOf) out = mergeAllOf(out)
|
|
131
|
+
let out = dereferenceSwallow(raw, doc);
|
|
132
|
+
if (typeof out === "object" && out.allOf) out = mergeAllOf(out, { dereference(schema) {
|
|
133
|
+
return dereferenceSwallow(schema, doc);
|
|
134
|
+
} });
|
|
124
135
|
return typeof out === "boolean" ? anyFields : out;
|
|
125
|
-
}, [raw]);
|
|
136
|
+
}, [doc, raw]);
|
|
126
137
|
}
|
|
127
138
|
function getUnion(schema) {
|
|
128
139
|
if (schema.anyOf) return [schema.anyOf, "anyOf"];
|
|
@@ -130,5 +141,3 @@ function getUnion(schema) {
|
|
|
130
141
|
}
|
|
131
142
|
//#endregion
|
|
132
143
|
export { SchemaProvider, anyFields, useFieldInfo, useResolvedSchema, useSchemaScope, useSchemaUtils };
|
|
133
|
-
|
|
134
|
-
//# sourceMappingURL=schema.js.map
|
|
@@ -3,5 +3,4 @@ import { CodeUsageGeneratorRegistry } from "./index.js";
|
|
|
3
3
|
//#region src/requests/generators/all.d.ts
|
|
4
4
|
declare function registerDefault(registry: CodeUsageGeneratorRegistry): void;
|
|
5
5
|
//#endregion
|
|
6
|
-
export { registerDefault };
|
|
7
|
-
//# sourceMappingURL=all.d.ts.map
|
|
6
|
+
export { registerDefault };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { doubleQuote } from "../string-utils.js";
|
|
1
2
|
import { resolveMediaAdapter } from "../media/resolve-adapter.js";
|
|
2
3
|
import "../media/adapter.js";
|
|
3
4
|
//#region src/requests/generators/csharp.ts
|
|
@@ -25,7 +26,7 @@ const csharp = {
|
|
|
25
26
|
s.push("var client = new HttpClient();");
|
|
26
27
|
const headerLines = [];
|
|
27
28
|
function addHeader(key, value) {
|
|
28
|
-
headerLines.push(`client.DefaultRequestHeaders.Add("${key}", ${
|
|
29
|
+
headerLines.push(`client.DefaultRequestHeaders.Add("${key}", ${doubleQuote(value)});`);
|
|
29
30
|
}
|
|
30
31
|
for (const k in headers) addHeader(k, headers[k].value);
|
|
31
32
|
if (Object.keys(data.cookie).length > 0) addHeader("cookie", Object.entries(data.cookie).map(([key, param]) => `${key}=${param.value}`).join("; "));
|
|
@@ -39,5 +40,3 @@ const csharp = {
|
|
|
39
40
|
};
|
|
40
41
|
//#endregion
|
|
41
42
|
export { csharp };
|
|
42
|
-
|
|
43
|
-
//# sourceMappingURL=csharp.js.map
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { doubleQuote, indent, inputToString, singleQuote } from "../string-utils.js";
|
|
2
2
|
//#region src/requests/generators/curl.ts
|
|
3
3
|
const curl = {
|
|
4
4
|
label: "cURL",
|
|
5
5
|
lang: "bash",
|
|
6
6
|
generate(url, data) {
|
|
7
7
|
const s = [];
|
|
8
|
-
s.push(`curl -X ${data.method} "${url}"`);
|
|
8
|
+
s.push(`curl -X ${data.method.toUpperCase()} "${url}"`);
|
|
9
9
|
for (const header in data.header) {
|
|
10
10
|
const value = `${header}: ${data.header[header].value}`;
|
|
11
11
|
s.push(`-H "${value}"`);
|
|
12
12
|
}
|
|
13
13
|
for (const k in data.cookie) {
|
|
14
14
|
const param = data.cookie[k];
|
|
15
|
-
s.push(`--cookie ${
|
|
15
|
+
s.push(`--cookie ${doubleQuote(`${k}=${param.value}`)}`);
|
|
16
16
|
}
|
|
17
17
|
if (data.body && data.bodyMediaType === "multipart/form-data") {
|
|
18
18
|
if (typeof data.body !== "object") throw new Error("[CURL] request body must be an object.");
|
|
19
|
-
for (const [key, value] of Object.entries(data.body)) s.push(`-F ${key}=${
|
|
19
|
+
for (const [key, value] of Object.entries(data.body)) s.push(`-F ${key}=${doubleQuote(inputToString(value))}`);
|
|
20
20
|
} else if (data.body && data.bodyMediaType) {
|
|
21
|
-
const escaped =
|
|
21
|
+
const escaped = singleQuote(inputToString(data.body, data.bodyMediaType));
|
|
22
22
|
s.push(`-H "Content-Type: ${data.bodyMediaType}"`);
|
|
23
23
|
s.push(`-d ${escaped}`);
|
|
24
24
|
}
|
|
@@ -27,5 +27,3 @@ const curl = {
|
|
|
27
27
|
};
|
|
28
28
|
//#endregion
|
|
29
29
|
export { curl };
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=curl.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { indent } from "../string-utils.js";
|
|
1
|
+
import { doubleQuote, indent } from "../string-utils.js";
|
|
2
2
|
import { resolveMediaAdapter } from "../media/resolve-adapter.js";
|
|
3
3
|
import "../media/adapter.js";
|
|
4
4
|
//#region src/requests/generators/go.ts
|
|
@@ -13,10 +13,10 @@ const go = {
|
|
|
13
13
|
];
|
|
14
14
|
const headers = /* @__PURE__ */ new Map();
|
|
15
15
|
const variables = /* @__PURE__ */ new Map();
|
|
16
|
-
variables.set("url",
|
|
17
|
-
for (const header in data.header) headers.set(header,
|
|
16
|
+
variables.set("url", doubleQuote(url));
|
|
17
|
+
for (const header in data.header) headers.set(header, doubleQuote(data.header[header].value));
|
|
18
18
|
const cookies = Object.entries(data.cookie);
|
|
19
|
-
if (cookies.length > 0) headers.set("Cookie",
|
|
19
|
+
if (cookies.length > 0) headers.set("Cookie", doubleQuote(cookies.map(([k, param]) => `${k}=${param.value}`).join("; ")));
|
|
20
20
|
let body;
|
|
21
21
|
if (data.body && data.bodyMediaType) {
|
|
22
22
|
const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);
|
|
@@ -37,7 +37,7 @@ ${indent(imports.map((v) => `"${v}"`).join("\n"))}
|
|
|
37
37
|
func main() {
|
|
38
38
|
${Array.from(variables.entries()).map(([k, v]) => indent(`${k} := ${v}`)).join("\n")}
|
|
39
39
|
${body ? indent(body) : ""}
|
|
40
|
-
req, _ := http.NewRequest("${data.method}", url, ${body ? "body" : "nil"})
|
|
40
|
+
req, _ := http.NewRequest("${data.method.toUpperCase()}", url, ${body ? "body" : "nil"})
|
|
41
41
|
${indent(Array.from(headers.entries()).map(([key, value]) => `req.Header.Add("${key}", ${value})`).join("\n"))}
|
|
42
42
|
res, _ := http.DefaultClient.Do(req)
|
|
43
43
|
defer res.Body.Close()
|
|
@@ -50,5 +50,3 @@ ${indent(Array.from(headers.entries()).map(([key, value]) => `req.Header.Add("${
|
|
|
50
50
|
};
|
|
51
51
|
//#endregion
|
|
52
52
|
export { go };
|
|
53
|
-
|
|
54
|
-
//# sourceMappingURL=go.js.map
|
|
@@ -52,5 +52,4 @@ type CodeUsageGeneratorFn<ServerContext = unknown> = (url: string, data: Request
|
|
|
52
52
|
server: ServerContext;
|
|
53
53
|
}) => string;
|
|
54
54
|
//#endregion
|
|
55
|
-
export { CodeUsageGenerator, CodeUsageGeneratorFn, CodeUsageGeneratorRegistry, InlineCodeUsageGenerator, createCodeUsageGeneratorRegistry };
|
|
56
|
-
//# sourceMappingURL=index.d.ts.map
|
|
55
|
+
export { CodeUsageGenerator, CodeUsageGeneratorFn, CodeUsageGeneratorRegistry, InlineCodeUsageGenerator, createCodeUsageGeneratorRegistry };
|