fumadocs-openapi 12.2.0 → 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 +1 -3
- package/dist/.translations/keys.js +1 -3
- package/dist/packages/shared-api/dist/.translations/index.d.ts +1 -0
- package/dist/packages/shared-api/dist/.translations/keys.js +1 -0
- package/dist/packages/shared-api/dist/auto-anchor/index.js +54 -10
- package/dist/packages/shared-api/dist/components/accordion.js +3 -11
- package/dist/packages/shared-api/dist/components/collapsible.js +16 -0
- package/dist/packages/shared-api/dist/components/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/ui/components/dialog.js +14 -0
- package/dist/ui/components/endpoint.js +11 -8
- package/dist/ui/components/heading.js +1 -1
- package/dist/ui/components/schema.js +1 -1
- package/dist/ui/{playground/components → components}/segmented.js +2 -2
- package/dist/ui/operation/index.js +261 -236
- package/dist/ui/playground/client.js +5 -4
- package/dist/ui/playground/components/fields.js +1 -1
- package/dist/ui/playground/components/request-panel.js +1 -1
- package/dist/ui/playground/components/response-panel.js +1 -1
- package/dist/ui/playground/components/result-display.js +1 -1
- package/dist/ui/playground/components/server-select.js +1 -1
- package/package.json +5 -5
- package/dist/packages/shared-api/dist/auto-anchor/client.js +0 -20
- package/dist/packages/shared-api/dist/components/popover.js +0 -23
- package/dist/packages/shared-api/dist/utils/merge-refs.js +0 -11
|
@@ -3,8 +3,7 @@ import { useOpenAPI, useRenderContext, useTypeScriptDefinitions } from "../../ut
|
|
|
3
3
|
import { OperationProvider, useOperation } from "../../operation.js";
|
|
4
4
|
import { Badge } from "../../packages/shared-api/dist/components/badge.js";
|
|
5
5
|
import { MethodLabel } from "../components/method-label.js";
|
|
6
|
-
import { AnchorSection } from "../../packages/shared-api/dist/auto-anchor/
|
|
7
|
-
import { AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger, Accordions } from "../../packages/shared-api/dist/components/accordion.js";
|
|
6
|
+
import { AnchorSection, useAnchorLink } from "../../packages/shared-api/dist/auto-anchor/index.js";
|
|
8
7
|
import { Markdown } from "../components/markdown.js";
|
|
9
8
|
import { UsageTabs } from "./usage-tabs.js";
|
|
10
9
|
import { SchemaUI } from "../components/schema.js";
|
|
@@ -12,14 +11,17 @@ import { RequestTabs } from "./request-tabs.js";
|
|
|
12
11
|
import { cn } from "../../utils/cn.js";
|
|
13
12
|
import { SelectTab, SelectTabTrigger, SelectTabs } from "../../packages/shared-api/dist/components/select-tab.js";
|
|
14
13
|
import { Heading } from "../components/heading.js";
|
|
14
|
+
import { Segmented, SegmentedList, SegmentedPanel } from "../components/segmented.js";
|
|
15
15
|
import { EndpointBar } from "../components/endpoint.js";
|
|
16
|
+
import { DialogPopup } from "../components/dialog.js";
|
|
16
17
|
import PlaygroundClient from "../playground/client.js";
|
|
17
|
-
import { Fragment } from "react";
|
|
18
|
+
import { Fragment, useState } from "react";
|
|
18
19
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
19
20
|
import { useTranslations } from "@fuma-translate/react";
|
|
20
|
-
import { Check, Copy } from "lucide-react";
|
|
21
|
+
import { Check, ChevronRight, Copy, Plus, X } from "lucide-react";
|
|
21
22
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
22
23
|
import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
|
|
24
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
23
25
|
import { Callout } from "fumadocs-ui/components/callout";
|
|
24
26
|
//#region src/ui/operation/index.tsx
|
|
25
27
|
function Operation({ type, path, method, operation, pathItem, ...props }) {
|
|
@@ -66,61 +68,48 @@ function OperationContent({ showTitle, showDescription, headingLevel = 2 }) {
|
|
|
66
68
|
if (requestBody) {
|
|
67
69
|
const contentTypes = Object.entries(requestBody.content);
|
|
68
70
|
const items = contentTypes.map(([mediaType]) => ({
|
|
69
|
-
label: /* @__PURE__ */ jsx("code", {
|
|
70
|
-
className: "text-xs",
|
|
71
|
-
children: mediaType
|
|
72
|
-
}),
|
|
71
|
+
label: /* @__PURE__ */ jsx("code", { children: mediaType }),
|
|
73
72
|
value: mediaType
|
|
74
73
|
}));
|
|
75
74
|
bodyNode = /* @__PURE__ */ jsxs(SelectTabs, {
|
|
76
75
|
defaultValue: items[0].value,
|
|
77
76
|
children: [
|
|
78
|
-
/* @__PURE__ */
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
items,
|
|
87
|
-
className: "font-medium"
|
|
88
|
-
}) : /* @__PURE__ */ jsx("p", {
|
|
89
|
-
className: "text-fd-muted-foreground not-prose",
|
|
90
|
-
children: items[0].label
|
|
91
|
-
})]
|
|
77
|
+
/* @__PURE__ */ jsx(SectionHeader, {
|
|
78
|
+
id: "request-body",
|
|
79
|
+
depth: headingLevel,
|
|
80
|
+
title: t("Request Body")
|
|
81
|
+
}),
|
|
82
|
+
requestBody.description && /* @__PURE__ */ jsx("div", {
|
|
83
|
+
className: "mb-3 prose-no-margin text-fd-muted-foreground",
|
|
84
|
+
children: /* @__PURE__ */ jsx(Markdown, { md: requestBody.description })
|
|
92
85
|
}),
|
|
93
|
-
requestBody.description && /* @__PURE__ */ jsx(Markdown, { md: requestBody.description }),
|
|
94
86
|
contentTypes.map(([mediaType, content]) => /* @__PURE__ */ jsx(SelectTab, {
|
|
95
87
|
anchorSegments: ["request-body", mediaType],
|
|
96
88
|
value: mediaType,
|
|
97
|
-
children: /* @__PURE__ */ jsx(
|
|
98
|
-
content,
|
|
89
|
+
children: /* @__PURE__ */ jsx(MediaContent, {
|
|
90
|
+
schema: content.schema,
|
|
99
91
|
required: requestBody.required,
|
|
100
|
-
|
|
92
|
+
selector: /* @__PURE__ */ jsx(CardSelector, { items }),
|
|
93
|
+
request: true
|
|
101
94
|
})
|
|
102
95
|
}, mediaType))
|
|
103
96
|
]
|
|
104
97
|
});
|
|
105
98
|
}
|
|
106
|
-
if (responses.length > 0 && ctx.showResponseSchema !== false) responseNode = /* @__PURE__ */
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}), /* @__PURE__ */ jsx(Accordions, {
|
|
111
|
-
type: "multiple",
|
|
112
|
-
children: responses.map((item) => /* @__PURE__ */ jsx(ResponseAccordion, { item }, item.status))
|
|
113
|
-
})] });
|
|
99
|
+
if (responses.length > 0 && ctx.showResponseSchema !== false) responseNode = /* @__PURE__ */ jsx(ResponseSection, {
|
|
100
|
+
responses,
|
|
101
|
+
headingLevel
|
|
102
|
+
});
|
|
114
103
|
const parameterNode = parameters.map(({ in: location, items }) => {
|
|
115
104
|
const parameterLabel = location === "path" ? t("Path Parameters") : location === "query" ? t("Query Parameters") : location === "header" ? t("Header Parameters") : t("Cookie Parameters");
|
|
116
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(
|
|
105
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(SectionHeader, {
|
|
117
106
|
id: `parameters-${location}`,
|
|
118
107
|
depth: headingLevel,
|
|
119
|
-
|
|
108
|
+
title: parameterLabel
|
|
120
109
|
}), /* @__PURE__ */ jsx(AnchorSection, {
|
|
121
110
|
segments: ["parameters", location],
|
|
122
111
|
children: /* @__PURE__ */ jsx("div", {
|
|
123
|
-
className: "
|
|
112
|
+
className: "rounded-xl border bg-fd-card px-3",
|
|
124
113
|
children: items.map((param) => {
|
|
125
114
|
if (param.schema == null) return;
|
|
126
115
|
const schema = resolve(param.schema);
|
|
@@ -142,87 +131,51 @@ function OperationContent({ showTitle, showDescription, headingLevel = 2 }) {
|
|
|
142
131
|
})] }, location);
|
|
143
132
|
});
|
|
144
133
|
if (security.length > 0) {
|
|
145
|
-
const items = security.map((requirement, i) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
scopes.length > 0 && /* @__PURE__ */ jsx("span", {
|
|
159
|
-
className: "text-fd-muted-foreground",
|
|
160
|
-
children: scopes.join(", ")
|
|
161
|
-
})
|
|
162
|
-
]
|
|
163
|
-
}, key))
|
|
164
|
-
})
|
|
165
|
-
};
|
|
166
|
-
});
|
|
134
|
+
const items = security.map((requirement, i) => ({
|
|
135
|
+
value: String(i),
|
|
136
|
+
label: /* @__PURE__ */ jsx("code", {
|
|
137
|
+
className: "flex min-w-0 items-center gap-1",
|
|
138
|
+
children: requirement.map(({ key, scopes }, j) => /* @__PURE__ */ jsxs(Fragment, { children: [j > 0 && /* @__PURE__ */ jsx(Plus, { className: "size-3 shrink-0 text-fd-muted-foreground" }), /* @__PURE__ */ jsxs("span", {
|
|
139
|
+
className: "truncate",
|
|
140
|
+
children: [key, scopes.length > 0 && /* @__PURE__ */ jsxs("span", {
|
|
141
|
+
className: "text-fd-muted-foreground",
|
|
142
|
+
children: [" ", scopes.join(", ")]
|
|
143
|
+
})]
|
|
144
|
+
})] }, key))
|
|
145
|
+
})
|
|
146
|
+
}));
|
|
167
147
|
authNode = /* @__PURE__ */ jsxs(SelectTabs, {
|
|
168
148
|
defaultValue: items[0].value,
|
|
169
|
-
children: [/* @__PURE__ */
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
},
|
|
186
|
-
}
|
|
149
|
+
children: [/* @__PURE__ */ jsx(SectionHeader, {
|
|
150
|
+
id: "authorization",
|
|
151
|
+
depth: headingLevel,
|
|
152
|
+
title: t("Authorization")
|
|
153
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
154
|
+
className: "overflow-hidden rounded-xl border bg-fd-card",
|
|
155
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
156
|
+
className: "flex h-9 items-center border-b ps-1.5 pe-1 text-[0.8125rem] not-prose",
|
|
157
|
+
children: /* @__PURE__ */ jsx(CardSelector, { items })
|
|
158
|
+
}), security.map((requirement, i) => /* @__PURE__ */ jsx(SelectTab, {
|
|
159
|
+
value: items[i].value,
|
|
160
|
+
className: "px-3",
|
|
161
|
+
children: requirement.map(({ key, scopes, scheme }) => scheme && /* @__PURE__ */ jsx(AuthScheme, {
|
|
162
|
+
scheme,
|
|
163
|
+
scopes
|
|
164
|
+
}, key))
|
|
165
|
+
}, i))]
|
|
166
|
+
})]
|
|
187
167
|
});
|
|
188
168
|
}
|
|
189
|
-
if (callbacks.length > 0) callbacksNode = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(
|
|
169
|
+
if (callbacks.length > 0) callbacksNode = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(SectionHeader, {
|
|
190
170
|
id: "callbacks",
|
|
191
171
|
depth: headingLevel,
|
|
192
|
-
|
|
193
|
-
}), /* @__PURE__ */ jsx(
|
|
194
|
-
|
|
195
|
-
children: callbacks.map((item, i) => /* @__PURE__ */
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
item.name,
|
|
200
|
-
item.path,
|
|
201
|
-
item.method
|
|
202
|
-
],
|
|
203
|
-
children: [/* @__PURE__ */ jsx(AccordionHeader, { children: /* @__PURE__ */ jsx(AccordionTrigger, {
|
|
204
|
-
className: "gap-3",
|
|
205
|
-
children: /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
|
|
206
|
-
className: "font-mono mb-2",
|
|
207
|
-
children: item.name
|
|
208
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
209
|
-
className: "flex items-center gap-2 text-xs",
|
|
210
|
-
children: [/* @__PURE__ */ jsx(MethodLabel, { children: item.method }), /* @__PURE__ */ jsx("code", {
|
|
211
|
-
className: "text-fd-muted-foreground",
|
|
212
|
-
children: item.path
|
|
213
|
-
})]
|
|
214
|
-
})] })
|
|
215
|
-
}) }), /* @__PURE__ */ jsx(AccordionContent, { children: /* @__PURE__ */ jsx("div", {
|
|
216
|
-
className: "border p-3 mb-2 @container prose-no-margin rounded-2xl",
|
|
217
|
-
children: /* @__PURE__ */ jsx(Operation, {
|
|
218
|
-
type: "webhook",
|
|
219
|
-
path,
|
|
220
|
-
headingLevel: headingLevel + 1,
|
|
221
|
-
method: item.method,
|
|
222
|
-
pathItem: item.pathItem,
|
|
223
|
-
operation: item.operation
|
|
224
|
-
})
|
|
225
|
-
}) })]
|
|
172
|
+
title: t("Callbacks")
|
|
173
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
174
|
+
className: "overflow-hidden rounded-xl border bg-fd-card not-prose",
|
|
175
|
+
children: callbacks.map((item, i) => /* @__PURE__ */ jsx(Callback, {
|
|
176
|
+
item,
|
|
177
|
+
path,
|
|
178
|
+
headingLevel: headingLevel + 1
|
|
226
179
|
}, i))
|
|
227
180
|
})] });
|
|
228
181
|
if (type === "operation") {
|
|
@@ -309,140 +262,164 @@ function OperationContent({ showTitle, showDescription, headingLevel = 2 }) {
|
|
|
309
262
|
})]
|
|
310
263
|
});
|
|
311
264
|
}
|
|
312
|
-
function
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
265
|
+
function SectionHeader({ id, depth, title, children }) {
|
|
266
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
267
|
+
className: "flex flex-wrap items-center gap-2 mt-10 mb-3 first:mt-0",
|
|
268
|
+
children: [/* @__PURE__ */ jsx(Heading, {
|
|
269
|
+
id,
|
|
270
|
+
depth,
|
|
271
|
+
className: "my-0! me-auto",
|
|
272
|
+
children: title
|
|
273
|
+
}), children]
|
|
317
274
|
});
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
275
|
+
}
|
|
276
|
+
/** selects the variant shown in a card, like the media type */
|
|
277
|
+
function CardSelector({ items }) {
|
|
278
|
+
if (items.length > 1) return /* @__PURE__ */ jsx(SelectTabTrigger, {
|
|
279
|
+
items,
|
|
280
|
+
className: "h-7 w-auto gap-1 border-0 bg-transparent px-1.5 py-0 text-[0.8125rem] font-medium hover:bg-fd-accent hover:text-fd-accent-foreground focus:ring-0 focus-visible:ring-2 focus-visible:ring-inset data-popup-open:bg-fd-accent"
|
|
281
|
+
});
|
|
282
|
+
return /* @__PURE__ */ jsx("span", {
|
|
283
|
+
className: "min-w-0 px-1.5 font-medium",
|
|
284
|
+
children: items[0].label
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/** the schema of a request body or response in a media type */
|
|
288
|
+
function MediaContent({ schema, required, selector, request = false }) {
|
|
289
|
+
const { method } = useOperation();
|
|
290
|
+
const ts = useTypeScriptDefinitions(schema, {
|
|
291
|
+
name: request ? "RequestBody" : "ResponseBody",
|
|
292
|
+
readOnly: !request,
|
|
293
|
+
writeOnly: request
|
|
294
|
+
});
|
|
295
|
+
if (!schema) return /* @__PURE__ */ jsx("div", {
|
|
296
|
+
className: "not-prose flex h-9 items-center rounded-xl border bg-fd-card ps-1.5 pe-1 text-[0.8125rem]",
|
|
297
|
+
children: selector
|
|
298
|
+
});
|
|
299
|
+
return /* @__PURE__ */ jsx(SchemaUI, {
|
|
323
300
|
client: {
|
|
324
|
-
name: "body",
|
|
301
|
+
name: request ? "body" : "response",
|
|
325
302
|
as: "body",
|
|
326
|
-
required
|
|
303
|
+
required,
|
|
304
|
+
selector,
|
|
305
|
+
actions: ts && /* @__PURE__ */ jsx(CopyTypeScript, {
|
|
306
|
+
code: ts,
|
|
307
|
+
name: request ? "request body" : "response body"
|
|
308
|
+
})
|
|
327
309
|
},
|
|
328
|
-
root:
|
|
329
|
-
readOnly: method === "get",
|
|
330
|
-
writeOnly: method !== "get"
|
|
331
|
-
})
|
|
310
|
+
root: schema,
|
|
311
|
+
readOnly: !request || method === "get",
|
|
312
|
+
writeOnly: request && method !== "get"
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function CopyTypeScript({ code, name }) {
|
|
316
|
+
const t = useTranslations({ note: "TypeScript definitions" });
|
|
317
|
+
const [isChecked, onCopy] = useCopyButton(() => navigator.clipboard.writeText(code));
|
|
318
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
319
|
+
type: "button",
|
|
320
|
+
title: t("Use the {name} type in TypeScript.", { variables: { name } }),
|
|
321
|
+
onClick: onCopy,
|
|
322
|
+
className: cn(buttonVariants({
|
|
323
|
+
variant: "ghost",
|
|
324
|
+
size: "sm"
|
|
325
|
+
}), "-my-1 shrink-0 gap-1.5 text-fd-muted-foreground [&_svg]:size-3.5"),
|
|
326
|
+
children: [isChecked ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(Copy, {}), "TypeScript"]
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function ResponseSection({ responses, headingLevel }) {
|
|
330
|
+
const t = useTranslations({ note: "operation page" });
|
|
331
|
+
const [selected, setSelected] = useState(responses[0].status);
|
|
332
|
+
return /* @__PURE__ */ jsxs(Segmented, {
|
|
333
|
+
value: selected,
|
|
334
|
+
onValueChange: setSelected,
|
|
335
|
+
className: "mt-10 first:mt-0",
|
|
336
|
+
children: [/* @__PURE__ */ jsx(SectionHeader, {
|
|
337
|
+
id: "response-body",
|
|
338
|
+
depth: headingLevel,
|
|
339
|
+
title: t("Response Body"),
|
|
340
|
+
children: /* @__PURE__ */ jsx(SegmentedList, {
|
|
341
|
+
className: "max-w-full overflow-x-auto font-mono [scrollbar-width:none]",
|
|
342
|
+
items: responses.map((item) => ({
|
|
343
|
+
value: item.status,
|
|
344
|
+
label: item.status
|
|
345
|
+
}))
|
|
346
|
+
})
|
|
347
|
+
}), responses.map((item) => /* @__PURE__ */ jsx(ResponseContent, {
|
|
348
|
+
item,
|
|
349
|
+
onLink: () => setSelected(item.status)
|
|
350
|
+
}, item.status))]
|
|
351
|
+
});
|
|
332
352
|
}
|
|
333
|
-
function
|
|
353
|
+
function ResponseContent({ item: { status, response, content }, onLink }) {
|
|
354
|
+
const segments = ["response", status];
|
|
355
|
+
const ref = useAnchorLink(segments, onLink);
|
|
334
356
|
const contentTypes = Object.entries(content);
|
|
335
|
-
const items = contentTypes.map(([
|
|
336
|
-
label: /* @__PURE__ */ jsx("code", {
|
|
337
|
-
|
|
338
|
-
children: key
|
|
339
|
-
}),
|
|
340
|
-
value: key
|
|
357
|
+
const items = contentTypes.map(([mediaType]) => ({
|
|
358
|
+
label: /* @__PURE__ */ jsx("code", { children: mediaType }),
|
|
359
|
+
value: mediaType
|
|
341
360
|
}));
|
|
342
|
-
return /* @__PURE__ */ jsx(
|
|
361
|
+
return /* @__PURE__ */ jsx(SegmentedPanel, {
|
|
343
362
|
value: status,
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
className: "font-mono",
|
|
350
|
-
children: status
|
|
351
|
-
}), items.length === 1 ? /* @__PURE__ */ jsx("p", {
|
|
352
|
-
className: "text-fd-muted-foreground not-prose py-2",
|
|
353
|
-
children: items[0].label
|
|
354
|
-
}) : items.length > 0 && /* @__PURE__ */ jsx(SelectTabTrigger, {
|
|
355
|
-
items,
|
|
356
|
-
className: "my-1.5 py-1"
|
|
357
|
-
})] }), /* @__PURE__ */ jsxs(AccordionContent, {
|
|
358
|
-
className: "ps-4.5 pe-3 border rounded-xl",
|
|
363
|
+
ref,
|
|
364
|
+
children: /* @__PURE__ */ jsx(AnchorSection, {
|
|
365
|
+
segments,
|
|
366
|
+
children: /* @__PURE__ */ jsxs(SelectTabs, {
|
|
367
|
+
defaultValue: items[0]?.value,
|
|
359
368
|
children: [response.description && /* @__PURE__ */ jsx("div", {
|
|
360
|
-
className: "prose-no-margin
|
|
369
|
+
className: "mb-3 prose-no-margin text-fd-muted-foreground",
|
|
361
370
|
children: /* @__PURE__ */ jsx(Markdown, { md: response.description })
|
|
362
371
|
}), contentTypes.map(([mediaType, media]) => /* @__PURE__ */ jsx(SelectTab, {
|
|
363
372
|
value: mediaType,
|
|
364
373
|
anchorSegments: [mediaType],
|
|
365
|
-
children: /* @__PURE__ */ jsx(
|
|
374
|
+
children: /* @__PURE__ */ jsx(MediaContent, {
|
|
375
|
+
schema: media.schema,
|
|
376
|
+
selector: /* @__PURE__ */ jsx(CardSelector, { items })
|
|
377
|
+
})
|
|
366
378
|
}, mediaType))]
|
|
367
|
-
})
|
|
379
|
+
})
|
|
368
380
|
})
|
|
369
381
|
});
|
|
370
382
|
}
|
|
371
|
-
function ResponseAccordionItem({ item: { schema } }) {
|
|
372
|
-
const ts = useTypeScriptDefinitions(schema, {
|
|
373
|
-
name: "ResponseBody",
|
|
374
|
-
readOnly: true,
|
|
375
|
-
writeOnly: false
|
|
376
|
-
});
|
|
377
|
-
return /* @__PURE__ */ jsxs(Fragment$1, { children: [ts && /* @__PURE__ */ jsx(CopyTypeScriptPanel, {
|
|
378
|
-
name: "response body",
|
|
379
|
-
code: ts,
|
|
380
|
-
className: "mb-2"
|
|
381
|
-
}), schema && /* @__PURE__ */ jsx(SchemaUI, {
|
|
382
|
-
client: {
|
|
383
|
-
name: "response",
|
|
384
|
-
as: "body"
|
|
385
|
-
},
|
|
386
|
-
root: schema,
|
|
387
|
-
readOnly: true
|
|
388
|
-
})] });
|
|
389
|
-
}
|
|
390
383
|
function AuthScheme({ scheme, scopes }) {
|
|
391
384
|
const t = useTranslations({ note: "security scheme" });
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
name: scheme.name,
|
|
405
|
-
type: "<token>",
|
|
406
|
-
deprecated: scheme.deprecated,
|
|
407
|
-
scopes,
|
|
408
|
-
children: [scheme.description && /* @__PURE__ */ jsx(Markdown, { md: scheme.description }), /* @__PURE__ */ jsxs("p", { children: [
|
|
409
|
-
t("In"),
|
|
410
|
-
": ",
|
|
411
|
-
/* @__PURE__ */ jsx("code", { children: scheme.in })
|
|
412
|
-
] })]
|
|
413
|
-
});
|
|
414
|
-
if (scheme.type === "openIdConnect") return /* @__PURE__ */ jsx(AuthProperty, {
|
|
415
|
-
name: t("OpenID Connect"),
|
|
416
|
-
type: "<token>",
|
|
417
|
-
deprecated: scheme.deprecated,
|
|
418
|
-
scopes,
|
|
419
|
-
children: scheme.description && /* @__PURE__ */ jsx(Markdown, { md: scheme.description })
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
function AuthProperty({ name, type, deprecated = false, scopes = [], className, ...props }) {
|
|
423
|
-
const t = useTranslations({ note: "security scheme" });
|
|
385
|
+
let name;
|
|
386
|
+
let type = "<token>";
|
|
387
|
+
let location;
|
|
388
|
+
if (scheme.type === "http" || scheme.type === "oauth2") {
|
|
389
|
+
name = t("Authorization");
|
|
390
|
+
type = scheme.type === "http" && scheme.scheme === "basic" ? t("Basic <token>") : t("Bearer <token>");
|
|
391
|
+
location = "header";
|
|
392
|
+
} else if (scheme.type === "apiKey") {
|
|
393
|
+
name = scheme.name;
|
|
394
|
+
location = scheme.in;
|
|
395
|
+
} else if (scheme.type === "openIdConnect") name = t("OpenID Connect");
|
|
396
|
+
else return null;
|
|
424
397
|
return /* @__PURE__ */ jsxs("div", {
|
|
425
|
-
className:
|
|
398
|
+
className: "border-t py-2.5 first:border-t-0",
|
|
426
399
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
427
|
-
className: "flex flex-wrap items-center gap-
|
|
400
|
+
className: "flex flex-wrap items-center gap-2 not-prose",
|
|
428
401
|
children: [
|
|
429
|
-
/* @__PURE__ */ jsx("span", {
|
|
430
|
-
className: "
|
|
402
|
+
location && /* @__PURE__ */ jsx("span", {
|
|
403
|
+
className: "rounded-md border bg-fd-secondary px-1.5 font-mono text-xs leading-5 text-fd-muted-foreground",
|
|
404
|
+
children: location
|
|
405
|
+
}),
|
|
406
|
+
/* @__PURE__ */ jsx("code", {
|
|
407
|
+
className: "text-[0.8125rem] font-medium text-fd-primary",
|
|
431
408
|
children: name
|
|
432
409
|
}),
|
|
433
|
-
/* @__PURE__ */ jsx("
|
|
434
|
-
className: "text-
|
|
410
|
+
/* @__PURE__ */ jsx("code", {
|
|
411
|
+
className: "text-xs text-fd-muted-foreground",
|
|
435
412
|
children: type
|
|
436
413
|
}),
|
|
437
|
-
deprecated && /* @__PURE__ */ jsx(Badge, {
|
|
414
|
+
scheme.deprecated && /* @__PURE__ */ jsx(Badge, {
|
|
438
415
|
color: "red",
|
|
439
416
|
className: "text-xs",
|
|
440
417
|
children: t("Deprecated")
|
|
441
418
|
})
|
|
442
419
|
]
|
|
443
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
444
|
-
className: "prose-no-margin
|
|
445
|
-
children: [
|
|
420
|
+
}), (scheme.description || scopes.length > 0) && /* @__PURE__ */ jsxs("div", {
|
|
421
|
+
className: "mt-1 prose-no-margin text-fd-muted-foreground",
|
|
422
|
+
children: [scheme.description && /* @__PURE__ */ jsx(Markdown, { md: scheme.description }), scopes.length > 0 && /* @__PURE__ */ jsxs("p", { children: [
|
|
446
423
|
t("Scope"),
|
|
447
424
|
": ",
|
|
448
425
|
/* @__PURE__ */ jsx("code", { children: scopes.join(", ") })
|
|
@@ -450,27 +427,75 @@ function AuthProperty({ name, type, deprecated = false, scopes = [], className,
|
|
|
450
427
|
})]
|
|
451
428
|
});
|
|
452
429
|
}
|
|
453
|
-
function
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
430
|
+
function Callback({ item, path, headingLevel }) {
|
|
431
|
+
const t = useTranslations({ note: "operation page" });
|
|
432
|
+
const segments = [
|
|
433
|
+
"callbacks",
|
|
434
|
+
item.name,
|
|
435
|
+
item.path,
|
|
436
|
+
item.method
|
|
437
|
+
];
|
|
438
|
+
const [open, setOpen] = useState(false);
|
|
439
|
+
const ref = useAnchorLink(segments, () => setOpen(true));
|
|
440
|
+
return /* @__PURE__ */ jsxs(Dialog.Root, {
|
|
441
|
+
open,
|
|
442
|
+
onOpenChange: setOpen,
|
|
443
|
+
children: [/* @__PURE__ */ jsxs(Dialog.Trigger, {
|
|
444
|
+
className: "group grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-baseline gap-x-2 gap-y-1 border-t px-4 py-3 text-start transition-colors first:border-t-0 hover:bg-fd-accent/40 focus-visible:bg-fd-accent/40 focus-visible:outline-none",
|
|
445
|
+
children: [
|
|
446
|
+
/* @__PURE__ */ jsx("span", {
|
|
447
|
+
className: "col-span-2 font-mono text-[0.8125rem] font-medium",
|
|
448
|
+
children: item.name
|
|
449
|
+
}),
|
|
450
|
+
/* @__PURE__ */ jsx(ChevronRight, { className: "row-span-2 ms-1 size-4 self-center text-fd-muted-foreground transition-transform group-hover:translate-x-0.5 motion-reduce:transition-none" }),
|
|
451
|
+
/* @__PURE__ */ jsx(MethodLabel, {
|
|
452
|
+
className: "text-xs",
|
|
453
|
+
children: item.method
|
|
454
|
+
}),
|
|
455
|
+
/* @__PURE__ */ jsx("code", {
|
|
456
|
+
className: "text-xs wrap-anywhere text-fd-muted-foreground",
|
|
457
|
+
children: item.path
|
|
458
|
+
})
|
|
459
|
+
]
|
|
460
|
+
}), /* @__PURE__ */ jsxs(DialogPopup, {
|
|
461
|
+
className: "sm:max-h-[min(52rem,calc(100dvh-3rem))] sm:w-[min(64rem,calc(100vw-3rem))]",
|
|
462
|
+
children: [
|
|
463
|
+
/* @__PURE__ */ jsxs("div", {
|
|
464
|
+
className: "flex h-12 shrink-0 items-center gap-2 ps-4 pe-2 sm:ps-5",
|
|
465
|
+
children: [/* @__PURE__ */ jsx(Dialog.Title, {
|
|
466
|
+
className: "truncate font-mono text-sm font-medium",
|
|
467
|
+
children: item.name
|
|
468
|
+
}), /* @__PURE__ */ jsx(Dialog.Close, {
|
|
469
|
+
"aria-label": t("Close"),
|
|
470
|
+
className: cn(buttonVariants({
|
|
471
|
+
variant: "ghost",
|
|
472
|
+
size: "icon-sm"
|
|
473
|
+
}), "ms-auto shrink-0 text-fd-muted-foreground"),
|
|
474
|
+
children: /* @__PURE__ */ jsx(X, {})
|
|
475
|
+
})]
|
|
476
|
+
}),
|
|
477
|
+
/* @__PURE__ */ jsx(EndpointBar, {
|
|
478
|
+
method: item.method,
|
|
479
|
+
route: item.path,
|
|
480
|
+
deprecated: item.operation.deprecated,
|
|
481
|
+
className: "mx-3 mb-3 shrink-0 sm:mx-4"
|
|
482
|
+
}),
|
|
483
|
+
/* @__PURE__ */ jsx("div", {
|
|
484
|
+
ref,
|
|
485
|
+
className: "fd-scroll-container prose min-h-0 flex-1 overflow-y-auto border-t p-5 text-sm @container [--fd-docs-row-1:0px] [--fd-docs-row-3:0px]",
|
|
486
|
+
children: /* @__PURE__ */ jsx(AnchorSection, {
|
|
487
|
+
segments,
|
|
488
|
+
children: /* @__PURE__ */ jsx(Operation, {
|
|
489
|
+
type: "webhook",
|
|
490
|
+
path,
|
|
491
|
+
headingLevel,
|
|
492
|
+
method: item.method,
|
|
493
|
+
pathItem: item.pathItem,
|
|
494
|
+
operation: item.operation
|
|
495
|
+
})
|
|
496
|
+
})
|
|
497
|
+
})
|
|
498
|
+
]
|
|
474
499
|
})]
|
|
475
500
|
});
|
|
476
501
|
}
|
|
@@ -4,9 +4,10 @@ import { useExampleRequests, useOperation } from "../../operation.js";
|
|
|
4
4
|
import { usePlayground } from "../../playground/use-playground.js";
|
|
5
5
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../packages/shared-api/dist/components/select.js";
|
|
6
6
|
import { cn } from "../../utils/cn.js";
|
|
7
|
-
import { Segmented, SegmentedList } from "
|
|
7
|
+
import { Segmented, SegmentedList } from "../components/segmented.js";
|
|
8
8
|
import { DefaultResultDisplay, iconButtonClassName } from "./components/result-display.js";
|
|
9
9
|
import { EndpointBar } from "../components/endpoint.js";
|
|
10
|
+
import { DialogPopup } from "../components/dialog.js";
|
|
10
11
|
import { SchemaProvider } from "../../packages/shared-api/dist/components/playground/schema.js";
|
|
11
12
|
import { UrlBar } from "./components/url-bar.js";
|
|
12
13
|
import { RequestPanel } from "./components/request-panel.js";
|
|
@@ -53,15 +54,15 @@ function PlaygroundClient({ writeOnly = true, readOnly = false, transformAuthInp
|
|
|
53
54
|
}), "group shrink-0 gap-1.5 rounded-lg px-3 transition-[background-color,scale] active:scale-[0.97] motion-reduce:transition-none"),
|
|
54
55
|
children: [/* @__PURE__ */ jsx(Play, { className: "size-3 fill-current transition-transform duration-200 group-hover:translate-x-px motion-reduce:transition-none" }), t("Try in Playground")]
|
|
55
56
|
})
|
|
56
|
-
}), /* @__PURE__ */
|
|
57
|
-
className: "
|
|
57
|
+
}), /* @__PURE__ */ jsx(DialogPopup, {
|
|
58
|
+
className: "sm:h-[min(52rem,calc(100dvh-3rem))] sm:w-[min(80rem,calc(100vw-3rem))]",
|
|
58
59
|
children: /* @__PURE__ */ jsx(PlaygroundDialog, {
|
|
59
60
|
playground,
|
|
60
61
|
renderParameterField,
|
|
61
62
|
renderBodyField,
|
|
62
63
|
ResultDisplay: components?.ResultDisplay
|
|
63
64
|
})
|
|
64
|
-
})]
|
|
65
|
+
})]
|
|
65
66
|
})
|
|
66
67
|
})
|
|
67
68
|
});
|
|
@@ -9,10 +9,10 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
|
9
9
|
import { useArray, useDataEngine, useFieldValue, useObject } from "@fumari/stf";
|
|
10
10
|
import { isPlainObject, stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
11
11
|
import { useTranslations } from "@fuma-translate/react";
|
|
12
|
-
import { Popover } from "@base-ui/react/popover";
|
|
13
12
|
import { Check, ChevronRight, ChevronsUpDown, Info, Plus, Trash2, Upload, X } from "lucide-react";
|
|
14
13
|
import { Select } from "@base-ui/react/select";
|
|
15
14
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
15
|
+
import { Popover } from "@base-ui/react/popover";
|
|
16
16
|
//#region src/ui/playground/components/fields.tsx
|
|
17
17
|
/** the type of a field, at the end of its cell like a unit */
|
|
18
18
|
const typeClassName = "flex shrink-0 items-center pe-1 font-mono text-xs text-fd-muted-foreground";
|