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.
Files changed (50) hide show
  1. package/css/generated/shared.css +1 -1
  2. package/dist/.translations/index.d.ts +63 -20
  3. package/dist/.translations/keys.js +63 -20
  4. package/dist/operation.d.ts +6 -1
  5. package/dist/operation.js +2 -4
  6. package/dist/packages/shared-api/dist/.translations/index.d.ts +1 -0
  7. package/dist/packages/shared-api/dist/.translations/keys.js +1 -0
  8. package/dist/packages/shared-api/dist/auto-anchor/index.js +54 -10
  9. package/dist/packages/shared-api/dist/components/accordion.js +3 -11
  10. package/dist/packages/shared-api/dist/components/collapsible.js +2 -2
  11. package/dist/packages/shared-api/dist/components/schema/client.d.ts +5 -0
  12. package/dist/packages/shared-api/dist/components/schema/client.js +408 -455
  13. package/dist/packages/shared-api/dist/components/select-tab.js +7 -12
  14. package/dist/packages/shared-api/dist/components/select.js +8 -7
  15. package/dist/playground/auth.d.ts +5 -1
  16. package/dist/playground/auth.js +7 -2
  17. package/dist/playground/fetcher.d.ts +8 -0
  18. package/dist/playground/fetcher.js +30 -1
  19. package/dist/playground/index.d.ts +2 -1
  20. package/dist/playground/index.js +2 -1
  21. package/dist/playground/use-playground.d.ts +62 -0
  22. package/dist/playground/use-playground.js +140 -0
  23. package/dist/ui/components/dialog.js +14 -0
  24. package/dist/ui/components/endpoint.js +40 -0
  25. package/dist/ui/components/heading.js +1 -1
  26. package/dist/ui/components/schema.js +1 -1
  27. package/dist/ui/components/segmented.js +21 -0
  28. package/dist/ui/operation/index.js +267 -250
  29. package/dist/ui/playground/client.d.ts +9 -26
  30. package/dist/ui/playground/client.js +150 -389
  31. package/dist/ui/playground/components/fields.js +693 -0
  32. package/dist/ui/playground/components/oauth-panel.js +182 -0
  33. package/dist/ui/playground/components/request-panel.js +480 -0
  34. package/dist/ui/playground/components/response-panel.js +150 -0
  35. package/dist/ui/playground/components/result-display.d.ts +1 -0
  36. package/dist/ui/playground/components/result-display.js +185 -168
  37. package/dist/ui/playground/components/server-select.js +100 -89
  38. package/dist/ui/playground/components/url-bar.js +96 -0
  39. package/dist/ui/playground/status-info.js +32 -45
  40. package/dist/utils/document/load.js +1 -1
  41. package/package.json +12 -12
  42. package/dist/packages/shared-api/dist/auto-anchor/client.js +0 -20
  43. package/dist/packages/shared-api/dist/components/collapsible.d.ts +0 -7
  44. package/dist/packages/shared-api/dist/components/dialog.js +0 -55
  45. package/dist/packages/shared-api/dist/components/input.js +0 -14
  46. package/dist/packages/shared-api/dist/components/label.js +0 -11
  47. package/dist/packages/shared-api/dist/components/playground/inputs.js +0 -439
  48. package/dist/packages/shared-api/dist/components/popover.js +0 -23
  49. package/dist/packages/shared-api/dist/utils/merge-refs.js +0 -11
  50. package/dist/ui/playground/components/oauth-dialog.js +0 -259
