fumadocs-openapi 12.5.0 → 12.5.2

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 (35) hide show
  1. package/css/generated/shared.css +1 -1
  2. package/dist/.translations/index.d.ts +0 -29
  3. package/dist/.translations/keys.js +1 -30
  4. package/dist/generate-file.js +4 -4
  5. package/dist/packages/shared-api/dist/.translations/index.d.ts +18 -0
  6. package/dist/packages/shared-api/dist/.translations/keys.js +19 -1
  7. package/dist/packages/shared-api/dist/components/defaults.js +13 -19
  8. package/dist/{ui → packages/shared-api/dist}/components/dialog.js +2 -2
  9. package/dist/packages/shared-api/dist/components/example.js +51 -0
  10. package/dist/{ui/playground/components → packages/shared-api/dist/components/playground}/fields.js +16 -15
  11. package/dist/packages/shared-api/dist/components/playground/panels.js +247 -0
  12. package/dist/packages/shared-api/dist/components/playground/param-input.js +54 -0
  13. package/dist/packages/shared-api/dist/components/playground/schema.js +5 -3
  14. package/dist/packages/shared-api/dist/components/playground/server-select.js +130 -0
  15. package/dist/packages/shared-api/dist/components/schema/client.js +1 -1
  16. package/dist/{ui → packages/shared-api/dist}/components/segmented.js +2 -2
  17. package/dist/packages/shared-api/dist/components/select.js +6 -2
  18. package/dist/requests/string-utils.js +7 -1
  19. package/dist/server/index.js +2 -5
  20. package/dist/ui/operation/index.js +20 -13
  21. package/dist/ui/operation/usage-tabs.js +26 -47
  22. package/dist/ui/playground/client.js +7 -4
  23. package/dist/ui/playground/components/oauth-panel.js +2 -2
  24. package/dist/ui/playground/components/request-panel.js +12 -195
  25. package/dist/ui/playground/components/response-panel.js +5 -3
  26. package/dist/ui/playground/components/result-display.d.ts +0 -1
  27. package/dist/ui/playground/components/result-display.js +3 -18
  28. package/dist/ui/playground/components/server-select.js +24 -122
  29. package/dist/ui/playground/components/url-bar.js +6 -47
  30. package/dist/utils/create-page.d.ts +1 -0
  31. package/dist/utils/pages/builder.js +2 -2
  32. package/dist/utils/pages/preset-auto.js +15 -4
  33. package/dist/utils/pages/to-static-data.js +2 -7
  34. package/dist/utils/pages/to-text.js +2 -2
  35. package/package.json +6 -6
@@ -1,18 +1,13 @@
1
1
  "use client";
2
2
  import { useServer } from "../../../utils/use-server.js";
3
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../packages/shared-api/dist/components/select.js";
4
3
  import { cn } from "../../../utils/cn.js";
5
- import { useRef, useState } from "react";
6
- import { jsx, jsxs } from "react/jsx-runtime";
7
- import { StfProvider, useFieldValue, useListener, useStf } from "@fumari/stf";
4
+ import { ServerPopover, ServerVariables } from "../../../packages/shared-api/dist/components/playground/server-select.js";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
6
  import { useTranslations } from "@fuma-translate/react";
9
- import { Check, ChevronDown } from "lucide-react";
10
- import { Popover } from "@base-ui/react/popover";
11
7
  //#region src/ui/playground/components/server-select.tsx
12
8
  /** the base URL of requests, selects the server and edits its variables */
