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.
- package/dist/generate-file.d.ts +55 -20
- package/dist/generate-file.d.ts.map +1 -1
- package/dist/generate-file.js +93 -68
- package/dist/generate.d.ts +10 -10
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +33 -64
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/playground/inputs.d.ts +4 -8
- package/dist/playground/inputs.d.ts.map +1 -1
- package/dist/playground/inputs.js +56 -37
- package/dist/render/api-page.d.ts.map +1 -1
- package/dist/render/markdown.d.ts.map +1 -1
- package/dist/render/markdown.js +15 -11
- package/dist/render/operation/api-example.js +10 -6
- package/dist/render/operation/index.d.ts +1 -1
- package/dist/render/operation/index.d.ts.map +1 -1
- package/dist/render/operation/index.js +4 -16
- package/dist/render/renderer.d.ts +1 -0
- package/dist/render/renderer.d.ts.map +1 -1
- package/dist/render/schema.d.ts +5 -15
- package/dist/render/schema.d.ts.map +1 -1
- package/dist/render/schema.js +178 -97
- package/dist/server/create.d.ts +1 -7
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/proxy.d.ts +11 -1
- package/dist/server/proxy.d.ts.map +1 -1
- package/dist/server/proxy.js +10 -3
- package/dist/server/source-api.d.ts +3 -2
- package/dist/server/source-api.d.ts.map +1 -1
- package/dist/ui/client.js +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +4 -4
- package/dist/utils/combine-schema.d.ts.map +1 -1
- package/dist/utils/combine-schema.js +22 -27
- package/dist/utils/generate-document.d.ts +4 -7
- package/dist/utils/generate-document.d.ts.map +1 -1
- package/dist/utils/generate-document.js +10 -6
- package/dist/utils/process-document.d.ts +1 -1
- package/dist/utils/process-document.d.ts.map +1 -1
- package/dist/utils/process-document.js +8 -5
- package/dist/utils/schema-to-string.d.ts.map +1 -1
- package/dist/utils/schema-to-string.js +8 -21
- package/dist/utils/schema.d.ts +1 -1
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +5 -8
- package/package.json +12 -12
package/dist/generate-file.d.ts
CHANGED
|
@@ -1,38 +1,73 @@
|
|
|
1
|
-
import { type GenerateOptions } from './generate.js';
|
|
2
|
-
|
|
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
|
-
*
|
|
5
|
+
* The original schema file path/url from `input`
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
pathOrUrl: string;
|
|
8
|
+
content: string;
|
|
9
|
+
}
|
|
10
|
+
interface OperationConfig extends BaseConfig {
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
12
|
+
* Generate a page for each API endpoint/operation (default).
|
|
9
13
|
*/
|
|
10
|
-
|
|
14
|
+
per?: 'operation';
|
|
11
15
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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 '
|
|
21
|
+
* @defaultValue 'none'
|
|
17
22
|
*/
|
|
18
|
-
|
|
23
|
+
groupBy?: 'tag' | 'route' | 'none';
|
|
19
24
|
/**
|
|
20
25
|
* Specify name for output file
|
|
21
26
|
*/
|
|
22
|
-
name?: (
|
|
27
|
+
name?: ((output: GeneratePageOutput, document: ProcessedDocument['document']) => string) | BaseName;
|
|
28
|
+
}
|
|
29
|
+
interface TagConfig extends BaseConfig {
|
|
23
30
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @deprecated Use `groupBy` instead
|
|
27
|
-
* @defaultValue false
|
|
31
|
+
* Generate a page for each tag.
|
|
28
32
|
*/
|
|
29
|
-
|
|
33
|
+
per: 'tag';
|
|
30
34
|
/**
|
|
31
|
-
*
|
|
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
|
-
*
|
|
54
|
+
* v1: Fumadocs OpenAPI v8
|
|
55
|
+
* v2: Fumadocs OpenAPI v9
|
|
56
|
+
*
|
|
57
|
+
* @defaultValue v2
|
|
34
58
|
*/
|
|
35
|
-
|
|
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":"
|
|
1
|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AAG,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"}
|
package/dist/generate-file.js
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
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
|
-
|
|
43
|
-
outPaths.push(path.join(getFilename(tag), `${file}.mdx`));
|
|
44
|
-
}
|
|
84
|
+
return tags.map((tag) => path.join(getFilename(tag), `${file}.mdx`));
|
|
45
85
|
}
|
|
46
|
-
|
|
47
|
-
outPaths.push(`${file}.mdx`);
|
|
48
|
-
}
|
|
49
|
-
return outPaths;
|
|
86
|
+
return [`${file}.mdx`];
|
|
50
87
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
69
|
-
await write(outPath, result);
|
|
103
|
+
await write(outPath, result.content);
|
|
70
104
|
console.log(`Generated: ${outPath}`);
|
|
71
105
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
|
|
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
|
|
129
|
-
|
|
130
|
-
|
|
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
|
}
|
package/dist/generate.d.ts
CHANGED
|
@@ -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 {
|
|
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(
|
|
57
|
-
export declare function generatePages(
|
|
58
|
-
export declare function generateTags(
|
|
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
|
package/dist/generate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,eAAe,EAErB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,EAAE,CAA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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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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(
|
|
35
|
-
const document =
|
|
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
|
-
|
|
63
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
},
|
|
64
|
+
}, {
|
|
65
|
+
type: 'operation',
|
|
93
66
|
}),
|
|
94
67
|
});
|
|
95
68
|
}
|
|
96
69
|
return result;
|
|
97
70
|
}
|
|
98
|
-
export async function generateTags(
|
|
99
|
-
const document =
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
},
|
|
92
|
+
}, {
|
|
93
|
+
type: 'tag',
|
|
94
|
+
tag,
|
|
126
95
|
}),
|
|
127
96
|
};
|
|
128
97
|
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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,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
|
-
} &
|
|
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
|
|
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,
|
|
1
|
+
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,KAAK,cAAc,EAEnB,KAAK,SAAS,EAGf,MAAM,OAAO,CAAC;AAef,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAgDxD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EACT,GAAG,KAAK,EACT,EAAE;IACD,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAAC,KAAK,CAAC,uDAqCxB;AAED,wBAAgB,SAAS,CAAC,EACxB,SAAS,EACT,QAAQ,GACT,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;CACrB,2CA0BA;AAkLD,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,KAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,CAAC;CACrB,kDA6KA"}
|