fumadocs-openapi 8.1.12 → 9.0.1

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 (49) hide show
  1. package/dist/generate-file.d.ts +55 -20
  2. package/dist/generate-file.d.ts.map +1 -1
  3. package/dist/generate-file.js +93 -68
  4. package/dist/generate.d.ts +10 -10
  5. package/dist/generate.d.ts.map +1 -1
  6. package/dist/generate.js +33 -64
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +0 -1
  10. package/dist/playground/inputs.d.ts +4 -8
  11. package/dist/playground/inputs.d.ts.map +1 -1
  12. package/dist/playground/inputs.js +56 -37
  13. package/dist/render/api-page.d.ts.map +1 -1
  14. package/dist/render/markdown.d.ts.map +1 -1
  15. package/dist/render/markdown.js +15 -11
  16. package/dist/render/operation/api-example.js +10 -6
  17. package/dist/render/operation/index.d.ts +1 -1
  18. package/dist/render/operation/index.d.ts.map +1 -1
  19. package/dist/render/operation/index.js +4 -16
  20. package/dist/render/renderer.d.ts +1 -0
  21. package/dist/render/renderer.d.ts.map +1 -1
  22. package/dist/render/schema.d.ts +5 -15
  23. package/dist/render/schema.d.ts.map +1 -1
  24. package/dist/render/schema.js +178 -97
  25. package/dist/server/create.d.ts +1 -7
  26. package/dist/server/create.d.ts.map +1 -1
  27. package/dist/server/proxy.d.ts +11 -1
  28. package/dist/server/proxy.d.ts.map +1 -1
  29. package/dist/server/proxy.js +10 -3
  30. package/dist/server/source-api.d.ts +3 -2
  31. package/dist/server/source-api.d.ts.map +1 -1
  32. package/dist/ui/client.js +1 -1
  33. package/dist/ui/index.d.ts +1 -1
  34. package/dist/ui/index.d.ts.map +1 -1
  35. package/dist/ui/index.js +4 -4
  36. package/dist/utils/combine-schema.d.ts.map +1 -1
  37. package/dist/utils/combine-schema.js +22 -27
  38. package/dist/utils/generate-document.d.ts +4 -7
  39. package/dist/utils/generate-document.d.ts.map +1 -1
  40. package/dist/utils/generate-document.js +10 -6
  41. package/dist/utils/process-document.d.ts +1 -1
  42. package/dist/utils/process-document.d.ts.map +1 -1
  43. package/dist/utils/process-document.js +8 -5
  44. package/dist/utils/schema-to-string.d.ts.map +1 -1
  45. package/dist/utils/schema-to-string.js +8 -21
  46. package/dist/utils/schema.d.ts +1 -1
  47. package/dist/utils/schema.d.ts.map +1 -1
  48. package/dist/utils/schema.js +5 -8
  49. package/package.json +12 -12