13
9
  function ServerSelect({ className }) {
14
10
  const { servers, server, resolveUrl, setServer, setServerVariables } = useServer();
15
- const [open, setOpen] = useState(false);
16
11
  const t = useTranslations({ note: "playground server select" });
17
12
  const base = resolveUrl().replace(/\/$/, "");
18
13
  if (!servers || servers.length === 0) return /* @__PURE__ */ jsx("span", {
@@ -20,121 +15,28 @@ function ServerSelect({ className }) {
20
15
  children: base
21
16
  });
22
17
  const serverSchema = server ? servers.find((item) => item.url === server.url) : void 0;
23
- return /* @__PURE__ */ jsxs(Popover.Root, {
24
- open,
25
- onOpenChange: setOpen,
26
- children: [/* @__PURE__ */ jsxs(Popover.Trigger, {
27
- className: cn("group flex min-w-0 shrink items-center gap-1 rounded-lg px-1.5 py-1 text-fd-muted-foreground transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring data-popup-open:bg-fd-accent data-popup-open:text-fd-accent-foreground", className),
28
- children: [/* @__PURE__ */ jsx("span", {
29
- className: "truncate",
30
- children: base
31
- }), /* @__PURE__ */ jsx(ChevronDown, { className: "size-3 shrink-0 transition-transform duration-200 group-data-popup-open:rotate-180" })]
32
- }), /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, {
33
- side: "bottom",
34
- align: "start",
35
- sideOffset: 8,
36
- className: "z-50",
37
- children: /* @__PURE__ */ jsxs(Popover.Popup, {
38
- className: "flex max-h-(--available-height) w-[min(26rem,calc(100vw-2rem))] origin-(--transform-origin) flex-col overflow-y-auto rounded-xl border bg-fd-popover p-1 text-sm text-fd-popover-foreground shadow-lg transition-[opacity,scale] duration-150 ease-out outline-none data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0",
39
- children: [
40
- /* @__PURE__ */ jsx("p", {
41
- className: "px-2.5 pt-1.5 pb-1 text-xs font-medium text-fd-muted-foreground",
42
- children: t("Server URL")
43
- }),
44
- servers.map((item) => {
45
- const selected = item.url === server?.url;
46
- return /* @__PURE__ */ jsxs("button", {
47
- type: "button",
48
- "aria-pressed": selected,
49
- onClick: () => {
50
- setServer(item.url);
51
- if (!item.variables) setOpen(false);
52
- },
53
- className: "flex w-full items-start gap-2 rounded-lg px-2.5 py-2 text-start transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground focus-visible:bg-fd-accent focus-visible:outline-none",
54
- children: [/* @__PURE__ */ jsxs("span", {
55
- className: "min-w-0 flex-1",
56
- children: [/* @__PURE__ */ jsx("span", {
57
- className: "block font-mono text-[0.8125rem] break-all",
58
- children: item.url
59
- }), item.description && /* @__PURE__ */ jsx("span", {
60
- className: "mt-0.5 block text-xs text-fd-muted-foreground",
61
- children: item.description
62
- })]
63
- }), selected && /* @__PURE__ */ jsx(Check, { className: "mt-0.5 size-3.5 shrink-0 text-fd-primary" })]
64
- }, item.url);
65
- }),
66
- server?.variables && serverSchema?.variables && /* @__PURE__ */ jsx(ServerVariables, {
67
- defaultValues: server.variables,
68
- schema: serverSchema.variables,
69
- onChange: setServerVariables
70
- }, server.url)
71
- ]
72
- })
73
- }) })]
74
- });
75
- }
76
- function ServerVariables({ defaultValues, onChange, schema }) {
77
- const t = useTranslations({ note: "playground server select" });
78
- const stf = useStf({ defaultValues: () => structuredClone(defaultValues) });
79
- const timerRef = useRef(null);
80
- useListener({
81
- stf,
82
- onUpdate() {
83
- if (timerRef.current !== null) window.clearTimeout(timerRef.current);
84
- timerRef.current = window.setTimeout(() => onChange(stf.dataEngine.getData()), 300);
85
- }
86
- });
87
- return /* @__PURE__ */ jsx(StfProvider, {
88
- value: stf,
89
- children: /* @__PURE__ */ jsxs("div", {
90
- className: "mt-1 flex flex-col gap-2.5 border-t px-2.5 pt-2.5 pb-2",
91
- children: [/* @__PURE__ */ jsx("p", {
92
- className: "text-xs font-medium text-fd-muted-foreground",
93
- children: t("Variables")
94
- }), Object.entries(schema).map(([key, variable]) => /* @__PURE__ */ jsxs("div", {
95
- className: "grid grid-cols-[minmax(0,2fr)_minmax(0,3fr)] items-center gap-3",
96
- children: [/* @__PURE__ */ jsxs("label", {
97
- htmlFor: `server-${key}`,
98
- className: "min-w-0",
99
- children: [/* @__PURE__ */ jsx("span", {
100
- className: "block truncate font-mono text-[0.8125rem]",
101
- children: key
102
- }), variable.description && /* @__PURE__ */ jsx("span", {
103
- className: "block text-xs text-fd-muted-foreground",
104
- children: variable.description
105
- })]
106
- }), /* @__PURE__ */ jsx(VariableInput, {
107
- fieldName: key,
108
- variable
109
- })]
110
- }, key))]
111
- })
112
- });
113
- }
114
- function VariableInput({ fieldName, variable }) {
115
- const t = useTranslations({ note: "playground server select" });
116
- const id = `server-${fieldName}`;
117
- const [value, setValue] = useFieldValue([fieldName], { compute(currentValue) {
118
- return typeof currentValue === "string" ? currentValue : void 0;
119
- } });
120
- if (variable.enum) return /* @__PURE__ */ jsxs(Select, {
121
- value: value ?? null,
122
- onValueChange: (v) => v !== null && setValue(v),
123
- children: [/* @__PURE__ */ jsx(SelectTrigger, {
124
- id,
125
- className: "h-8 py-1 text-[0.8125rem]",
126
- children: /* @__PURE__ */ jsx(SelectValue, {})
127
- }), /* @__PURE__ */ jsx(SelectContent, { children: variable.enum.map((item) => /* @__PURE__ */ jsx(SelectItem, {
128
- value: item,
129
- children: item
130
- }, item)) })]
131
- });
132
- return /* @__PURE__ */ jsx("input", {
133
- id,
134
- value: value ?? "",
135
- onChange: (e) => setValue(e.target.value),
136
- placeholder: t("Enter Value"),
137
- className: "h-8 w-full rounded-md border bg-fd-secondary px-2 font-mono text-[0.8125rem] text-fd-secondary-foreground outline-none placeholder:text-fd-muted-foreground focus-visible:ring-2 focus-visible:ring-fd-ring"
18
+ return /* @__PURE__ */ jsx(ServerPopover, {
19
+ label: base,
20
+ title: t("Server URL"),
21
+ value: server?.url,
22
+ onValueChange: setServer,
23
+ className,
24
+ options: servers.map((item) => ({
25
+ value: item.url,
26
+ hasVariables: item.variables !== void 0,
27
+ label: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
28
+ className: "block font-mono text-[0.8125rem] break-all",
29
+ children: item.url
30
+ }), item.description && /* @__PURE__ */ jsx("span", {
31
+ className: "mt-0.5 block text-xs text-fd-muted-foreground",
32
+ children: item.description
33
+ })] })
34
+ })),
35
+ children: server?.variables && serverSchema?.variables && /* @__PURE__ */ jsx(ServerVariables, {
36
+ defaultValues: server.variables,
37
+ variables: serverSchema.variables,
38
+ onChange: setServerVariables
39
+ }, server.url)
138
40
  });
