fumadocs-openapi 11.3.4 → 11.3.5

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.
@@ -6,9 +6,7 @@ import { bundle } from "@fumadocs/api-docs/schema/bundle";
6
6
  */
7
7
  async function loadDocument(input) {
8
8
  try {
9
- let bundled = await bundle(input);
10
- bundled = upgrade(bundled, "3.2");
11
- return { bundled };
9
+ return { bundled: await bundle(input, { transform: (document) => typeof document === "object" && document !== null ? upgrade(document, "3.2") : document }) };
12
10
  } catch (e) {
13
11
  throw new Error(`[OpenAPI] Failed to resolve input: ${input}`, { cause: e });
14
12
  }
@@ -1,3 +1,4 @@
1
+ import { getTagDisplayName } from "../schema.js";
1
2
  import * as path$1 from "node:path";
2
3
  import { dereferenceShallow } from "@fumadocs/api-docs/schema/dereference";
3
4
  //#region src/utils/pages/preset-auto.ts
@@ -31,6 +32,36 @@ function createAutoPreset(options) {
31
32
  const rest = [];
32
33
  const doc = builder.document;
33
34
  const { groupBy = "none" } = options;
35
+ const docTags = /* @__PURE__ */ new Map();
36
+ if (groupBy === "tag") {
37
+ for (const tag of doc.tags ?? []) if (tag.name) docTags.set(tag.name, tag);
38
+ }
39
+ const tagGroups = /* @__PURE__ */ new Map();
40
+ let warnedUntagged = false;
41
+ function tagGroup(name, seen) {
42
+ let group = tagGroups.get(name);
43
+ if (group) return group;
44
+ const tag = docTags.get(name);
45
+ let parent;
46
+ if (tag?.parent) {
47
+ (seen ??= /* @__PURE__ */ new Set()).add(name);
48
+ if (!seen.has(tag.parent)) parent = tagGroup(tag.parent, seen);
49
+ }
50
+ group = {
51
+ type: "group",
52
+ info: {
53
+ title: getTagDisplayName(tag ?? { name }),
54
+ description: tag?.description
55
+ },
56
+ tag,
57
+ entries: [],
58
+ schemaId: builder.id,
59
+ path: path$1.join(parent?.path ?? "", slugify(name))
60
+ };
61
+ tagGroups.set(name, group);
62
+ (parent ? parent.entries : rest).push(group);
63
+ return group;
64
+ }
34
65
  for (const entry of entries) switch (groupBy) {
35
66
  case "route": {
36
67
  const groupName = builder.routePathToFilePath(entry.type === "operation" ? entry.item.path : entry.item.name);
@@ -52,33 +83,25 @@ function createAutoPreset(options) {
52
83
  break;
53
84
  }
54
85
  case "tag": {
55
- let tags = entry.type === "operation" ? dereferenceShallow(doc.paths?.[entry.item.path])?.[entry.item.method]?.tags : dereferenceShallow(doc.webhooks?.[entry.item.name])?.[entry.item.method]?.tags;
56
- if (!tags || tags.length === 0) {
57
- console.warn("When `groupBy` is set to `tag`, make sure a `tags` is defined for every operation schema.");
58
- tags = ["unknown"];
86
+ const operation = entry.type === "operation" ? dereferenceShallow(doc.paths?.[entry.item.path])?.[entry.item.method] : dereferenceShallow(doc.webhooks?.[entry.item.name])?.[entry.item.method];
87
+ const tags = [];
88
+ for (const name of operation?.tags ?? []) {
89
+ const kind = docTags.get(name)?.kind;
90
+ if (!kind || kind === "nav") tags.push(name);
59
91
  }
60
- for (const tag of tags) {
61
- const res = builder.fromTagName(tag);
62
- if (!res) continue;
63
- const groupName = slugify(tag);
64
- let group = groups.get(groupName);
65
- if (!group) {
66
- group = {
67
- type: "group",
68
- info: {
69
- title: res.displayName,
70
- description: res.info.description
71
- },
72
- tag: res.info,
73
- entries: [],
74
- schemaId: builder.id,
75
- path: groupName
76
- };
77
- groups.set(groupName, group);
92
+ if (tags.length === 0) {
93
+ if (!warnedUntagged) {
94
+ warnedUntagged = true;
95
+ console.warn("[Fumadocs OpenAPI] found operations without tags, they will be grouped under \"unknown\".");
78
96
  }
97
+ tags.push("unknown");
98
+ }
99
+ const fileName = `${nameFn.call(builder, entry)}.mdx`;
100
+ for (const name of tags) {
101
+ const group = tagGroup(name);
79
102
  group.entries.push({
80
103
  ...entry,
81
- path: path$1.join(groupName, `${nameFn.call(builder, entry)}.mdx`)
104
+ path: path$1.join(group.path, fileName)
82
105
  });
83
106
  }
84
107
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "11.3.4",
3
+ "version": "11.3.5",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "Docs",
@@ -56,8 +56,8 @@
56
56
  "remark-rehype": "^11.1.2",
57
57
  "shiki": "^4.4.3",
58
58
  "yaml": "^2.9.0",
59
- "@fumari/stf": "1.1.0",
60
- "@fumadocs/api-docs": "0.2.5"
59
+ "@fumadocs/api-docs": "0.2.6",
60
+ "@fumari/stf": "1.1.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@scalar/api-client-react": "^2.0.42",
@@ -69,8 +69,8 @@
69
69
  "json-schema-typed": "^8.0.2",
70
70
  "tsdown": "0.22.14",
71
71
  "xml-js": "^1.6.11",
72
- "fumadocs-core": "16.15.2",
73
- "fumadocs-ui": "npm:@fumadocs/base-ui@16.15.2",
72
+ "fumadocs-ui": "npm:@fumadocs/base-ui@16.15.4",
73
+ "fumadocs-core": "16.15.4",
74
74
  "tsconfig": "0.0.0"
75
75
  },
76
76
  "peerDependencies": {