@@ -1,38 +1,73 @@
1
- import { type GenerateOptions } from './generate.js';
2
- export interface Config extends GenerateOptions {
1
+ import { type GenerateOptions, type GeneratePageOutput, type GenerateTagOutput } from './generate.js';
2
+ import { type ProcessedDocument } from './utils/process-document.js';
3
+ interface GenerateFileOutput {
3
4
  /**
4
- * Schema files
5
+ * The original schema file path/url from `input`
5
6
  */
6
- input: string[] | string;
7
+ pathOrUrl: string;
8
+ content: string;
9
+ }
10
+ interface OperationConfig extends BaseConfig {
7
11
  /**
8
- * Output directory
12
+ * Generate a page for each API endpoint/operation (default).
9
13
  */
10
- output: string;
14
+ per?: 'operation';
11
15
  /**
12
- * tag: Generate a page for each tag
13
- * file: Generate a page for each schema
14
- * operation: Generate a page for each API endpoint/operation
16
+ * Group output using folders (Only works on `operation` mode)
17
+ * - tag: `{tag}/{file}`
18
+ * - route: `{endpoint}/{method}` (it will ignore the `name` option)
19
+ * - none: `{file}` (default)
15
20
  *
16
- * @defaultValue 'operation'
21
+ * @defaultValue 'none'
17
22
  */
18
- per?: 'tag' | 'file' | 'operation';
23
+ groupBy?: 'tag' | 'route' | 'none';
19
24
  /**
20
25
  * Specify name for output file
21
26
  */
22
- name?: (type: 'file' | 'tag', name: string) => string;
27
+ name?: ((output: GeneratePageOutput, document: ProcessedDocument['document']) => string) | BaseName;
28
+ }
29
+ interface TagConfig extends BaseConfig {
23
30
  /**
24
- * Group output using folders (Only works on `operation` mode)
25
- *
26
- * @deprecated Use `groupBy` instead
27
- * @defaultValue false
31
+ * Generate a page for each tag.
28
32
  */
29
- groupByFolder?: boolean;
33
+ per: 'tag';
30
34
  /**
31
- * Group output using folders (Only works on `operation` mode)
35
+ * Specify name for output file
36
+ */
37
+ name?: ((output: GenerateTagOutput, document: ProcessedDocument['document']) => string) | BaseName;
38
+ }
39
+ interface FileConfig extends BaseConfig {
40
+ /**
41
+ * Generate a page for each schema file.
42
+ */
43
+ per: 'file';
44
+ /**
45
+ * Specify name for output file
46
+ */
47
+ name?: ((output: GenerateFileOutput, document: ProcessedDocument['document']) => string) | BaseName;
48
+ }
49
+ export type Config = FileConfig | TagConfig | OperationConfig;
50
+ interface BaseName {
51
+ /**
52
+ * The version of algorithm used to generate file paths.
32
53
  *
33
- * @defaultValue 'none'
54
+ * v1: Fumadocs OpenAPI v8
55
+ * v2: Fumadocs OpenAPI v9
56
+ *
57
+ * @defaultValue v2
34
58
  */
35
- groupBy?: 'tag' | 'route' | 'none';
59
+ algorithm?: 'v2' | 'v1';
60
+ }
61
+ interface BaseConfig extends GenerateOptions {
62
+ /**
63
+ * Schema files
64
+ */
65
+ input: string[] | string;
66
+ /**
67
+ * Output directory
68
+ */
69
+ output: string;
36
70
  }
37
71
  export declare function generateFiles(options: Config): Promise<void>;
72
+ export {};
38
73
  //# sourceMappingURL=generate-file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-file.d.ts","sourceRoot":"","sources":["../src/generate-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,eAAe,EAIrB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAEzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,WAAW,CAAC;IAEnC;;OAEG;IACH,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,IAAI,EAAE,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AAM,EAAE,kBAAkB,EAC1B,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,KACpC,MAAM,CAAC,GACZ,QAAQ,CAAC;CACd;AAED,MAAM,MAAM,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,eAAe,CAAC;AAE9D,UAAU,QAAQ;IAChB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACzB;AAED,UAAU,UAAW,SAAQ,eAAe;IAC1C;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAEzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BlE"}
@@ -1,9 +1,11 @@
1
1
  import { mkdir, writeFile } from 'node:fs/promises';
2
2
  import * as path from 'node:path';
3
+ import { resolve } from 'node:path';
3
4
  import { glob } from 'tinyglobby';
4
5
  import { generateAll, generatePages, generateTags, } from './generate.js';
6
+ import { processDocument, } from './utils/process-document.js';
5
7
  export async function generateFiles(options) {
6
- const { input, output, name: nameFn, per = 'operation', groupBy = 'none', cwd = process.cwd(), } = options;
8
+ const { input, cwd = process.cwd() } = options;
7
9
  const urlInputs = [];
8
10
  const fileInputs = [];
9
11
  for (const v of typeof input === 'string' ? [input] : input) {
@@ -21,91 +23,109 @@ export async function generateFiles(options) {
21
23
  if (resolvedInputs.length === 0) {
22
24
  throw new Error(`No input files found. Tried resolving: ${typeof input === 'string' ? input : input.join(', ')}`);
23
25
  }
24
- function getOutputPaths(result) {
25
- let file;
26
- if (result.pathItem.summary) {
27
- file = getFilename(result.pathItem.summary);
28
- }
29
- else if (result.type === 'operation') {
30
- file = path.join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
31
- }
32
- else {
33
- file = getFilename(result.item.name);
26
+ await Promise.all(resolvedInputs.map((input) => generateFromDocument(input, options)));
27
+ }
28
+ async function generateFromDocument(pathOrUrl, options) {
29
+ const { output, cwd = process.cwd() } = options;
30
+ let nameFn;
31
+ if (!options.name || typeof options.name !== 'function') {
32
+ const { algorithm = 'v2' } = options.name ?? {};
33
+ nameFn = (output, document) => {
34
+ if (options.per === 'tag') {
35
+ const result = output;
36
+ return getFilename(result.tag);
37
+ }
38
+ if (options.per === 'file') {
39
+ return isUrl(pathOrUrl)
40
+ ? 'index'
41
+ : path.basename(pathOrUrl, path.extname(pathOrUrl));
42
+ }
43
+ const result = output;
44
+ if (result.type === 'operation') {
45
+ const operation = document.paths[result.item.path][result.item.method];
46
+ if (algorithm === 'v2' && operation.operationId) {
47
+ return operation.operationId;
48
+ }
49
+ return path.join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
50
+ }
51
+ const hook = document.webhooks[result.item.name][result.item.method];
52
+ if (algorithm === 'v2' && hook.operationId) {
53
+ return hook.operationId;
54
+ }
55
+ return getFilename(result.item.name);
56
+ };
57
+ }
58
+ else {
59
+ nameFn = options.name;
60
+ }
61
+ const document = await dereference(pathOrUrl, options);
62
+ const outputDir = path.join(cwd, output);
63
+ async function write(file, content) {
64
+ await mkdir(path.dirname(file), { recursive: true });
65
+ await writeFile(file, content);
66
+ }
67
+ function getOutputPaths(groupBy = 'none', result) {
68
+ const file = nameFn(result, document.document);
69
+ if (groupBy === 'route') {
70
+ return [
71
+ path.join(result.type === 'operation' ? result.item.path : result.item.name, result.item.method) + '.mdx',
72
+ ];
34
73
  }
35
- const outPaths = [];
36
74
  if (groupBy === 'tag') {
37
- let tags = result.operation.tags;
75
+ let tags = result.type === 'operation'
76
+ ? document.document.paths[result.item.path][result.item.method]
77
+ .tags
78
+ : document.document.webhooks[result.item.name][result.item.method]
79
+ .tags;
38
80
  if (!tags || tags.length === 0) {
39
81
  console.warn('When `groupBy` is set to `tag`, make sure a `tags` is defined for every operation schema.');
40
82
  tags = ['unknown'];
41
83
  }
42
- for (const tag of tags) {
43
- outPaths.push(path.join(getFilename(tag), `${file}.mdx`));
44
- }
84
+ return tags.map((tag) => path.join(getFilename(tag), `${file}.mdx`));
45
85
  }
46
- else {
47
- outPaths.push(`${file}.mdx`);
48
- }
49
- return outPaths;
86
+ return [`${file}.mdx`];
50
87
  }
51
- const metaFiles = new Set();
52
- async function writeMetafile(file, data) {
53
- if (metaFiles.has(file))
54
- return;
55
- metaFiles.add(file);
56
- await write(file, JSON.stringify(data, null, 2));
57
- console.log(`Generated Meta: ${file}`);
88
+ if (options.per === 'file') {
89
+ const result = await generateAll(pathOrUrl, document, options);
90
+ const filename = nameFn({
91
+ pathOrUrl,
92
+ content: result,
93
+ }, document.document);
94
+ const outPath = path.join(outputDir, `${filename}.mdx`);
95
+ await write(outPath, result);
96
+ console.log(`Generated: ${outPath}`);
58
97
  }
59
- async function generateFromDocument(pathOrUrl) {
60
- const outputDir = path.join(cwd, output);
61
- if (per === 'file') {
62
- let filename = isUrl(pathOrUrl)
63
- ? 'index'
64
- : path.basename(pathOrUrl, path.extname(pathOrUrl));
65
- if (nameFn)
66
- filename = nameFn('file', filename);
98
+ else if (options.per === 'tag') {
99
+ const results = await generateTags(pathOrUrl, document, options);
100
+ for (const result of results) {
101
+ const filename = nameFn(result, document.document);
67
102
  const outPath = path.join(outputDir, `${filename}.mdx`);
68
- const result = await generateAll(pathOrUrl, options);
69
- await write(outPath, result);
103
+ await write(outPath, result.content);
70
104
  console.log(`Generated: ${outPath}`);
71
105
  }
72
- if (per === 'operation') {
73
- const results = await generatePages(pathOrUrl, options);
74
- const mapping = new Map();
75
- for (const result of results) {
76
- const outputPaths = getOutputPaths(result);
77
- for (const outputPath of outputPaths) {
78
- mapping.set(outputPath, result);
79
- }
106
+ }
107
+ else {
108
+ const results = await generatePages(pathOrUrl, document, options);
109
+ const mapping = new Map();
110
+ for (const result of results) {
111
+ for (const outputPath of getOutputPaths(options.groupBy, result)) {
112
+ mapping.set(outputPath, result);
80
113
  }
81
- for (const [key, output] of mapping.entries()) {
82
- let outputPath = key;
114
+ }
115
+ for (const [key, output] of mapping.entries()) {
116
+ let outputPath = key;
117
+ // v1 will remove nested directories
118
+ if (typeof options.name === 'object' && options.name.algorithm === 'v1') {
83
119
  const isSharedDir = Array.from(mapping.keys()).some((item) => item !== outputPath &&
84
120
  path.dirname(item) === path.dirname(outputPath));
85
121
  if (!isSharedDir && path.dirname(outputPath) !== '.') {
86
122
  outputPath = path.join(path.dirname(outputPath) + '.mdx');
87
123
  }
88
- await write(path.join(outputDir, outputPath), output.content);
89
- if (groupBy === 'route' && output.pathItem.summary) {
90
- await writeMetafile(path.join(outputDir, path.dirname(outputPath), 'meta.json'), {
91
- title: output.pathItem.summary,
92
- });
93
- }
94
- console.log(`Generated: ${outputPath}`);
95
- }
96
- }
97
- if (per === 'tag') {
98
- const results = await generateTags(pathOrUrl, options);
99
- for (const result of results) {
100
- let tagName = result.tag;
101
- tagName = nameFn?.('tag', tagName) ?? getFilename(tagName);
102
- const outPath = path.join(outputDir, `${tagName}.mdx`);
103
- await write(outPath, result.content);
104
- console.log(`Generated: ${outPath}`);
105
124
  }
125
+ await write(path.join(outputDir, outputPath), output.content);
126
+ console.log(`Generated: ${outputPath}`);
106
127
  }
107
128
  }
108
- await Promise.all(resolvedInputs.map(generateFromDocument));
109
129
  }
110
130
  function isUrl(input) {
111
131
  return input.startsWith('https://') || input.startsWith('http://');
@@ -125,7 +145,12 @@ function getOutputPathFromRoute(path) {
125
145
  function getFilename(s) {
126
146
  return s.replace(/\s+/g, '-').toLowerCase();
127
147
  }
128
- async function write(file, content) {
129
- await mkdir(path.dirname(file), { recursive: true });
130
- await writeFile(file, content);
148
+ async function dereference(pathOrDocument, options) {
149
+ return processDocument(
150
+ // resolve paths
151
+ typeof pathOrDocument === 'string' &&
152
+ !pathOrDocument.startsWith('http://') &&
153
+ !pathOrDocument.startsWith('https://')
154
+ ? resolve(options.cwd ?? process.cwd(), pathOrDocument)
155
+ : pathOrDocument);
131
156
  }
@@ -1,8 +1,6 @@
1
1
  import { type DocumentContext } from './utils/generate-document.js';
2
- import type { OperationObject, PathItemObject } from './types.js';
3
- import type { NoReference } from './utils/schema.js';
4
2
  import type { OperationItem, WebhookItem } from './render/api-page.js';
5
- import { type DocumentInput } from './utils/process-document.js';
3
+ import type { DocumentInput, ProcessedDocument } from './utils/process-document.js';
6
4
  export interface GenerateOptions {
7
5
  /**
8
6
  * Additional imports of your MDX components.
@@ -35,6 +33,12 @@ export interface GenerateOptions {
35
33
  */
36
34
  addGeneratedComment?: boolean | string;
37
35
  cwd?: string;
36
+ /**
37
+ * Inline the entire OpenAPI document into the MDX file.
38
+ *
39
+ * @defaultValue false
40
+ */
41
+ inlineDocument?: boolean;
38
42
  }
39
43
  export interface GenerateTagOutput {
40
44
  tag: string;
@@ -42,18 +46,14 @@ export interface GenerateTagOutput {
42
46
  }
43
47
  export type GeneratePageOutput = {
44
48
  type: 'operation';
45
- pathItem: NoReference<PathItemObject>;
46
- operation: NoReference<OperationObject>;
47
49
  item: OperationItem;
48
50
  content: string;
49
51
  } | {
50
52
  type: 'webhook';
51
- pathItem: NoReference<PathItemObject>;
52
- operation: NoReference<OperationObject>;
53
53
  item: WebhookItem;
54
54
  content: string;
55
55
  };
56
- export declare function generateAll(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<string>;
57
- export declare function generatePages(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<GeneratePageOutput[]>;
58
- export declare function generateTags(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<GenerateTagOutput[]>;
56
+ export declare function generateAll(input: DocumentInput, processed: ProcessedDocument, options?: GenerateOptions): Promise<string>;
57
+ export declare function generatePages(input: DocumentInput, processed: ProcessedDocument, options?: GenerateOptions): Promise<GeneratePageOutput[]>;
58
+ export declare function generateTags(input: DocumentInput, processed: ProcessedDocument, options?: GenerateOptions): Promise<GenerateTagOutput[]>;
59
59
  //# sourceMappingURL=generate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts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AC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,kBAAkB,GAC1B;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEN,wBAAsB,WAAW,CAC/B,KAAK,EAAE,aAAa,EACpB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAqBjB;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,aAAa,EACpB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAiE/B;AAED,wBAAsB,YAAY,CAChC,KAAK,EAAE,aAAa,EACpB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAwC9B"}
package/dist/generate.js CHANGED
@@ -1,38 +1,23 @@
1
- import { resolve } from 'node:path';
2
1
  import { getAPIPageItems } from './build-routes.js';
3
2
  import { generateDocument, } from './utils/generate-document.js';
4
3
  import { idToTitle } from './utils/id-to-title.js';
5
- import { processDocument } from './utils/process-document.js';
6
- async function dereference(pathOrDocument, options) {
7
- return await processDocument(
8
- // resolve paths
9
- typeof pathOrDocument === 'string' &&
10
- !pathOrDocument.startsWith('http://') &&
11
- !pathOrDocument.startsWith('https://')
12
- ? resolve(options.cwd ?? process.cwd(), pathOrDocument)
13
- : pathOrDocument).then((res) => res.document);
14
- }
15
- export async function generateAll(pathOrDocument, options = {}) {
16
- const document = await dereference(pathOrDocument, options);
4
+ export async function generateAll(input, processed, options = {}) {
5
+ const { document } = processed;
17
6
  const items = getAPIPageItems(document);
18
- return generateDocument({
7
+ return generateDocument(input, processed, {
8
+ operations: items.operations,
9
+ webhooks: items.webhooks,
10
+ hasHead: true,
11
+ }, {
19
12
  ...options,
20
- dereferenced: document,
21
13
  title: document.info.title,
22
14
  description: document.info.description,
23
- page: {
24
- operations: items.operations,
25
- webhooks: items.webhooks,
26
- hasHead: true,
27
- document: pathOrDocument,
28
- },
29
- context: {
30
- type: 'file',
31
- },
15
+ }, {
16
+ type: 'file',
32
17
  });
33
18
  }
34
- export async function generatePages(pathOrDocument, options = {}) {
35
- const document = await dereference(pathOrDocument, options);
19
+ export async function generatePages(input, processed, options = {}) {
20
+ const { document } = processed;
36
21
  const items = getAPIPageItems(document);
37
22
  const result = [];
38
23
  for (const item of items.operations) {
@@ -44,24 +29,18 @@ export async function generatePages(pathOrDocument, options = {}) {
44
29
  continue;
45
30
  result.push({
46
31
  type: 'operation',
47
- pathItem,
48
- operation,
49
32
  item,
50
- content: generateDocument({
33
+ content: generateDocument(input, processed, {
34
+ operations: [item],
35
+ hasHead: false,
36
+ }, {
51
37
  ...options,
52
- page: {
53
- operations: [item],
54
- hasHead: false,
55
- document: pathOrDocument,
56
- },
57
- dereferenced: document,
58
38
  title: operation.summary ??
59
39
  pathItem.summary ??
60
40
  idToTitle(operation.operationId ?? 'unknown'),
61
41
  description: operation.description ?? pathItem.description,
62
- context: {
63
- type: 'operation',
64
- },
42
+ }, {
43
+ type: 'operation',
65
44
  }),
66
45
  });
67
46
  }
@@ -74,29 +53,23 @@ export async function generatePages(pathOrDocument, options = {}) {
74
53
  continue;
75
54
  result.push({
76
55
  type: 'webhook',
77
- pathItem,
78
- operation,
79
56
  item,
80
- content: generateDocument({
57
+ content: generateDocument(input, processed, {
58
+ webhooks: [item],
59
+ hasHead: false,
60
+ }, {
81
61
  ...options,
82
- page: {
83
- webhooks: [item],
84
- hasHead: false,
85
- document: pathOrDocument,
86
- },
87
- dereferenced: document,
88
62
  title: operation.summary ?? pathItem.summary ?? idToTitle(item.name),
89
63
  description: operation.description ?? pathItem.description,
90
- context: {
91
- type: 'operation',
92
- },
64
+ }, {
65
+ type: 'operation',
93
66
  }),
94
67
  });
95
68
  }
96
69
  return result;
97
70
  }
98
- export async function generateTags(pathOrDocument, options = {}) {
99
- const document = await dereference(pathOrDocument, options);
71
+ export async function generateTags(input, processed, options = {}) {
72
+ const { document } = processed;
100
73
  if (!document.tags)
101
74
  return [];
102
75
  const items = getAPIPageItems(document);
@@ -108,21 +81,17 @@ export async function generateTags(pathOrDocument, options = {}) {
108
81
  : idToTitle(tag.name);
109
82
  return {
110
83
  tag: tag.name,
111
- content: generateDocument({
84
+ content: generateDocument(input, processed, {
85
+ operations,
86
+ webhooks,
87
+ hasHead: true,
88
+ }, {
112
89
  ...options,
113
- page: {
114
- document: pathOrDocument,
115
- operations,
116
- webhooks,
117
- hasHead: true,
118
- },
119
- dereferenced: document,
120
90
  title: displayName,
121
91
  description: tag?.description,
122
- context: {
123
- type: 'tag',
124
- tag,
125
- },
92
+ }, {
93
+ type: 'tag',
94
+ tag,
126
95
  }),
127
96
  };
128
97
  });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './generate.js';
2
1
  export * from './generate-file.js';
3
2
  export * from './types.js';
3
+ export type { MediaAdapter } from './media/adapter.js';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
- export * from './generate.js';
2
1
  export * from './generate-file.js';
3
2
  export * from './types.js';
@@ -1,24 +1,20 @@
1
- import { type HTMLAttributes, type ReactNode } from 'react';
1
+ import { ComponentProps, type HTMLAttributes, type ReactNode } from 'react';
2
2
  import type { RequestSchema } from '../playground/index.js';
3
3
  export declare function ObjectInput({ field: _field, fieldName, ...props }: {
4
4
  field: Exclude<RequestSchema, boolean>;
5
5
  fieldName: string;
6
- } & HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
6
+ } & ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element | undefined;
7
7
  export declare function JsonInput({ fieldName, children, }: {
8
8
  fieldName: string;
9
9
  children: ReactNode;
10
10
  }): import("react/jsx-runtime").JSX.Element;
11
- export declare function FieldInput({ field, fieldName, isRequired, ...props }: HTMLAttributes<HTMLElement> & {
12
- field: Exclude<RequestSchema, boolean>;
13
- isRequired?: boolean;
14
- fieldName: string;
15
- }): import("react/jsx-runtime").JSX.Element;
16
- export declare function FieldSet({ field: _field, fieldName, toolbar, name, isRequired, depth, ...props }: HTMLAttributes<HTMLElement> & {
11
+ export declare function FieldSet({ field: _field, fieldName, toolbar, name, isRequired, depth, slotType, ...props }: HTMLAttributes<HTMLElement> & {
17
12
  isRequired?: boolean;
18
13
  name?: ReactNode;
19
14
  field: RequestSchema;
20
15
  fieldName: string;
21
16
  depth?: number;
17
+ slotType?: ReactNode;
22
18
  toolbar?: ReactNode;
23
19
  }): import("react/jsx-runtime").JSX.Element | null;
24
20
  //# sourceMappingURL=inputs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAef,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA8CxD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EAAE,MAAM,EAC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