139
41
  }
140
42
  //#endregion
@@ -1,11 +1,10 @@
1
1
  "use client";
2
2
  import { MethodLabel } from "../../components/method-label.js";
3
3
  import { cn } from "../../../utils/cn.js";
4
- import { useResolvedSchema } from "../../../packages/shared-api/dist/components/playground/schema.js";
5
4
  import { Spinner } from "../../../packages/shared-api/dist/components/spinner.js";
5
+ import { ParamInput } from "../../../packages/shared-api/dist/components/playground/param-input.js";
6
6
  import ServerSelect from "./server-select.js";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
- import { useFieldValue } from "@fumari/stf";
9
8
  import { useTranslations } from "@fuma-translate/react";
10
9
  import { SendHorizontal } from "lucide-react";
11
10
  import { buttonVariants } from "fumadocs-ui/components/ui/button";
@@ -27,9 +26,12 @@ function UrlBar({ method, route, parameters, deprecated = false, loading }) {
27
26
  children: route.split(/(\{[^}]+\})/).map((part, i) => {
28
27
  if (!part.startsWith("{") || !part.endsWith("}")) return part;
29
28
  const name = part.slice(1, -1);
30
- return /* @__PURE__ */ jsx(PathParam, {
29
+ const param = parameters.find((p) => p.name === name);
30
+ return /* @__PURE__ */ jsx(ParamInput, {
31
+ fieldName: ["path", name],
31
32
  name,
32
- param: parameters.find((p) => p.name === name)
33
+ schema: param?.schema,
34
+ description: param?.description
33
35
  }, i);
34
36
  })
35
37
  })]
