fumadocs-openapi 12.3.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 +3 -1
- package/dist/.translations/keys.js +3 -1
- package/dist/operation.js +4 -4
- package/dist/packages/shared-api/dist/components/defaults.js +1 -1
- 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/operation/index.js +1 -1
- 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 +18 -15
- package/dist/ui/playground/components/fields.js +35 -14
- package/dist/ui/playground/components/oauth-panel.js +71 -21
- package/dist/ui/playground/components/request-panel.js +79 -93
- 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 +3 -3
|
@@ -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
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,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
|
|
@@ -12,9 +12,9 @@ interface ServerContextType {
|
|
|
12
12
|
/**
|
|
13
13
|
* The URL of `pathname` on the selected server, with the server variables resolved.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
* selected. On the server and during hydration the origin is unknown, so
|
|
17
|
-
* `https://example.com
|
|
15
|
+
* Relative server URLs are resolved against the page origin, which also serves the request when
|
|
16
|
+
* no server is selected. On the server and during hydration the origin is unknown, so
|
|
17
|
+
* `https://example.com` takes its place.
|
|
18
18
|
*/
|
|
19
19
|
resolveUrl: (pathname?: string) => string;
|
|
20
20
|
setServer: (value: string) => void;
|
package/dist/utils/use-server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useServerStore } from "../packages/shared-api/dist/utils/use-server-store.js";
|
|
3
2
|
import { joinURL, resolveServerUrl } from "../packages/shared-api/dist/utils/url.js";
|
|
3
|
+
import { useServerStore } from "../packages/shared-api/dist/utils/use-server-store.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
|
|
@@ -31,7 +31,7 @@ function ServerProvider({ servers, storageKeyPrefix, children }) {
|
|
|
31
31
|
const { server } = store;
|
|
32
32
|
const isClient = useSyncExternalStore(noop, () => true, () => false);
|
|
33
33
|
const resolveUrl = useCallback((pathname = "") => {
|
|
34
|
-
const base =
|
|
34
|
+
const base = new URL(server ? resolveServerUrl(server.url, server.variables) : "/", isClient ? window.location.origin : "https://example.com").href;
|
|
35
35
|
return pathname ? joinURL(base, pathname) : base;
|
|
36
36
|
}, [server, isClient]);
|
|
37
37
|
return /* @__PURE__ */ jsx(ServerContext, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.4.0",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"@types/react-dom": "^19.3.0",
|
|
79
79
|
"fast-content-type-parse": "^4.0.0",
|
|
80
80
|
"fuma-cli": "^0.3.1",
|
|
81
|
-
"fumadocs-core": "16.
|
|
82
|
-
"fumadocs-ui": "npm:@fumadocs/base-ui@16.
|
|
81
|
+
"fumadocs-core": "16.17.0",
|
|
82
|
+
"fumadocs-ui": "npm:@fumadocs/base-ui@16.17.0",
|
|
83
83
|
"json-schema-typed": "^8.0.2",
|
|
84
84
|
"shared-api": "0.2.11",
|
|
85
85
|
"tsconfig": "0.0.0",
|