fumadocs-openapi 12.4.1 → 12.5.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 +12 -1
- package/dist/.translations/keys.js +12 -1
- package/dist/generate-file.js +3 -1
- package/dist/index.browser.d.ts +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/operation.js +2 -2
- package/dist/packages/shared-api/dist/codegen.js +1 -3
- package/dist/packages/shared-api/dist/components/schema/client.js +1 -1
- package/dist/playground/auth.d.ts +84 -30
- package/dist/playground/auth.js +250 -150
- package/dist/playground/fetcher.js +11 -6
- package/dist/playground/index.d.ts +2 -2
- package/dist/playground/index.js +2 -2
- package/dist/playground/use-playground.d.ts +3 -3
- package/dist/playground/use-playground.js +46 -31
- package/dist/requests/generators/python.d.ts +0 -1
- package/dist/requests/generators/python.js +1 -1
- package/dist/server/index.d.ts +2 -9
- package/dist/server/index.js +0 -4
- package/dist/server/proxy.d.ts +5 -4
- package/dist/server/proxy.js +105 -25
- package/dist/types/openapi.d.ts +7 -2
- package/dist/types.d.ts +1 -0
- package/dist/ui/operation/index.js +48 -27
- package/dist/ui/operation/usage-tabs.js +251 -34
- package/dist/ui/playground/client.js +8 -4
- package/dist/ui/playground/components/fields.js +2 -2
- package/dist/ui/playground/components/oauth-panel.js +150 -39
- package/dist/ui/playground/components/request-panel.js +18 -3
- package/dist/ui/playground/components/response-panel.js +53 -90
- package/dist/utils/create-page.d.ts +1 -1
- package/dist/utils/pages/to-static-data.d.ts +12 -0
- package/dist/utils/use-server.js +1 -1
- package/package.json +7 -6
- package/dist/packages/shared-api/dist/components/accordion.js +0 -63
- package/dist/ui/operation/request-tabs.js +0 -92
- package/dist/ui/operation/response-tabs.js +0 -53
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useOperation } from "../../../operation.js";
|
|
3
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
4
|
+
import { Markdown } from "../../components/markdown.js";
|
|
4
5
|
import { cn } from "../../../utils/cn.js";
|
|
5
6
|
import { Segmented, SegmentedList } from "../../components/segmented.js";
|
|
6
7
|
import { anyFields, useResolvedSchema, useSchemaUtils } from "../../../packages/shared-api/dist/components/playground/schema.js";
|
|
@@ -10,7 +11,7 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
|
10
11
|
import { useDataEngine, useFieldValue } from "@fumari/stf";
|
|
11
12
|
import { stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
12
13
|
import { useTranslations } from "@fuma-translate/react";
|
|
13
|
-
import { ArrowLeft, Braces, ChevronRight, Cookie, KeyRound, PlusIcon, Route, Rows3, SlidersHorizontal } from "lucide-react";
|
|
14
|
+
import { ArrowLeft, Braces, ChevronRight, Cookie, KeyRound, PlusIcon, Route, Rows3, ShieldCheck, SlidersHorizontal } from "lucide-react";
|
|
14
15
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
15
16
|
//#region src/ui/playground/components/request-panel.tsx
|
|
16
17
|
const sectionIcons = {
|
|
@@ -283,7 +284,7 @@ function Section({ icon: Icon, title, count, actions, children }) {
|
|
|
283
284
|
return /* @__PURE__ */ jsxs("section", {
|
|
284
285
|
className: "border-b last:border-b-0",
|
|
285
286
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
286
|
-
className: "sticky top-0 z-10 flex h-
|
|
287
|
+
className: "sticky top-0 z-10 flex h-10 items-center gap-2 border-b bg-fd-card ps-4 pe-2 @sm:pe-7.5",
|
|
287
288
|
children: [
|
|
288
289
|
/* @__PURE__ */ jsx(Icon, { className: "size-3.5 shrink-0 text-fd-primary" }),
|
|
289
290
|
/* @__PURE__ */ jsx("h3", {
|
|
@@ -374,6 +375,20 @@ function AuthPanelRow({ title, component }) {
|
|
|
374
375
|
children: title
|
|
375
376
|
});
|
|
376
377
|
}
|
|
378
|
+
/** mutual TLS schemes, they have no value */
|
|
379
|
+
const mutualTLSProvider = {
|
|
380
|
+
on: ({ scheme }) => scheme.type === "mutualTLS",
|
|
381
|
+
render: function MutualTLSNote({ field }) {
|
|
382
|
+
const t = useTranslations({ note: "playground" });
|
|
383
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
384
|
+
className: "flex gap-2 border-b px-4 py-2.5 text-xs text-fd-muted-foreground last:border-b-0",
|
|
385
|
+
children: [/* @__PURE__ */ jsx(ShieldCheck, { className: "mt-px size-3.5 shrink-0" }), /* @__PURE__ */ jsxs("div", {
|
|
386
|
+
className: "min-w-0 flex-1 [&_a]:underline",
|
|
387
|
+
children: [/* @__PURE__ */ jsx("p", { children: t("Requires a client certificate installed in your browser.") }), field.scheme.description && /* @__PURE__ */ jsx(Markdown, { md: field.scheme.description })]
|
|
388
|
+
})]
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
};
|
|
377
392
|
function BodySection({ body, renderBodyField, onNavigate }) {
|
|
378
393
|
const t = useTranslations({ note: "playground" });
|
|
379
394
|
const [mode, setMode] = useState("form");
|
|
@@ -463,4 +478,4 @@ function formatJson(value) {
|
|
|
463
478
|
return JSON.stringify(value ?? {}, null, 2);
|
|
464
479
|
}
|
|
465
480
|
//#endregion
|
|
466
|
-
export { RequestPanel };
|
|
481
|
+
export { RequestPanel, mutualTLSProvider };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
|
|
4
|
-
import { Markdown } from "../../components/markdown.js";
|
|
2
|
+
import { useResponseExamples } from "../../../operation.js";
|
|
5
3
|
import { ClientCodeBlock } from "../../components/codeblock.js";
|
|
4
|
+
import { Markdown } from "../../components/markdown.js";
|
|
6
5
|
import { cn } from "../../../utils/cn.js";
|
|
6
|
+
import { CodeUsages, ExampleSelect } from "../../operation/usage-tabs.js";
|
|
7
7
|
import { Segmented, SegmentedList, SegmentedPanel } from "../../components/segmented.js";
|
|
8
8
|
import { DefaultResultDisplay, PanelHeader, panelCodeBlock } from "./result-display.js";
|
|
9
9
|
import { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
|
|
@@ -11,14 +11,16 @@ import { useState } from "react";
|
|
|
11
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
import { useTranslations } from "@fuma-translate/react";
|
|
13
13
|
import { SendHorizontal } from "lucide-react";
|
|
14
|
-
import { CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger } from "fumadocs-ui/components/codeblock";
|
|
15
14
|
//#region src/ui/playground/components/response-panel.tsx
|
|
16
|
-
/** the code usages of the request, above its response or the documented examples */
|
|
17
15
|
function ResponsePanel({ response, loading, onReset, ResultDisplay = DefaultResultDisplay, className }) {
|
|
18
16
|
const t = useTranslations({ note: "playground" });
|
|
19
17
|
return /* @__PURE__ */ jsxs("div", {
|
|
20
18
|
className: cn("@container flex min-h-0 flex-col", className),
|
|
21
|
-
children: [/* @__PURE__ */ jsx(
|
|
19
|
+
children: [/* @__PURE__ */ jsx(CodeUsages, {
|
|
20
|
+
title: t("Request"),
|
|
21
|
+
className: "shrink-0 border-b",
|
|
22
|
+
viewportClassName: "max-h-[min(18rem,30vh)]"
|
|
23
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
22
24
|
className: "relative flex min-h-0 flex-1 flex-col",
|
|
23
25
|
children: [response ? /* @__PURE__ */ jsx(ResultDisplay, {
|
|
24
26
|
data: response.result,
|
|
@@ -31,40 +33,6 @@ function ResponsePanel({ response, loading, onReset, ResultDisplay = DefaultResu
|
|
|
31
33
|
})]
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
|
-
function RequestExample() {
|
|
35
|
-
const items = Array.from(useOperation().codeUsages.map());
|
|
36
|
-
if (items.length === 0) return null;
|
|
37
|
-
return /* @__PURE__ */ jsxs(CodeBlockTabs, {
|
|
38
|
-
groupId: "fumadocs_openapi_requests",
|
|
39
|
-
defaultValue: items[0][0],
|
|
40
|
-
className: "my-0 shrink-0 rounded-none border-0 border-b bg-transparent",
|
|
41
|
-
children: [/* @__PURE__ */ jsx(CodeBlockTabsList, {
|
|
42
|
-
className: "h-10 items-stretch border-b [scrollbar-width:none]",
|
|
43
|
-
children: items.map(([id, item]) => /* @__PURE__ */ jsx(CodeBlockTabsTrigger, {
|
|
44
|
-
value: id,
|
|
45
|
-
children: item.label ?? item.lang
|
|
46
|
-
}, id))
|
|
47
|
-
}), items.map(([id, item]) => /* @__PURE__ */ jsx(CodeBlockTab, {
|
|
48
|
-
value: id,
|
|
49
|
-
children: /* @__PURE__ */ jsx(UsageCode, {
|
|
50
|
-
id,
|
|
51
|
-
lang: item.lang
|
|
52
|
-
})
|
|
53
|
-
}, id))]
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function UsageCode({ id, lang }) {
|
|
57
|
-
const code = useCodeUsage(id);
|
|
58
|
-
if (!code) return null;
|
|
59
|
-
return /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
60
|
-
lang,
|
|
61
|
-
code,
|
|
62
|
-
codeblock: {
|
|
63
|
-
className: "rounded-none border-0 bg-transparent shadow-none",
|
|
64
|
-
viewportProps: { className: "max-h-[min(18rem,30vh)]" }
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
36
|
function ResponseExamples() {
|
|
69
37
|
const t = useTranslations({ note: "playground" });
|
|
70
38
|
const tabs = useResponseExamples();
|
|
@@ -90,60 +58,55 @@ function ResponseExamples() {
|
|
|
90
58
|
setSelected(0);
|
|
91
59
|
},
|
|
92
60
|
className: "flex min-h-0 flex-1 flex-col",
|
|
93
|
-
children: [
|
|
94
|
-
/* @__PURE__ */
|
|
95
|
-
className: "
|
|
96
|
-
children:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
61
|
+
children: [
|
|
62
|
+
/* @__PURE__ */ jsxs(PanelHeader, {
|
|
63
|
+
className: "border-b-0",
|
|
64
|
+
children: [
|
|
65
|
+
/* @__PURE__ */ jsx("span", {
|
|
66
|
+
className: "me-auto text-[0.8125rem] font-medium",
|
|
67
|
+
children: t("Response")
|
|
68
|
+
}),
|
|
69
|
+
examples.length > 1 && /* @__PURE__ */ jsx(ExampleSelect, {
|
|
70
|
+
items: examples.map((item, i) => ({
|
|
71
|
+
value: String(i),
|
|
72
|
+
label: item.label
|
|
73
|
+
})),
|
|
74
|
+
value: String(selected),
|
|
75
|
+
onValueChange: (v) => setSelected(Number(v)),
|
|
76
|
+
className: "max-w-40"
|
|
77
|
+
}),
|
|
78
|
+
/* @__PURE__ */ jsx(SegmentedList, {
|
|
79
|
+
className: "max-w-1/2 shrink-0 overflow-x-auto [scrollbar-width:none]",
|
|
80
|
+
items: tabs.map((item) => ({
|
|
81
|
+
value: item.code,
|
|
82
|
+
label: /* @__PURE__ */ jsx("span", {
|
|
83
|
+
className: "font-mono",
|
|
84
|
+
children: item.code
|
|
85
|
+
})
|
|
86
|
+
}))
|
|
87
|
+
})
|
|
88
|
+
]
|
|
102
89
|
}),
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
label: item.label
|
|
107
|
-
})),
|
|
108
|
-
value: String(selected),
|
|
109
|
-
onValueChange: (v) => v !== null && setSelected(Number(v)),
|
|
110
|
-
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
111
|
-
className: "h-7 w-auto max-w-40 shrink-0 gap-1.5 border-0 bg-transparent px-2 text-xs hover:bg-fd-accent focus:ring-0 focus-visible:ring-2",
|
|
112
|
-
children: /* @__PURE__ */ jsx(SelectValue, { className: "truncate" })
|
|
113
|
-
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
114
|
-
align: "end",
|
|
115
|
-
children: examples.map((item, i) => /* @__PURE__ */ jsx(SelectItem, {
|
|
116
|
-
value: String(i),
|
|
117
|
-
className: "text-xs",
|
|
118
|
-
children: item.label
|
|
119
|
-
}, i))
|
|
120
|
-
})]
|
|
90
|
+
tab.response.description && /* @__PURE__ */ jsx("div", {
|
|
91
|
+
className: "prose prose-xs prose-no-margin -mt-1 px-4 pb-2.5 text-fd-muted-foreground",
|
|
92
|
+
children: /* @__PURE__ */ jsx(Markdown, { md: tab.response.description })
|
|
121
93
|
}),
|
|
122
|
-
/* @__PURE__ */ jsx(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
94
|
+
/* @__PURE__ */ jsx(SegmentedPanel, {
|
|
95
|
+
value: tab.code,
|
|
96
|
+
className: "flex min-h-0 flex-1 flex-col overflow-auto border-t",
|
|
97
|
+
children: example ? /* @__PURE__ */ jsx("div", {
|
|
98
|
+
className: "min-h-0 flex-1",
|
|
99
|
+
children: /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
100
|
+
lang: "json",
|
|
101
|
+
code: JSON.stringify(example.sample, null, 2),
|
|
102
|
+
codeblock: panelCodeBlock
|
|
129
103
|
})
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
value: tab.code,
|
|
134
|
-
className: "flex min-h-0 flex-1 flex-col overflow-auto",
|
|
135
|
-
children: example ? /* @__PURE__ */ jsx("div", {
|
|
136
|
-
className: "min-h-0 flex-1",
|
|
137
|
-
children: /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
138
|
-
lang: "json",
|
|
139
|
-
code: JSON.stringify(example.sample, null, 2),
|
|
140
|
-
codeblock: panelCodeBlock
|
|
104
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
105
|
+
className: "p-4 text-sm text-fd-muted-foreground",
|
|
106
|
+
children: t("No example available.")
|
|
141
107
|
})
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
children: t("No example available.")
|
|
145
|
-
})
|
|
146
|
-
}, tab.code)]
|
|
108
|
+
}, tab.code)
|
|
109
|
+
]
|
|
147
110
|
});
|
|
148
111
|
}
|
|
149
112
|
//#endregion
|
|
@@ -27,7 +27,7 @@ export interface OpenAPIRuntimeOptions {
|
|
|
27
27
|
*/
|
|
28
28
|
mediaAdapters?: Record<string, MediaAdapter>;
|
|
29
29
|
/**
|
|
30
|
-
* Set a prefix for
|
|
30
|
+
* Set a prefix for storage keys.
|
|
31
31
|
*
|
|
32
32
|
* Useful when using multiple OpenAPI instances to prevent state conflicts.
|
|
33
33
|
*
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "./builder.js";
|
|
2
|
+
import { TOCItemType } from "fumadocs-core/toc";
|
|
3
|
+
import "fumadocs-core/mdx-plugins";
|
|
4
|
+
//#region src/utils/pages/to-static-data.d.ts
|
|
5
|
+
/** the `_openapi` data of pages */
|
|
6
|
+
export interface InternalOpenAPIMeta {
|
|
7
|
+
method?: string;
|
|
8
|
+
webhook?: boolean;
|
|
9
|
+
deprecated?: boolean;
|
|
10
|
+
preload?: string[];
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
package/dist/utils/use-server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { joinURL, resolveServerUrl } from "../packages/shared-api/dist/utils/url.js";
|
|
3
2
|
import { useServerStore } from "../packages/shared-api/dist/utils/use-server-store.js";
|
|
3
|
+
import { joinURL, resolveServerUrl } from "../packages/shared-api/dist/utils/url.js";
|
|
4
4
|
import { createContext, use, useCallback, useMemo, useSyncExternalStore } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/utils/use-server.tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.5.0",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"./ui/playground/client": "./dist/ui/playground/client.js",
|
|
47
47
|
"./ui/scalar": "./dist/ui/scalar/index.js",
|
|
48
48
|
"./package.json": "./package.json",
|
|
49
|
-
"./css
|
|
49
|
+
"./css/preset.css": "./css/preset.css"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@base-ui/react": "^1.8.0",
|
|
56
56
|
"@fuma-translate/react": "^1.0.2",
|
|
57
|
-
"@fumadocs/json-schema": "0.3.0",
|
|
57
|
+
"@fumadocs/json-schema": "^0.3.0",
|
|
58
58
|
"@fumari/json-schema-ts": "^1.0.2",
|
|
59
|
-
"@fumari/stf": "1.1.1",
|
|
59
|
+
"@fumari/stf": "^1.1.1",
|
|
60
60
|
"@scalar/json-magic": "^0.15.4",
|
|
61
61
|
"@scalar/openapi-upgrader": "^0.4.1",
|
|
62
62
|
"chokidar": "^5.0.0",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"remark": "^15.0.1",
|
|
69
69
|
"remark-rehype": "^11.1.2",
|
|
70
70
|
"shiki": "^4.5.0",
|
|
71
|
+
"undici": "^7.29.1",
|
|
71
72
|
"yaml": "^2.9.1"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
@@ -78,8 +79,8 @@
|
|
|
78
79
|
"@types/react-dom": "^19.3.0",
|
|
79
80
|
"fast-content-type-parse": "^4.0.0",
|
|
80
81
|
"fuma-cli": "^0.3.1",
|
|
81
|
-
"fumadocs-core": "16.17.
|
|
82
|
-
"fumadocs-ui": "npm:@fumadocs/base-ui@16.17.
|
|
82
|
+
"fumadocs-core": "16.17.4",
|
|
83
|
+
"fumadocs-ui": "npm:@fumadocs/base-ui@16.17.4",
|
|
83
84
|
"json-schema-typed": "^8.0.2",
|
|
84
85
|
"shared-api": "0.2.11",
|
|
85
86
|
"tsconfig": "0.0.0",
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { cn } from "../utils/cn.js";
|
|
3
|
-
import { AnchorSection, useAnchorLink } from "../auto-anchor/index.js";
|
|
4
|
-
import { createContext, use, useMemo, useState } from "react";
|
|
5
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { ChevronRight } from "lucide-react";
|
|
7
|
-
import { Accordion } from "@base-ui/react/accordion";
|
|
8
|
-
//#region ../shared-api/dist/components/accordion.js
|
|
9
|
-
const Context = createContext(null);
|
|
10
|
-
function Accordions({ type = "single", defaultValue, ...props }) {
|
|
11
|
-
const [value, setValue] = useState(() => {
|
|
12
|
-
if (Array.isArray(defaultValue)) return defaultValue;
|
|
13
|
-
if (defaultValue) return [defaultValue];
|
|
14
|
-
return [];
|
|
15
|
-
});
|
|
16
|
-
return /* @__PURE__ */ jsx(Context, {
|
|
17
|
-
value: useMemo(() => ({
|
|
18
|
-
type,
|
|
19
|
-
setValue
|
|
20
|
-
}), [type]),
|
|
21
|
-
children: /* @__PURE__ */ jsx(Accordion.Root, {
|
|
22
|
-
multiple: type === "multiple",
|
|
23
|
-
value,
|
|
24
|
-
onValueChange: setValue,
|
|
25
|
-
...props
|
|
26
|
-
})
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function AccordionItem({ value, className, anchorSegments, ...props }) {
|
|
30
|
-
const ctx = use(Context);
|
|
31
|
-
useAnchorLink(anchorSegments ?? false, () => ctx.setValue([value]));
|
|
32
|
-
const content = /* @__PURE__ */ jsx(Accordion.Item, {
|
|
33
|
-
value,
|
|
34
|
-
className: cn("scroll-m-20 border-b last:border-b-0", className),
|
|
35
|
-
...props
|
|
36
|
-
});
|
|
37
|
-
return anchorSegments ? /* @__PURE__ */ jsx(AnchorSection, {
|
|
38
|
-
segments: anchorSegments,
|
|
39
|
-
children: content
|
|
40
|
-
}) : content;
|
|
41
|
-
}
|
|
42
|
-
function AccordionContent(props) {
|
|
43
|
-
return /* @__PURE__ */ jsx(Accordion.Panel, {
|
|
44
|
-
...props,
|
|
45
|
-
className: cn("h-(--accordion-panel-height) overflow-hidden transition-[height] ease-out data-ending-style:h-0 data-starting-style:h-0", props.className)
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function AccordionHeader(props) {
|
|
49
|
-
return /* @__PURE__ */ jsx(Accordion.Header, {
|
|
50
|
-
...props,
|
|
51
|
-
className: cn("not-prose flex text-fd-foreground font-medium", props.className),
|
|
52
|
-
children: props.children
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function AccordionTrigger(props) {
|
|
56
|
-
return /* @__PURE__ */ jsxs(Accordion.Trigger, {
|
|
57
|
-
...props,
|
|
58
|
-
className: cn("flex flex-1 items-center gap-1 text-start group/accordion py-2 focus-visible:outline-none", props.className),
|
|
59
|
-
children: [/* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 text-fd-muted-foreground shrink-0 transition-transform group-data-[panel-open]/accordion:rotate-90" }), props.children]
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
export { AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger, Accordions };
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useExampleRequests, useOperation } from "../../operation.js";
|
|
3
|
-
import { useRenderContext } from "../../utils/create-page.js";
|
|
4
|
-
import { MethodLabel } from "../components/method-label.js";
|
|
5
|
-
import { AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger, Accordions } from "../../packages/shared-api/dist/components/accordion.js";
|
|
6
|
-
import { Markdown } from "../components/markdown.js";
|
|
7
|
-
import { ClientCodeBlock } from "../components/codeblock.js";
|
|
8
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
-
import { useTranslations } from "@fuma-translate/react";
|
|
10
|
-
import { Tabs, TabsContent, TabsList, TabsTrigger } from "fumadocs-ui/components/tabs";
|
|
11
|
-
//#region src/ui/operation/request-tabs.tsx
|
|
12
|
-
function RequestTabs() {
|
|
13
|
-
const ctx = useRenderContext();
|
|
14
|
-
const { path, method, operation, pathItem } = useOperation();
|
|
15
|
-
const { items } = useExampleRequests();
|
|
16
|
-
if (!operation.requestBody) return null;
|
|
17
|
-
if (ctx.content?.renderRequestTabs) return ctx.content.renderRequestTabs({
|
|
18
|
-
items,
|
|
19
|
-
route: path,
|
|
20
|
-
method,
|
|
21
|
-
pathItem,
|
|
22
|
-
operation
|
|
23
|
-
}, ctx);
|
|
24
|
-
return /* @__PURE__ */ jsx(RequestTabsDefaultContent, { items });
|
|
25
|
-
}
|
|
26
|
-
function RequestTabsDefaultContent({ items }) {
|
|
27
|
-
const t = useTranslations({ note: "operation page" });
|
|
28
|
-
let children;
|
|
29
|
-
if (items.length > 1) children = /* @__PURE__ */ jsxs(Tabs, {
|
|
30
|
-
defaultValue: items[0].id,
|
|
31
|
-
children: [/* @__PURE__ */ jsx(TabsList, { children: items.map((item) => /* @__PURE__ */ jsx(TabsTrigger, {
|
|
32
|
-
value: item.id,
|
|
33
|
-
children: item.id === "_default" ? t("Default") : item.name
|
|
34
|
-
}, item.id)) }), items.map((item) => /* @__PURE__ */ jsx(TabsContent, {
|
|
35
|
-
value: item.id,
|
|
36
|
-
children: /* @__PURE__ */ jsx(RequestTabsItem, { item })
|
|
37
|
-
}, item.id))]
|
|
38
|
-
});
|
|
39
|
-
else if (items.length === 1) children = /* @__PURE__ */ jsx(RequestTabsItem, { item: items[0] });
|
|
40
|
-
else children = /* @__PURE__ */ jsx("p", {
|
|
41
|
-
className: "text-fd-muted-foreground text-xs",
|
|
42
|
-
children: t("Empty")
|
|
43
|
-
});
|
|
44
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
45
|
-
className: "p-3 rounded-xl border prose-no-margin bg-fd-card text-fd-card-foreground shadow-md",
|
|
46
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
47
|
-
className: "font-semibold border-b pb-2",
|
|
48
|
-
children: t("Example Requests")
|
|
49
|
-
}), children]
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function RequestTabsItem({ item }) {
|
|
53
|
-
const t = useTranslations({ note: "operation page" });
|
|
54
|
-
const requestData = item.data;
|
|
55
|
-
const displayNames = {
|
|
56
|
-
body: /* @__PURE__ */ jsxs(Fragment, { children: [t("Request Body"), /* @__PURE__ */ jsx("code", {
|
|
57
|
-
className: "text-xs text-fd-muted-foreground ms-auto",
|
|
58
|
-
children: requestData.bodyMediaType
|
|
59
|
-
})] }),
|
|
60
|
-
cookie: t("Cookie Parameters"),
|
|
61
|
-
header: t("Header Parameters"),
|
|
62
|
-
query: t("Query Parameters"),
|
|
63
|
-
path: t("Path Parameters")
|
|
64
|
-
};
|
|
65
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
66
|
-
item.description && /* @__PURE__ */ jsx(Markdown, { md: item.description }),
|
|
67
|
-
/* @__PURE__ */ jsxs("div", {
|
|
68
|
-
className: "flex flex-row gap-2 items-center justify-between",
|
|
69
|
-
children: [/* @__PURE__ */ jsx(MethodLabel, { children: requestData.method }), /* @__PURE__ */ jsx("code", { children: item.pathname })]
|
|
70
|
-
}),
|
|
71
|
-
/* @__PURE__ */ jsx(Accordions, {
|
|
72
|
-
type: "multiple",
|
|
73
|
-
className: "mt-2",
|
|
74
|
-
children: Object.entries(displayNames).map(([k, v]) => {
|
|
75
|
-
const data = requestData[k];
|
|
76
|
-
if (!data || Object.keys(data).length === 0) return;
|
|
77
|
-
return /* @__PURE__ */ jsxs(AccordionItem, {
|
|
78
|
-
value: k,
|
|
79
|
-
children: [/* @__PURE__ */ jsx(AccordionHeader, { children: /* @__PURE__ */ jsx(AccordionTrigger, { children: v }) }), /* @__PURE__ */ jsx(AccordionContent, {
|
|
80
|
-
className: "prose-no-margin",
|
|
81
|
-
children: /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
82
|
-
lang: "json",
|
|
83
|
-
code: JSON.stringify(data, null, 2)
|
|
84
|
-
})
|
|
85
|
-
})]
|
|
86
|
-
}, k);
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
] });
|
|
90
|
-
}
|
|
91
|
-
//#endregion
|
|
92
|
-
export { RequestTabs };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useResponseExamples } from "../../operation.js";
|
|
3
|
-
import { useRenderContext } from "../../utils/create-page.js";
|
|
4
|
-
import { AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger, Accordions } from "../../packages/shared-api/dist/components/accordion.js";
|
|
5
|
-
import { Markdown } from "../components/markdown.js";
|
|
6
|
-
import { ClientCodeBlock } from "../components/codeblock.js";
|
|
7
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import { useTranslations } from "@fuma-translate/react";
|
|
9
|
-
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
|
10
|
-
//#region src/ui/operation/response-tabs.tsx
|
|
11
|
-
function ResponseTabs() {
|
|
12
|
-
const ctx = useRenderContext();
|
|
13
|
-
const tabs = useResponseExamples();
|
|
14
|
-
if (tabs.length === 0) return null;
|
|
15
|
-
if (ctx.content?.renderResponseTabs) return ctx.content.renderResponseTabs({ tabs }, ctx);
|
|
16
|
-
return /* @__PURE__ */ jsx(ResponseTabsDefaultContent, { tabs });
|
|
17
|
-
}
|
|
18
|
-
function ResponseTabsDefaultContent({ tabs }) {
|
|
19
|
-
const t = useTranslations({ note: "operation page" });
|
|
20
|
-
function renderExampleContent(example) {
|
|
21
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [example.description && /* @__PURE__ */ jsx(Markdown, { md: example.description }), /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
22
|
-
lang: "json",
|
|
23
|
-
code: JSON.stringify(example.sample, null, 2)
|
|
24
|
-
})] });
|
|
25
|
-
}
|
|
26
|
-
return /* @__PURE__ */ jsx(Tabs, {
|
|
27
|
-
groupId: "fumadocs_openapi_responses",
|
|
28
|
-
items: tabs.map((tab) => tab.code),
|
|
29
|
-
children: tabs.map((tab) => {
|
|
30
|
-
const { examples = [] } = tab;
|
|
31
|
-
let slot = t("Empty");
|
|
32
|
-
if (examples.length > 1) slot = /* @__PURE__ */ jsx(Accordions, {
|
|
33
|
-
type: "single",
|
|
34
|
-
className: "pt-2",
|
|
35
|
-
defaultValue: "0",
|
|
36
|
-
children: examples.map((example, i) => /* @__PURE__ */ jsxs(AccordionItem, {
|
|
37
|
-
value: i.toString(),
|
|
38
|
-
children: [/* @__PURE__ */ jsx(AccordionHeader, { children: /* @__PURE__ */ jsx(AccordionTrigger, { children: example.label }) }), /* @__PURE__ */ jsx(AccordionContent, {
|
|
39
|
-
className: "prose-no-margin",
|
|
40
|
-
children: renderExampleContent(example)
|
|
41
|
-
})]
|
|
42
|
-
}, i))
|
|
43
|
-
});
|
|
44
|
-
else if (examples.length === 1) slot = renderExampleContent(examples[0]);
|
|
45
|
-
return /* @__PURE__ */ jsx(Tab, {
|
|
46
|
-
value: tab.code,
|
|
47
|
-
children: slot
|
|
48
|
-
}, tab.code);
|
|
49
|
-
})
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
export { ResponseTabs };
|