@@ -49,48 +51,5 @@ function UrlBar({ method, route, parameters, deprecated = false, loading }) {
49
51
  })]
50
52
  });
51
53
  }
52
- function PathParam({ name, param }) {
53
- const schema = useResolvedSchema(param?.schema ?? true);
54
- const [value, setValue] = useFieldValue(["path", name]);
55
- const text = value == null ? "" : String(value);
56
- const className = "mx-px rounded-md bg-fd-primary/10 px-1.5 py-0.5 text-fd-primary outline-none transition-colors placeholder:text-fd-primary/50 hover:bg-fd-primary/15 focus-visible:bg-fd-primary/15 focus-visible:ring-2 focus-visible:ring-fd-primary/30";
57
- if (schema.enum && schema.enum.length > 0) {
58
- const options = schema.enum;
59
- return /* @__PURE__ */ jsxs("select", {
60
- "aria-label": name,
61
- title: param?.description,
62
- value: String(options.indexOf(value)),
63
- onChange: (e) => setValue(options[Number(e.target.value)]),
64
- className: cn(className, "cursor-pointer appearance-none"),
65
- children: [/* @__PURE__ */ jsx("option", {
66
- value: "-1",
67
- disabled: true,
68
- className: "bg-fd-popover text-fd-popover-foreground",
69
- children: name
70
- }), options.map((item, i) => /* @__PURE__ */ jsx("option", {
71
- value: i,
72
- className: "bg-fd-popover text-fd-popover-foreground",
73
- children: String(item)
74
- }, i))]
75
- });
76
- }
77
- const isNumber = schema.type === "integer" || schema.type === "number";
78
- return /* @__PURE__ */ jsx("input", {
79
- "aria-label": name,
80
- title: param?.description,
81
- value: text,
82
- placeholder: name,
83
- autoComplete: "off",
84
- spellCheck: false,
85
- inputMode: isNumber ? "decimal" : void 0,
86
- onChange: (e) => {
87
- const v = e.target.value;
88
- if (v.length === 0) setValue(void 0);
89
- else setValue(isNumber && !Number.isNaN(Number(v)) ? Number(v) : v);
90
- },
91
- style: { width: `calc(${Math.max(text.length, name.length, 1)}ch + 0.75rem)` },
92
- className
93
- });
94
- }
95
54
  //#endregion
96
55
  export { UrlBar };
@@ -119,6 +119,7 @@ export interface OpenAPIRenderOptions {
119
119
  operation: OperationObject;
120
120
  }, ctx: RenderContext) => ReactNode;
