fumadocs-openapi 12.5.1 → 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 (32) 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 +11 -8
  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/requests/string-utils.js +7 -1
  18. package/dist/ui/operation/index.js +2 -2
  19. package/dist/ui/operation/usage-tabs.js +6 -47
  20. package/dist/ui/playground/client.js +7 -4
  21. package/dist/ui/playground/components/oauth-panel.js +2 -2
  22. package/dist/ui/playground/components/request-panel.js +12 -195
  23. package/dist/ui/playground/components/response-panel.js +5 -3
  24. package/dist/ui/playground/components/result-display.d.ts +0 -1
  25. package/dist/ui/playground/components/result-display.js +3 -18
  26. package/dist/ui/playground/components/server-select.js +24 -122
  27. package/dist/ui/playground/components/url-bar.js +6 -47
  28. package/dist/utils/pages/builder.js +2 -2
  29. package/dist/utils/pages/preset-auto.js +15 -4
  30. package/dist/utils/pages/to-static-data.js +2 -7
  31. package/dist/utils/pages/to-text.js +2 -2
  32. package/package.json +4 -4
@@ -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 };
@@ -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.1",
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.1",
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",
@@ -82,7 +82,7 @@
82
82
  "fumadocs-core": "16.17.5",
83
83
  "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.5",
84
84
  "json-schema-typed": "^8.0.2",
85
- "shared-api": "0.2.12",
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"