fumadocs-openapi 9.6.3 → 9.6.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.
@@ -41,14 +41,15 @@ interface OperationConfig extends BaseConfig {
41
41
  * - tag: `{tag}/{file}`
42
42
  * - route: `{endpoint}/{method}` (it will ignore the `name` option)
43
43
  * - none: `{file}` (default)
44
+ * - a function that aligns group name (folder path) to each entry
44
45
  *
45
46
  * @defaultValue 'none'
46
47
  */
47
- groupBy?: 'tag' | 'route' | 'none';
48
+ groupBy?: 'tag' | 'route' | 'none' | ((entry: OutputOperationEntry | OutputWebhookEntry) => string);
48
49
  /**
49
50
  * Specify name for output file
50
51
  */
51
- name?: NameFn<OutputOperationEntry | OutputWebhookEntry>;
52
+ name?: NameFn<OutputOperationEntry | OutputWebhookEntry> | NameFnOptions;
52
53
  }
53
54
  interface TagConfig extends BaseConfig {
54
55
  /**
@@ -58,7 +59,7 @@ interface TagConfig extends BaseConfig {
58
59
  /**
59
60
  * Specify name for output file
60
61
  */
61
- name?: NameFn<OutputTagEntry>;
62
+ name?: NameFn<OutputTagEntry> | NameFnOptions;
62
63
  }
63
64
  interface SchemaConfig extends BaseConfig {
64
65
  /**
@@ -68,10 +69,11 @@ interface SchemaConfig extends BaseConfig {
68
69
  /**
69
70
  * Specify name for output file
70
71
  */
71
- name?: NameFn<OutputSchemaEntry>;
72
+ name?: NameFn<OutputSchemaEntry> | NameFnOptions;
72
73
  }
73
74
  export type SchemaToPagesOptions = SchemaConfig | TagConfig | OperationConfig;
74
- type NameFn<Entry> = ((output: Entry, document: ProcessedDocument['dereferenced']) => string) | {
75
+ type NameFn<Entry> = (output: Entry, document: ProcessedDocument['dereferenced']) => string;
76
+ interface NameFnOptions {
75
77
  /**
76
78
  * The version of algorithm used to generate file paths.
77
79
  *
@@ -81,7 +83,7 @@ type NameFn<Entry> = ((output: Entry, document: ProcessedDocument['dereferenced'
81
83
  * @defaultValue v2
82
84
  */
83
85
  algorithm?: 'v2' | 'v1';
84
- };
86
+ }
85
87
  interface BaseConfig {
86
88
  /**
87
89
  * Custom function to convert names into file names.
@@ -1 +1 @@
1
- {"version":3,"file":"schema-to-pages.d.ts","sourceRoot":"","sources":["../../src/utils/schema-to-pages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,UAAU,SAAS;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,kBAAmB,SAAQ,SAAS;IACnD,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,MAAM,MAAM,WAAW,GACnB,cAAc,GACd,oBAAoB,GACpB,kBAAkB,GACl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B,OAAO,EAAE,oBAAoB,GAC5B,WAAW,EAAE,CAoJf;AA4CD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE/C"}
@@ -21,7 +21,7 @@ export function schemaToPages(schemaId, processed, options) {
21
21
  let nameFn;
22
22
  if (!options.name || typeof options.name !== 'function') {
23
23
  const algorithm = options.name?.algorithm;
24
- nameFn = (out, doc) => defaultNameFn(schemaId, out, doc, options, algorithm);
24
+ nameFn = createDefaultNameFn(options, algorithm);
25
25
  }
26
26
  else {
27
27
  nameFn = options.name;
@@ -43,6 +43,9 @@ export function schemaToPages(schemaId, processed, options) {
43
43
  }
44
44
  return tags.map((tag) => path.join(slugify(tag), `${file}.mdx`));
45
45
  }
46
+ if (typeof groupBy === 'function') {
47
+ return [path.join(slugify(groupBy(entry)), `${file}.mdx`)];
48
+ }
46
49
  return [`${file}.mdx`];
47
50
  }
48
51
  if (options.per === 'file') {
@@ -122,28 +125,31 @@ export function schemaToPages(schemaId, processed, options) {
122
125
  }
123
126
  return files;
124
127
  }
125
- function defaultNameFn(schemaId, result, document, options, algorithm = 'v2') {
128
+ function createDefaultNameFn(options, algorithm = 'v2') {
126
129
  const { slugify = defaultSlugify } = options;
127
- if (result.type === 'tag') {
128
- return slugify(result.tag);
129
- }
130
- if (result.type === 'schema') {
131
- return isUrl(schemaId)
132
- ? 'index'
133
- : path.basename(schemaId, path.extname(schemaId));
134
- }
135
- if (result.type === 'operation') {
136
- const operation = document.paths[result.item.path][result.item.method];
137
- if (algorithm === 'v2' && operation.operationId) {
138
- return operation.operationId;
130
+ return (result, document) => {
131
+ if (result.type === 'tag') {
132
+ return slugify(result.tag);
139
133
  }
140
- return path.join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
141
- }
142
- const hook = document.webhooks[result.item.name][result.item.method];
143
- if (algorithm === 'v2' && hook.operationId) {
144
- return hook.operationId;
145
- }
146
- return slugify(result.item.name);
134
+ if (result.type === 'schema') {
135
+ const schemaId = result.schemaId;
136
+ return isUrl(schemaId)
137
+ ? 'index'
138
+ : path.basename(schemaId, path.extname(schemaId));
139
+ }
140
+ if (result.type === 'operation') {
141
+ const operation = document.paths[result.item.path][result.item.method];
142
+ if (algorithm === 'v2' && operation.operationId) {
143
+ return operation.operationId;
144
+ }
145
+ return path.join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
146
+ }
147
+ const hook = document.webhooks[result.item.name][result.item.method];
148
+ if (algorithm === 'v2' && hook.operationId) {
149
+ return hook.operationId;
150
+ }
151
+ return slugify(result.item.name);
152
+ };
147
153
  }
148
154
  export function isUrl(schemaId) {
149
155
  return schemaId.startsWith('https://') || schemaId.startsWith('http://');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "9.6.3",
3
+ "version": "9.6.5",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -65,8 +65,8 @@
65
65
  "remark-rehype": "^11.1.2",
66
66
  "tinyglobby": "^0.2.15",
67
67
  "xml-js": "^1.6.11",
68
- "fumadocs-core": "16.0.2",
69
- "fumadocs-ui": "16.0.2"
68
+ "fumadocs-core": "16.0.4",
69
+ "fumadocs-ui": "16.0.4"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@scalar/api-client-react": "^1.3.46",