@@ -1,439 +0,0 @@
1
- "use client";
2
- import { cn } from "../../utils/cn.js";
3
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select.js";
4
- import { anyFields, useFieldInfo, useResolvedSchema, useSchemaContext, useSchemaUtils } from "./schema.js";
5
- import { Input } from "../input.js";
6
- import { useState } from "react";
7
- import { stringify } from "@fumadocs/json-schema";
8
- import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
9
- import { useArray, useDataEngine, useFieldValue, useObject } from "@fumari/stf";
10
- import { stringifyFieldKey } from "@fumari/stf/lib/utils";
11
- import { useTranslations } from "@fuma-translate/react";
12
- import { cva } from "class-variance-authority";
13
- import { ChevronRight, Plus, Trash2, X } from "lucide-react";
14
- import { buttonVariants } from "fumadocs-ui/components/ui/button";
15
- //#region ../shared-api/dist/components/playground/inputs.js
16
- const fieldLabelVariants = cva("w-full inline-flex items-center gap-0.5");
17
- function FieldLabelType(props) {
18
- return /* @__PURE__ */ jsx("code", {
19
- ...props,
20
- className: cn("text-xs text-fd-muted-foreground", props.className),
21
- children: props.children
22
- });
23
- }
24
- const labelClassName = "text-xs font-medium text-fd-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-70";
25
- function ObjectInput({ field: _field, fieldName, ...props }) {
26
- const { generateDefault } = useSchemaUtils();
27
- const field = useResolvedSchema(_field);
28
- const schemaPropKeys = field.properties ? Object.keys(field.properties) : [];
29
- const { patternProperties = {}, additionalProperties, "x-playground-lazy": isLazy = schemaPropKeys.length > 100 } = field;
30
- const isDynamic = Object.keys(patternProperties).length > 0 || additionalProperties;
31
- const [nextName, setNextName] = useState("");
32
- const { properties, onAppend, onDelete, _objectKeys } = useObject(fieldName, {
33
- lazy: isLazy,
34
- defaultValue: () => generateDefault(field),
35
- properties: field.properties ?? {},
36
- fallback: additionalProperties,
37
- patternProperties
38
- });
39
- const hiddenProperties = isLazy ? schemaPropKeys.filter((key) => !_objectKeys.includes(key)) : [];
40
- const t = useTranslations({ note: "playground" });
41
- return /* @__PURE__ */ jsxs("div", {
42
- ...props,
43
- className: cn("grid grid-cols-1 gap-4 @md:grid-cols-2 *:data-[collapsible=true]:order-last", props.className),
44
- children: [
45
- isLazy && hiddenProperties.length > 0 && /* @__PURE__ */ jsxs(Select, {
46
- value: "",
47
- onValueChange: (v) => v !== null && onAppend(v),
48
- children: [/* @__PURE__ */ jsx(SelectTrigger, {
49
- className: "col-span-full",
50
- children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("Show Property") })
51
- }), /* @__PURE__ */ jsx(SelectContent, { children: hiddenProperties.map((key) => /* @__PURE__ */ jsx(SelectItem, {
52
- value: key,
53
- children: key
54
- }, key)) })]
55
- }),
56
- properties.map((child) => {
57
- let toolbar = null;
58
- if (child.kind === "pattern" || child.kind === "fallback") toolbar = /* @__PURE__ */ jsx("button", {
59
- type: "button",
60
- "aria-label": t("Remove Item", { note: "aria-label" }),
61
- className: cn(buttonVariants({
62
- variant: "outline",
63
- size: "icon-xs"
64
- })),
65
- onClick: () => {
66
- onDelete(child.key);
67
- },
68
- children: /* @__PURE__ */ jsx(Trash2, {})
69
- });
70
- return /* @__PURE__ */ jsx(FieldSet, {
71
- name: child.key,
72
- field: child.info,
73
- fieldName: child.field,
74
- isRequired: field.required?.includes(child.key),
75
- toolbar
76
- }, child.key);
77
- }),
78
- isDynamic && /* @__PURE__ */ jsxs("div", {
79
- className: "flex gap-2 order-last col-span-full",
80
- children: [/* @__PURE__ */ jsx(Input, {
81
- value: nextName,
82
- placeholder: t("Enter Property Name"),
83
- onChange: (e) => setNextName(e.target.value),
84
- onKeyDown: (e) => {
85
- if (e.key === "Enter") {
86
- setNextName("");
87
- onAppend(nextName);
88
- e.preventDefault();
89
- }
90
- }
91
- }), /* @__PURE__ */ jsx("button", {
92
- type: "button",
93
- className: cn(buttonVariants({
94
- variant: "secondary",
95
- size: "sm"
96
- }), "px-4"),
97
- onClick: () => {
98
- onAppend(nextName);
99
- setNextName("");
100
- },
101
- children: t("New")
102
- })]
103
- })
104
- ]
105
- });
106
- }
107
- function JsonInput({ fieldName }) {
108
- const engine = useDataEngine();
109
- const [error, setError] = useState(null);
110
- const [value, setValue] = useState(() => JSON.stringify(engine.init(fieldName, {}), null, 2));
111
- return /* @__PURE__ */ jsxs("div", {
112
- className: "flex flex-col bg-fd-secondary text-fd-secondary-foreground overflow-hidden border rounded-lg",
113
- children: [/* @__PURE__ */ jsx("textarea", {
114
- value,
115
- className: "p-2 h-[240px] text-sm font-mono resize-none focus-visible:outline-none",
116
- onChange: (v) => {
117
- setValue(v.target.value);
118
- try {
119
- engine.update(fieldName, JSON.parse(v.target.value));
120
- setError(null);
121
- } catch (e) {
122
- if (e instanceof Error) setError(e.message);
123
- }
124
- }
125
- }), /* @__PURE__ */ jsx("p", {
126
- className: "p-2 text-xs font-mono border-t text-red-400 empty:hidden",
127
- children: error
128
- })]
129
- });
130
- }
131
- function FieldInput({ field, fieldName, isRequired, ...props }) {
132
- const [value, setValue] = useFieldValue(fieldName);
133
- const id = stringifyFieldKey(fieldName);
134
- const t = useTranslations({ note: "playground" });
135
- if (field.type === "null") return;
136
- if (field.type === "string" && field.format === "binary") return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("label", {
137
- htmlFor: id,
138
- className: cn(buttonVariants({
139
- variant: "secondary",
140
- className: "w-full h-9 gap-2 truncate"
141
- })),
142
- children: value instanceof File ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
143
- className: "text-fd-muted-foreground text-xs",
144
- children: t("Selected")
145
- }), /* @__PURE__ */ jsx("span", {
146
- className: "truncate w-0 flex-1 text-end",
147
- children: value.name
148
- })] }) : /* @__PURE__ */ jsx("span", {
149
- className: "text-fd-muted-foreground",
150
- children: t("Upload")
151
- })
152
- }), /* @__PURE__ */ jsx("input", {
153
- id,
154
- type: "file",
155
- multiple: false,
156
- onChange: (e) => {
157
- if (!e.target.files || e.target.files.length === 0) return;
158
- setValue(e.target.files.item(0));
159
- },
160
- hidden: true
161
- })] });
162
- if (field.enum && field.enum.length > 0) {
163
- const idx = field.enum.indexOf(value);
164
- const items = [...field.enum.map((item, i) => ({
165
- value: String(i),
166
- label: typeof item === "string" ? item : JSON.stringify(item, null, 2)
167
- })), ...!isRequired ? [{
168
- value: "-1",
169
- label: /* @__PURE__ */ jsx("span", {
170
- className: "text-fd-muted-foreground",
171
- children: t("Unset")
172
- })
173
- }] : []];
174
- return /* @__PURE__ */ jsxs(Select, {
175
- items,
176
- value: idx === -1 && isRequired ? "" : String(idx),
177
- onValueChange: (v) => setValue(field.enum[Number(v)]),
178
- children: [/* @__PURE__ */ jsx(SelectTrigger, {
179
- id,
180
- ...props,
181
- children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("Select") })
182
- }), /* @__PURE__ */ jsx(SelectContent, { children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
183
- value: item.value,
184
- children: item.label
185
- }, item.value)) })]
186
- });
187
- }
188
- if (field.type === "boolean") {
189
- const items = [
190
- {
191
- value: "true",
192
- label: "True"
193
- },
194
- {
195
- value: "false",
196
- label: "False"
197
- },
198
- ...!isRequired ? [{
199
- value: "undefined",
200
- label: /* @__PURE__ */ jsx("span", {
201
- className: "text-fd-muted-foreground",
202
- children: t("Unset")
203
- })
204
- }] : []
205
- ];
206
- return /* @__PURE__ */ jsxs(Select, {
207
- items,
208
- value: value === void 0 && isRequired ? "" : String(value),
209
- onValueChange: (value) => setValue(value === "undefined" ? void 0 : value === "true"),
210
- children: [/* @__PURE__ */ jsx(SelectTrigger, {
211
- id,
212
- ...props,
213
- children: /* @__PURE__ */ jsx(SelectValue, {})
214
- }), /* @__PURE__ */ jsx(SelectContent, { children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
215
- value: item.value,
216
- children: item.label
217
- }, item.value)) })]
218
- });
219
- }
220
- const isNumber = field.type === "integer" || field.type === "number";
221
- return /* @__PURE__ */ jsx(Input, {
222
- id,
223
- placeholder: t("Enter value"),
224
- type: isNumber ? "number" : "text",
225
- step: field.type === "integer" ? 1 : void 0,
226
- value: String(value ?? ""),
227
- onChange: (e) => {
228
- if (isNumber) setValue(Number.isNaN(e.target.valueAsNumber) ? void 0 : e.target.valueAsNumber);
229
- else if (!isNumber) setValue(e.target.value);
230
- }
231
- });
232
- }
233
- function FieldSet({ field: _field, fieldName, toolbar, name, isRequired, depth = 0, slotType, collapsible = true, ...props }) {
234
- const { readOnly, writeOnly } = useSchemaContext();
235
- const { generateDefault } = useSchemaUtils();
236
- const field = useResolvedSchema(_field);
237
- const [show, setShow] = useState(!collapsible);
238
- const { info, updateInfo } = useFieldInfo(fieldName, field, depth);
239
- const id = stringifyFieldKey(fieldName);
240
- const dataEngine = useDataEngine();
241
- const [isDefined] = useFieldValue(fieldName, { compute(currentValue) {
242
- return currentValue !== void 0;
243
- } });
244
- if (_field === false) return;
245
- if (field.readOnly && !readOnly) return;
246
- if (field.writeOnly && !writeOnly) return;
247
- if (collapsible && !isDefined && show) setShow(false);
248
- function renderLabelTrigger(schema = field) {
249
- if (!collapsible) return renderLabelName();
250
- return /* @__PURE__ */ jsxs("button", {
251
- type: "button",
252
- className: cn(labelClassName, "inline-flex items-center gap-1 font-mono me-auto"),
253
- onClick: () => {
254
- dataEngine.init(fieldName, generateDefault(schema));
255
- setShow((prev) => !prev);
256
- },
257
- children: [
258
- /* @__PURE__ */ jsx(ChevronRight, { className: cn("size-3.5 text-fd-muted-foreground", show && "rotate-90") }),
259
- name,
260
- isRequired && /* @__PURE__ */ jsx("span", {
261
- className: "text-red-400/80",
262
- children: "*"
263
- })
264
- ]
265
- });
266
- }
267
- function renderLabelName() {
268
- return /* @__PURE__ */ jsxs("span", {
269
- className: cn(labelClassName, "font-mono me-auto"),
270
- children: [name, isRequired && /* @__PURE__ */ jsx("span", {
271
- className: "text-red-400/80 mx-1",
272
- children: "*"
273
- })]
274
- });
275
- }
276
- function renderUnsetButton() {
277
- return /* @__PURE__ */ jsx("button", {
278
- type: "button",
279
- onClick: () => dataEngine.delete(fieldName),
280
- className: "text-fd-muted-foreground hover:text-fd-accent-foreground",
281
- children: /* @__PURE__ */ jsx(X, { className: "size-3.5" })
282
- });
283
- }
284
- if (info.unionField && field[info.unionField] && field[info.unionField].length > 0) {
285
- const union = field[info.unionField];
286
- const showSelect = union.length > 1;
287
- return /* @__PURE__ */ jsx(FieldSet, {
288
- ...props,
289
- name,
290
- fieldName,
291
- isRequired,
292
- field: union[info.oneOf],
293
- depth: depth + 1,
294
- slotType: showSelect ? false : slotType,
295
- collapsible,
296
- toolbar: /* @__PURE__ */ jsxs(Fragment$1, { children: [showSelect && /* @__PURE__ */ jsx("select", {
297
- className: "text-xs font-mono",
298
- value: info.oneOf,
299
- onChange: (e) => {
300
- updateInfo({ oneOf: Number(e.target.value) });
301
- },
302
- children: union.map((item, i) => /* @__PURE__ */ jsx("option", {
303
- value: i,
304
- className: "bg-fd-popover text-fd-popover-foreground",
305
- children: stringify(item, { alias: true })
306
- }, i))
307
- }), toolbar] })
308
- });
309
- }
310
- if (Array.isArray(field.type)) {
311
- const showSelect = field.type.length > 1;
312
- return /* @__PURE__ */ jsx(FieldSet, {
313
- ...props,
314
- name,
315
- fieldName,
316
- isRequired,
317
- field: {
318
- ...field,
319
- type: info.selectedType
320
- },
321
- collapsible,
322
- depth: depth + 1,
323
- slotType: showSelect ? false : slotType,
324
- toolbar: /* @__PURE__ */ jsxs(Fragment$1, { children: [showSelect && /* @__PURE__ */ jsx("select", {
325
- className: "text-xs font-mono",
326
- value: info.selectedType,
327
- onChange: (e) => {
328
- updateInfo({ selectedType: e.target.value });
329
- },
330
- children: field.type.map((item) => /* @__PURE__ */ jsx("option", {
331
- value: item,
332
- className: "bg-fd-popover text-fd-popover-foreground",
333
- children: item
334
- }, item))
335
- }), toolbar] })
336
- });
337
- }
338
- if (field.type === "object") return /* @__PURE__ */ jsxs("fieldset", {
339
- ...props,
340
- "data-collapsible": collapsible,
341
- className: cn("flex flex-col gap-1.5 col-span-full @container", props.className),
342
- children: [/* @__PURE__ */ jsxs("div", {
343
- className: fieldLabelVariants(),
344
- children: [
345
- renderLabelTrigger(field),
346
- slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: stringify(field) }),
347
- toolbar,
348
- !isRequired && isDefined && renderUnsetButton()
349
- ]
350
- }), show && /* @__PURE__ */ jsx(ObjectInput, {
351
- field,
352
- fieldName,
353
- className: "rounded-lg border border-fd-primary/20 bg-fd-background/50 p-2 shadow-sm"
354
- })]
355
- });
356
- if (field.type === "array") return /* @__PURE__ */ jsxs("fieldset", {
357
- ...props,
358
- "data-collapsible": collapsible,
359
- className: cn("flex flex-col gap-1.5 col-span-full", props.className),
360
- children: [/* @__PURE__ */ jsxs("div", {
361
- className: fieldLabelVariants(),
362
- children: [
363
- renderLabelTrigger(),
364
- slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: stringify(field) }),
365
- toolbar,
366
- !isRequired && isDefined && renderUnsetButton()
367
- ]
368
- }), show && /* @__PURE__ */ jsx(ArrayInput, {
369
- fieldName,
370
- items: field.items ?? anyFields,
371
- className: "rounded-lg border border-fd-primary/20 bg-fd-background/50 p-2 shadow-sm"
372
- })]
373
- });
374
- return /* @__PURE__ */ jsxs("fieldset", {
375
- ...props,
376
- className: cn("flex flex-col gap-1.5", props.className),
377
- children: [/* @__PURE__ */ jsxs("label", {
378
- className: fieldLabelVariants(),
379
- htmlFor: id,
380
- children: [
381
- renderLabelName(),
382
- slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: stringify(field) }),
383
- toolbar,
384
- !isRequired && isDefined && renderUnsetButton()
385
- ]
386
- }), /* @__PURE__ */ jsx(FieldInput, {
387
- field,
388
- fieldName,
389
- isRequired
390
- })]
391
- });
392
- }
393
- function ArrayInput({ fieldName, items: itemSchema, ...props }) {
394
- const name = fieldName.at(-1) ?? "";
395
- const { generateDefault } = useSchemaUtils();
396
- const { items, insertItem, removeItem } = useArray(fieldName);
397
- const t = useTranslations({ note: "playground" });
398
- return /* @__PURE__ */ jsxs("div", {
399
- ...props,
400
- className: cn("flex flex-col gap-2", props.className),
401
- children: [items.map((item) => /* @__PURE__ */ jsx(FieldSet, {
402
- name: /* @__PURE__ */ jsxs("span", {
403
- className: "text-fd-muted-foreground",
404
- children: [
405
- name,
406
- "[",
407
- item.index,
408
- "]"
409
- ]
410
- }),
411
- field: itemSchema,
412
- isRequired: true,
413
- fieldName: item.field,
414
- toolbar: /* @__PURE__ */ jsx("button", {
415
- type: "button",
416
- "aria-label": t("Remove Item", { note: "aria-label" }),
417
- className: cn(buttonVariants({
418
- variant: "outline",
419
- size: "icon-xs"
420
- })),
421
- onClick: () => removeItem(item.index),
422
- children: /* @__PURE__ */ jsx(Trash2, {})
423
- })
424
- }, item.index)), /* @__PURE__ */ jsxs("button", {
425
- type: "button",
426
- className: cn(buttonVariants({
427
- variant: "secondary",
428
- className: "gap-1.5 py-2",
429
- size: "sm"
430
- })),
431
- onClick: () => {
432
- insertItem(generateDefault(itemSchema));
433
- },
434
- children: [/* @__PURE__ */ jsx(Plus, { className: "size-4" }), t("New Item")]
435
- })]
436
- });
437
- }
438
- //#endregion
439
- export { FieldInput, FieldSet, JsonInput, ObjectInput };
@@ -1,23 +0,0 @@
1
- "use client";
2
- import { cn } from "../utils/cn.js";
3
- import "react";
4
- import { jsx } from "react/jsx-runtime";
5
- import { Popover } from "@base-ui/react/popover";
6
- //#region ../shared-api/dist/components/popover.js
7
- const Popover$1 = Popover.Root;
8
- const PopoverTrigger = Popover.Trigger;
9
- function PopoverContent({ className, align = "center", sideOffset = 4, ...props }) {
10
- return /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, {
11
- align,
12
- side: "bottom",
13
- sideOffset,
14
- className: "z-50",
15
- children: /* @__PURE__ */ jsx(Popover.Popup, {
16
- className: (s) => cn("z-50 origin-(--transform-origin) overflow-y-auto max-h-(--available-height) min-w-[240px] max-w-[98vw] rounded-xl border bg-fd-popover/60 backdrop-blur-lg p-2 text-sm text-fd-popover-foreground shadow-lg focus-visible:outline-none data-[closed]:animate-fd-popover-out data-[open]:animate-fd-popover-in", typeof className === "function" ? className(s) : className),
17
- ...props
18
- })
19
- }) });
20
- }
21
- Popover.Close;
22
- //#endregion
23
- export { Popover$1 as Popover, PopoverContent, PopoverTrigger };
@@ -1,11 +0,0 @@
1
- //#region ../shared-api/dist/utils/merge-refs.js
2
- function mergeRefs(...refs) {
3
- return (value) => {
4
- refs.forEach((ref) => {
5
- if (typeof ref === "function") ref(value);
6
- else if (ref != null) ref.current = value;
7
- });
8
- };
9
- }
10
- //#endregion
11
- export { mergeRefs };