fumadocs-openapi 12.1.1 → 12.3.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 +63 -20
- package/dist/.translations/keys.js +63 -20
- package/dist/operation.d.ts +6 -1
- package/dist/operation.js +2 -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 +2 -2
- 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/packages/shared-api/dist/components/select.js +8 -7
- package/dist/playground/auth.d.ts +5 -1
- package/dist/playground/auth.js +7 -2
- package/dist/playground/fetcher.d.ts +8 -0
- package/dist/playground/fetcher.js +30 -1
- package/dist/playground/index.d.ts +2 -1
- package/dist/playground/index.js +2 -1
- package/dist/playground/use-playground.d.ts +62 -0
- package/dist/playground/use-playground.js +140 -0
- package/dist/ui/components/dialog.js +14 -0
- package/dist/ui/components/endpoint.js +40 -0
- package/dist/ui/components/heading.js +1 -1
- package/dist/ui/components/schema.js +1 -1
- package/dist/ui/components/segmented.js +21 -0
- package/dist/ui/operation/index.js +267 -250
- package/dist/ui/playground/client.d.ts +9 -26
- package/dist/ui/playground/client.js +150 -389
- package/dist/ui/playground/components/fields.js +693 -0
- package/dist/ui/playground/components/oauth-panel.js +182 -0
- package/dist/ui/playground/components/request-panel.js +480 -0
- package/dist/ui/playground/components/response-panel.js +150 -0
- package/dist/ui/playground/components/result-display.d.ts +1 -0
- package/dist/ui/playground/components/result-display.js +185 -168
- package/dist/ui/playground/components/server-select.js +100 -89
- package/dist/ui/playground/components/url-bar.js +96 -0
- package/dist/ui/playground/status-info.js +32 -45
- package/dist/utils/document/load.js +1 -1
- package/package.json +12 -12
- package/dist/packages/shared-api/dist/auto-anchor/client.js +0 -20
- package/dist/packages/shared-api/dist/components/collapsible.d.ts +0 -7
- package/dist/packages/shared-api/dist/components/dialog.js +0 -55
- package/dist/packages/shared-api/dist/components/input.js +0 -14
- package/dist/packages/shared-api/dist/components/label.js +0 -11
- package/dist/packages/shared-api/dist/components/playground/inputs.js +0 -439
- package/dist/packages/shared-api/dist/components/popover.js +0 -23
- package/dist/packages/shared-api/dist/utils/merge-refs.js +0 -11
- package/dist/ui/playground/components/oauth-dialog.js +0 -259
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import { useQuery } from "../../../packages/shared-api/dist/utils/use-query.js";
|
|
2
|
-
import { requestOAuthToken, usePlaygroundAuth } from "../../../playground/auth.js";
|
|
3
|
-
import { useServer } from "../../../utils/use-server.js";
|
|
4
|
-
import { useOpenAPI } from "../../../utils/create-page.js";
|
|
5
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
6
|
-
import { cn } from "../../../utils/cn.js";
|
|
7
|
-
import { Label } from "../../../packages/shared-api/dist/components/label.js";
|
|
8
|
-
import { Input } from "../../../packages/shared-api/dist/components/input.js";
|
|
9
|
-
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "../../../packages/shared-api/dist/components/dialog.js";
|
|
10
|
-
import { useMemo, useState } from "react";
|
|
11
|
-
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
-
import { useTranslations } from "@fuma-translate/react";
|
|
13
|
-
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
14
|
-
//#region src/ui/playground/components/oauth-dialog.tsx
|
|
15
|
-
const OAuthDialog = Dialog;
|
|
16
|
-
function OAuthDialogContent(props) {
|
|
17
|
-
const t = useTranslations({ note: "OAuth dialog" });
|
|
18
|
-
return /* @__PURE__ */ jsxs(DialogContent, { children: [/* @__PURE__ */ jsxs(DialogHeader, { children: [/* @__PURE__ */ jsx(DialogTitle, { children: t("Authorization") }), /* @__PURE__ */ jsx(DialogDescription, { children: t("Obtain the access token for API.") })] }), /* @__PURE__ */ jsx(Content, { ...props })] });
|
|
19
|
-
}
|
|
20
|
-
function Content({ schemeId, scopes, setToken, setOpen }) {
|
|
21
|
-
const { doc, oauthRedirectUrl } = useOpenAPI();
|
|
22
|
-
const { dereferenced, resolve } = doc;
|
|
23
|
-
const schemes = dereferenced.components?.securitySchemes;
|
|
24
|
-
const tokenInfo = usePlaygroundAuth().store[schemeId];
|
|
25
|
-
const { resolveUrl } = useServer();
|
|
26
|
-
const scheme = resolve(schemes?.[schemeId]);
|
|
27
|
-
if (!scheme || scheme.type !== "oauth2") throw new Error("unexpected schemaId: must be type oauth2");
|
|
28
|
-
const [type, setType] = useState(() => {
|
|
29
|
-
return Object.keys(scheme.flows)[0];
|
|
30
|
-
});
|
|
31
|
-
const [clientAuth, setClientAuth] = useState(() => tokenInfo?.type === "authorization_code" ? tokenInfo.client_auth : "header");
|
|
32
|
-
const t = useTranslations({ note: "OAuth dialog" });
|
|
33
|
-
const clientAuthMethods = {
|
|
34
|
-
header: {
|
|
35
|
-
name: t("Send as Basic Auth header"),
|
|
36
|
-
description: t("Send the client ID and secret in the Authorization header.")
|
|
37
|
-
},
|
|
38
|
-
body: {
|
|
39
|
-
name: t("Send client credentials in body"),
|
|
40
|
-
description: t("Include the client ID and secret in the token request body.")
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const allFlows = useMemo(() => ({
|
|
44
|
-
password: {
|
|
45
|
-
name: t("Resource Owner Password Flow"),
|
|
46
|
-
description: t("Authenticate using username and password."),
|
|
47
|
-
supported: true
|
|
48
|
-
},
|
|
49
|
-
clientCredentials: {
|
|
50
|
-
name: t("Client Credentials"),
|
|
51
|
-
description: t("Intended for the server-to-server authentication."),
|
|
52
|
-
supported: true
|
|
53
|
-
},
|
|
54
|
-
authorizationCode: {
|
|
55
|
-
name: t("Authorization code"),
|
|
56
|
-
description: t("Authenticate with 3rd party services"),
|
|
57
|
-
supported: true
|
|
58
|
-
},
|
|
59
|
-
implicit: {
|
|
60
|
-
name: t("Implicit"),
|
|
61
|
-
description: t("Retrieve the access token directly."),
|
|
62
|
-
supported: true
|
|
63
|
-
},
|
|
64
|
-
deviceAuthorization: {
|
|
65
|
-
name: t("Device Authorization"),
|
|
66
|
-
description: t("Authenticate with device."),
|
|
67
|
-
supported: false
|
|
68
|
-
}
|
|
69
|
-
}), [t]);
|
|
70
|
-
const defaultValues = useMemo(() => {
|
|
71
|
-
return {
|
|
72
|
-
clientId: tokenInfo?.client_id ?? "",
|
|
73
|
-
clientSecret: tokenInfo?.type === "authorization_code" ? tokenInfo.client_secret : "",
|
|
74
|
-
username: "",
|
|
75
|
-
password: ""
|
|
76
|
-
};
|
|
77
|
-
}, [tokenInfo]);
|
|
78
|
-
const authorize = useQuery(async (values) => {
|
|
79
|
-
if (!type) return;
|
|
80
|
-
const token = await requestOAuthToken(scheme, type, {
|
|
81
|
-
...values,
|
|
82
|
-
schemeId,
|
|
83
|
-
scopes,
|
|
84
|
-
clientAuth,
|
|
85
|
-
serverUrl: resolveUrl(),
|
|
86
|
-
redirectUrl: oauthRedirectUrl
|
|
87
|
-
});
|
|
88
|
-
if (!token) return;
|
|
89
|
-
setToken(token);
|
|
90
|
-
setOpen(false);
|
|
91
|
-
});
|
|
92
|
-
const isLoading = authorize.isLoading;
|
|
93
|
-
return /* @__PURE__ */ jsxs("form", {
|
|
94
|
-
className: "flex flex-col gap-6",
|
|
95
|
-
onSubmit: (e) => {
|
|
96
|
-
const formData = new FormData(e.target);
|
|
97
|
-
authorize.start(Object.fromEntries(formData.entries()));
|
|
98
|
-
e.preventDefault();
|
|
99
|
-
e.stopPropagation();
|
|
100
|
-
},
|
|
101
|
-
children: [
|
|
102
|
-
/* @__PURE__ */ jsxs(Select, {
|
|
103
|
-
items: Object.keys(scheme.flows).map((key) => {
|
|
104
|
-
const { name, description } = allFlows[key];
|
|
105
|
-
return {
|
|
106
|
-
value: key,
|
|
107
|
-
label: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("p", {
|
|
108
|
-
className: "font-medium",
|
|
109
|
-
children: name
|
|
110
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
111
|
-
className: "text-fd-muted-foreground",
|
|
112
|
-
children: description
|
|
113
|
-
})] })
|
|
114
|
-
};
|
|
115
|
-
}),
|
|
116
|
-
value: type,
|
|
117
|
-
onValueChange: setType,
|
|
118
|
-
children: [/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("Select a flow") }) }), /* @__PURE__ */ jsx(SelectContent, { children: Object.keys(scheme.flows).map((key) => {
|
|
119
|
-
const { name, description } = allFlows[key];
|
|
120
|
-
return /* @__PURE__ */ jsxs(SelectItem, {
|
|
121
|
-
value: key,
|
|
122
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
123
|
-
className: "font-medium",
|
|
124
|
-
children: name
|
|
125
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
126
|
-
className: "text-fd-muted-foreground",
|
|
127
|
-
children: description
|
|
128
|
-
})]
|
|
129
|
-
}, key);
|
|
130
|
-
}) })]
|
|
131
|
-
}),
|
|
132
|
-
(type === "authorizationCode" || type === "clientCredentials" || type === "implicit" || type === "password") && /* @__PURE__ */ jsxs("fieldset", {
|
|
133
|
-
className: "flex flex-col gap-1.5",
|
|
134
|
-
children: [
|
|
135
|
-
/* @__PURE__ */ jsx(Label, {
|
|
136
|
-
htmlFor: "client_id",
|
|
137
|
-
children: t("Client ID")
|
|
138
|
-
}),
|
|
139
|
-
/* @__PURE__ */ jsx("p", {
|
|
140
|
-
className: "text-fd-muted-foreground text-sm",
|
|
141
|
-
children: t("The client ID of your OAuth application.")
|
|
142
|
-
}),
|
|
143
|
-
/* @__PURE__ */ jsx(Input, {
|
|
144
|
-
id: "client_id",
|
|
145
|
-
name: "clientId",
|
|
146
|
-
placeholder: t("Enter value"),
|
|
147
|
-
type: "text",
|
|
148
|
-
autoComplete: "off",
|
|
149
|
-
disabled: isLoading,
|
|
150
|
-
defaultValue: defaultValues.clientId,
|
|
151
|
-
required: type !== "password"
|
|
152
|
-
})
|
|
153
|
-
]
|
|
154
|
-
}),
|
|
155
|
-
(type === "authorizationCode" || type === "clientCredentials" || type === "password") && /* @__PURE__ */ jsxs("fieldset", {
|
|
156
|
-
className: "flex flex-col gap-1.5",
|
|
157
|
-
children: [
|
|
158
|
-
/* @__PURE__ */ jsx(Label, {
|
|
159
|
-
htmlFor: "client_secret",
|
|
160
|
-
children: t("Client Secret")
|
|
161
|
-
}),
|
|
162
|
-
/* @__PURE__ */ jsx("p", {
|
|
163
|
-
className: "text-fd-muted-foreground text-sm",
|
|
164
|
-
children: t("The client secret of your OAuth application.")
|
|
165
|
-
}),
|
|
166
|
-
/* @__PURE__ */ jsx(Input, {
|
|
167
|
-
id: "client_secret",
|
|
168
|
-
name: "clientSecret",
|
|
169
|
-
placeholder: t("Enter value"),
|
|
170
|
-
type: "password",
|
|
171
|
-
autoComplete: "off",
|
|
172
|
-
disabled: isLoading,
|
|
173
|
-
defaultValue: defaultValues.clientSecret,
|
|
174
|
-
required: type !== "password"
|
|
175
|
-
})
|
|
176
|
-
]
|
|
177
|
-
}),
|
|
178
|
-
(type === "authorizationCode" || type === "clientCredentials" || type === "password") && /* @__PURE__ */ jsxs("fieldset", {
|
|
179
|
-
className: "flex flex-col gap-1.5",
|
|
180
|
-
children: [/* @__PURE__ */ jsx(Label, {
|
|
181
|
-
htmlFor: "client_auth",
|
|
182
|
-
children: t("Client Authentication")
|
|
183
|
-
}), /* @__PURE__ */ jsxs(Select, {
|
|
184
|
-
items: Object.entries(clientAuthMethods).map(([key, method]) => ({
|
|
185
|
-
label: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("p", {
|
|
186
|
-
className: "font-medium",
|
|
187
|
-
children: method.name
|
|
188
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
189
|
-
className: "text-fd-muted-foreground",
|
|
190
|
-
children: method.description
|
|
191
|
-
})] }),
|
|
192
|
-
value: key
|
|
193
|
-
})),
|
|
194
|
-
value: clientAuth,
|
|
195
|
-
onValueChange: (v) => v !== null && setClientAuth(v),
|
|
196
|
-
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
197
|
-
id: "client_auth",
|
|
198
|
-
disabled: isLoading,
|
|
199
|
-
children: /* @__PURE__ */ jsx(SelectValue, {})
|
|
200
|
-
}), /* @__PURE__ */ jsx(SelectContent, { children: Object.entries(clientAuthMethods).map(([key, method]) => /* @__PURE__ */ jsxs(SelectItem, {
|
|
201
|
-
value: key,
|
|
202
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
203
|
-
className: "font-medium",
|
|
204
|
-
children: method.name
|
|
205
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
206
|
-
className: "text-fd-muted-foreground",
|
|
207
|
-
children: method.description
|
|
208
|
-
})]
|
|
209
|
-
}, key)) })]
|
|
210
|
-
})]
|
|
211
|
-
}),
|
|
212
|
-
type === "password" && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("fieldset", {
|
|
213
|
-
className: "flex flex-col gap-1.5",
|
|
214
|
-
children: [/* @__PURE__ */ jsx(Label, {
|
|
215
|
-
htmlFor: "username",
|
|
216
|
-
children: t("Username")
|
|
217
|
-
}), /* @__PURE__ */ jsx(Input, {
|
|
218
|
-
id: "username",
|
|
219
|
-
name: "username",
|
|
220
|
-
placeholder: t("Enter value"),
|
|
221
|
-
type: "text",
|
|
222
|
-
autoComplete: "off",
|
|
223
|
-
disabled: isLoading,
|
|
224
|
-
defaultValue: defaultValues.username,
|
|
225
|
-
required: true
|
|
226
|
-
})]
|
|
227
|
-
}), /* @__PURE__ */ jsxs("fieldset", {
|
|
228
|
-
className: "flex flex-col gap-1.5",
|
|
229
|
-
children: [/* @__PURE__ */ jsx(Label, {
|
|
230
|
-
htmlFor: "password",
|
|
231
|
-
children: t("Password")
|
|
232
|
-
}), /* @__PURE__ */ jsx(Input, {
|
|
233
|
-
id: "password",
|
|
234
|
-
name: "password",
|
|
235
|
-
placeholder: t("Enter value"),
|
|
236
|
-
type: "password",
|
|
237
|
-
autoComplete: "off",
|
|
238
|
-
disabled: isLoading,
|
|
239
|
-
defaultValue: defaultValues.password,
|
|
240
|
-
required: true
|
|
241
|
-
})]
|
|
242
|
-
})] }),
|
|
243
|
-
type && allFlows[type].supported ? /* @__PURE__ */ jsxs(Fragment$1, { children: [authorize.error ? /* @__PURE__ */ jsx("p", {
|
|
244
|
-
className: "text-red-400 font-medium text-sm",
|
|
245
|
-
children: String(authorize.error)
|
|
246
|
-
}) : null, /* @__PURE__ */ jsx("button", {
|
|
247
|
-
type: "submit",
|
|
248
|
-
className: cn(buttonVariants({ variant: "default" })),
|
|
249
|
-
children: t("Submit")
|
|
250
|
-
})] }) : /* @__PURE__ */ jsx("p", {
|
|
251
|
-
className: "text-fd-muted-foreground bg-fd-muted p-2 rounded-lg border",
|
|
252
|
-
children: t("Unsupported")
|
|
253
|
-
})
|
|
254
|
-
]
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
const OAuthDialogTrigger = DialogTrigger;
|
|
258
|
-
//#endregion
|
|
259
|
-
export { OAuthDialog, OAuthDialogContent, OAuthDialogTrigger };
|