121
121
  renderAPIExampleLayout?: (slots: {
122
+ /** the select of example requests, only with `renderAPIExampleUsageTabs`, default usage tabs have it in their title */
122
123
  selector: ReactNode;
123
124
  usageTabs: ReactNode;
124
125
  responseTabs: ReactNode;
@@ -1,12 +1,12 @@
1
+ import { dereferenceBundledDocument } from "../document/dereference.js";
1
2
  import { idToTitle } from "../../packages/shared-api/dist/utils/id-to-title.js";
2
3
  import { getTagDisplayName, methodKeys } from "../schema.js";
3
- import { createMagicProxy } from "@scalar/json-magic/magic-proxy";
4
4
  import { dereference } from "@fumadocs/json-schema";
5
5
  //#region src/utils/pages/builder.ts
6
6
  function fromSchema(schemaId, bundled, config) {
7
7
  const files = [];
8
8
  const { toPages } = config;
9
- const document = createMagicProxy(bundled);
9
+ const document = dereferenceBundledDocument(bundled).dereferenced;
10
10
  toPages({
11
11
  id: schemaId,
12
12
  document,
@@ -156,8 +156,9 @@ function createAutoPreset(options) {
156
156
  return;
157
157
  }
158
158
  if (options.per === "tag") {
159
- const tags = doc.tags ?? [];
160
- for (const tag of tags) {
159
+ const operations = groupByTag(items.operations);
160
+ const webhooks = groupByTag(items.webhooks);
161
+ for (const tag of doc.tags ?? []) {
161
162
  const { displayName } = builder.fromTag(tag);
162
163
  const entry = {
163
164
  type: "page",
@@ -167,8 +168,8 @@ function createAutoPreset(options) {
167
168
  title: displayName,
168
169
  description: tag.description
169
170
  },
170
- webhooks: items.webhooks.filter((webhook) => webhook.tags?.includes(tag.name)),
171
- operations: items.operations.filter((op) => op.tags?.includes(tag.name)),
171
+ webhooks: webhooks.get(tag.name) ?? [],
172
+ operations: operations.get(tag.name) ?? [],
172
173
  tag
173
174
  };
174
175
  entry.path = `${nameFn.call(builder, entry)}.mdx`;
@@ -206,5 +207,15 @@ function createAutoPreset(options) {
206
207
  for (const entry of group(builder, entries)) builder.create(entry);
207
208
  } };
208
209
  }
210
+ /** items by the names of their tags, in their order */
211
+ function groupByTag(items) {
212
+ const out = /* @__PURE__ */ new Map();
213
+ for (const item of items) for (const name of item.tags ?? []) {
214
+ const list = out.get(name);
215
+ if (!list) out.set(name, [item]);
216
+ else if (list.at(-1) !== item) list.push(item);
217
+ }
218
+ return out;
219
+ }
209
220
  //#endregion
210
221
  export { createAutoPreset };
@@ -1,15 +1,10 @@
1
+ import { dereferenceBundledDocument } from "../document/dereference.js";
1
2
  import { idToTitle } from "../../packages/shared-api/dist/utils/id-to-title.js";
2
- import { createMagicProxy } from "@scalar/json-magic/magic-proxy";
3
3
  import { dereference } from "@fumadocs/json-schema";
4
4
  import Slugger from "github-slugger";
5
5
  //#region src/utils/pages/to-static-data.ts
6
- const proxyCache = /* @__PURE__ */ new WeakMap();
7
6
  function toStaticData(page, doc) {
8
- let proxied = proxyCache.get(doc);
9
- if (!proxied) {
10
- proxied = createMagicProxy(doc);
11
- proxyCache.set(doc, proxied);
12
- }
7
+ const proxied = dereferenceBundledDocument(doc).dereferenced;
13
8
  const slugger = new Slugger();
14
9
  const toc = [];
15
10
  const structuredData = {
@@ -1,4 +1,4 @@
1
- import { doubleQuote } from "../../requests/string-utils.js";
1
+ import { doubleQuote, jsxString } from "../../requests/string-utils.js";
2
2
  import { getPageProps } from "./builder.js";
3
3
  import { toStaticData } from "./to-static-data.js";
4
4
  import { stringify } from "yaml";
@@ -49,7 +49,7 @@ function generateDocument(frontmatter, content, options) {
49
49
  return out.join("\n\n");
50
50
  }
51
51
  function pageContent({ showTitle, showDescription, document, webhooks, operations }) {
52
- const propStrs = [`document=${doubleQuote(document)}`];
52
+ const propStrs = [`document=${jsxString(document)}`];
53
53
  if (webhooks) propStrs.push(`webhooks={${JSON.stringify(webhooks.map((item) => ({
54
54
  name: item.name,
55
55
  method: item.method
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "12.5.0",
3
+ "version": "12.5.2",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "Docs",
@@ -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.2",
58
58
  "@fumari/json-schema-ts": "^1.0.2",
59
- "@fumari/stf": "^1.1.1",
59
+ "@fumari/stf": "^1.1.2",
60
60
  "@scalar/json-magic": "^0.15.4",
61
61
  "@scalar/openapi-upgrader": "^0.4.1",
62
62
  "chokidar": "^5.0.0",
@@ -79,10 +79,10 @@
79
79
  "@types/react-dom": "^19.3.0",
80
80
  "fast-content-type-parse": "^4.0.0",
81
81
  "fuma-cli": "^0.3.1",
82
- "fumadocs-core": "16.17.4",
83
- "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.4",
82
+ "fumadocs-core": "16.17.5",
83
+ "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.5",
84
84
  "json-schema-typed": "^8.0.2",
85
- "shared-api": "0.2.11",
85
+ "shared-api": "0.2.13",
86
86
  "tsconfig": "0.0.0",
87
87
  "tsdown": "0.23.0",
88
88
  "xml-js": "^1.6.11"