fumadocs-openapi 6.0.0 → 6.0.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.
- package/dist/build-routes.d.ts +15 -0
- package/dist/build-routes.d.ts.map +1 -0
- package/dist/build-routes.js +38 -0
- package/dist/generate-file.d.ts +38 -0
- package/dist/generate-file.d.ts.map +1 -0
- package/dist/generate-file.js +118 -0
- package/dist/generate.d.ts +48 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +129 -0
- package/dist/index.d.ts +4 -274
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -389
- package/dist/render/codeblock.d.ts +9 -0
- package/dist/render/codeblock.d.ts.map +1 -0
- package/dist/render/codeblock.js +13 -0
- package/dist/render/heading.d.ts +4 -0
- package/dist/render/heading.d.ts.map +1 -0
- package/dist/render/heading.js +6 -0
- package/dist/render/markdown.d.ts +5 -0
- package/dist/render/markdown.d.ts.map +1 -0
- package/dist/render/markdown.js +25 -0
- package/dist/render/operation.d.ts +17 -0
- package/dist/render/operation.d.ts.map +1 -0
- package/dist/render/operation.js +230 -0
- package/dist/render/playground.d.ts +66 -0
- package/dist/render/playground.d.ts.map +1 -0
- package/dist/render/playground.js +181 -0
- package/dist/render/renderer.d.ts +76 -0
- package/dist/render/renderer.d.ts.map +1 -0
- package/dist/render/renderer.js +23 -0
- package/dist/render/schema.d.ts +29 -0
- package/dist/render/schema.d.ts.map +1 -0
- package/dist/render/schema.js +151 -0
- package/dist/requests/curl.d.ts +3 -0
- package/dist/requests/curl.d.ts.map +1 -0
- package/dist/requests/curl.js +33 -0
- package/dist/requests/go.d.ts +3 -0
- package/dist/requests/go.d.ts.map +1 -0
- package/dist/requests/go.js +54 -0
- package/dist/requests/javascript.d.ts +3 -0
- package/dist/requests/javascript.d.ts.map +1 -0
- package/dist/requests/javascript.js +49 -0
- package/dist/requests/python.d.ts +3 -0
- package/dist/requests/python.d.ts.map +1 -0
- package/dist/requests/python.js +45 -0
- package/dist/scalar/client.d.ts +6 -0
- package/dist/scalar/client.d.ts.map +1 -0
- package/dist/scalar/client.js +25 -0
- package/dist/scalar/index.d.ts +4 -173
- package/dist/scalar/index.d.ts.map +1 -0
- package/dist/scalar/index.js +4 -11
- package/dist/server/api-page.d.ts +33 -0
- package/dist/server/api-page.d.ts.map +1 -0
- package/dist/server/api-page.js +59 -0
- package/dist/server/create-method.d.ts +7 -0
- package/dist/server/create-method.d.ts.map +1 -0
- package/dist/server/create-method.js +12 -0
- package/dist/server/create.d.ts +16 -0
- package/dist/server/create.d.ts.map +1 -0
- package/dist/server/create.js +11 -0
- package/dist/server/index.d.ts +3 -221
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +2 -1493
- package/dist/server/proxy.d.ts +8 -0
- package/dist/server/proxy.d.ts.map +1 -0
- package/dist/server/proxy.js +53 -0
- package/dist/server/source-api.d.ts +8 -0
- package/dist/server/source-api.d.ts.map +1 -0
- package/dist/server/source-api.js +34 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/ui/client.d.ts +22 -0
- package/dist/ui/client.d.ts.map +1 -0
- package/dist/ui/client.js +10 -0
- package/dist/ui/components/input.d.ts +6 -0
- package/dist/ui/components/input.d.ts.map +1 -0
- package/dist/ui/components/input.js +10 -0
- package/dist/ui/components/method-label.d.ts +5 -0
- package/dist/ui/components/method-label.d.ts.map +1 -0
- package/dist/ui/components/method-label.js +33 -0
- package/dist/ui/components/select.d.ts +14 -0
- package/dist/ui/components/select.d.ts.map +1 -0
- package/dist/ui/components/select.js +24 -0
- package/dist/ui/components/variants.d.ts +6 -0
- package/dist/ui/components/variants.d.ts.map +1 -0
- package/dist/ui/components/variants.js +26 -0
- package/dist/ui/contexts/api.d.ts +28 -0
- package/dist/ui/contexts/api.d.ts.map +1 -0
- package/dist/ui/contexts/api.js +74 -0
- package/dist/ui/contexts/schema.d.ts +17 -0
- package/dist/ui/contexts/schema.d.ts.map +1 -0
- package/dist/ui/contexts/schema.js +8 -0
- package/dist/ui/index.d.ts +12 -302
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +18 -98
- package/dist/ui/playground/fetcher.d.ts +34 -0
- package/dist/ui/playground/fetcher.d.ts.map +1 -0
- package/dist/ui/{fetcher-Cey1qI8X.js → playground/fetcher.js} +45 -44
- package/dist/ui/playground/get-default-values.d.ts +4 -0
- package/dist/ui/playground/get-default-values.d.ts.map +1 -0
- package/dist/ui/playground/get-default-values.js +24 -0
- package/dist/ui/playground/index.d.ts +44 -0
- package/dist/ui/playground/index.d.ts.map +1 -0
- package/dist/ui/playground/index.js +187 -0
- package/dist/ui/playground/inputs.d.ts +23 -0
- package/dist/ui/playground/inputs.d.ts.map +1 -0
- package/dist/ui/playground/inputs.js +172 -0
- package/dist/ui/playground/resolve.d.ts +6 -0
- package/dist/ui/playground/resolve.d.ts.map +1 -0
- package/dist/ui/playground/resolve.js +14 -0
- package/dist/ui/playground/status-info.d.ts +8 -0
- package/dist/ui/playground/status-info.d.ts.map +1 -0
- package/dist/ui/playground/status-info.js +40 -0
- package/dist/ui/server-select.d.ts +3 -0
- package/dist/ui/server-select.d.ts.map +1 -0
- package/dist/ui/server-select.js +27 -0
- package/dist/utils/combine-schema.d.ts +6 -0
- package/dist/utils/combine-schema.d.ts.map +1 -0
- package/dist/utils/combine-schema.js +46 -0
- package/dist/utils/generate-document.d.ts +20 -0
- package/dist/utils/generate-document.d.ts.map +1 -0
- package/dist/utils/generate-document.js +82 -0
- package/dist/utils/generate-sample.d.ts +33 -0
- package/dist/utils/generate-sample.d.ts.map +1 -0
- package/dist/utils/generate-sample.js +97 -0
- package/dist/utils/get-security.d.ts +8 -0
- package/dist/utils/get-security.d.ts.map +1 -0
- package/dist/utils/get-security.js +23 -0
- package/dist/utils/get-typescript-schema.d.ts +4 -0
- package/dist/utils/get-typescript-schema.d.ts.map +1 -0
- package/dist/utils/get-typescript-schema.js +18 -0
- package/dist/utils/id-to-title.d.ts +2 -0
- package/dist/utils/id-to-title.d.ts.map +1 -0
- package/dist/utils/id-to-title.js +17 -0
- package/dist/utils/input-to-string.d.ts +5 -0
- package/dist/utils/input-to-string.d.ts.map +1 -0
- package/dist/utils/input-to-string.js +21 -0
- package/dist/utils/process-document.d.ts +14 -0
- package/dist/utils/process-document.d.ts.map +1 -0
- package/dist/utils/process-document.js +32 -0
- package/dist/utils/schema.d.ts +9 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +16 -0
- package/dist/utils/server-url.d.ts +2 -0
- package/dist/utils/server-url.d.ts.map +1 -0
- package/dist/utils/server-url.js +7 -0
- package/dist/utils/use-query.d.ts +6 -0
- package/dist/utils/use-query.d.ts.map +1 -0
- package/dist/utils/use-query.js +22 -0
- package/package.json +9 -9
- package/dist/scalar/client-client-DgnHaOQ3.js +0 -93
- package/dist/ui/client-client-CpwKrzlY.js +0 -107
- package/dist/ui/index-client-CehDtJk-.js +0 -1116
- package/dist/ui/server-select-client-CbFencmM.js +0 -86
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Document } from './types';
|
|
2
|
+
import type { NoReference } from './utils/schema';
|
|
3
|
+
import type { OperationItem, WebhookItem } from './server/api-page';
|
|
4
|
+
export declare const methodKeys: readonly ["get", "post", "patch", "delete", "head", "put"];
|
|
5
|
+
type Result = {
|
|
6
|
+
webhooks: (WebhookItem & {
|
|
7
|
+
tags?: string[];
|
|
8
|
+
})[];
|
|
9
|
+
operations: (OperationItem & {
|
|
10
|
+
tags?: string[];
|
|
11
|
+
})[];
|
|
12
|
+
};
|
|
13
|
+
export declare function getAPIPageItems(document: NoReference<Document>): Result;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=build-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-routes.d.ts","sourceRoot":"","sources":["../src/build-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGpE,eAAO,MAAM,UAAU,4DAOb,CAAC;AAEX,KAAK,MAAM,GAAG;IACZ,QAAQ,EAAE,CAAC,WAAW,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,EAAE,CAAC;IAChD,UAAU,EAAE,CAAC,aAAa,GAAG;QAC3B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;KACjB,CAAC,EAAE,CAAC;CACN,CAAC;AAEF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,MAAM,CAgCvE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const methodKeys = [
|
|
2
|
+
'get',
|
|
3
|
+
'post',
|
|
4
|
+
'patch',
|
|
5
|
+
'delete',
|
|
6
|
+
'head',
|
|
7
|
+
'put',
|
|
8
|
+
];
|
|
9
|
+
export function getAPIPageItems(document) {
|
|
10
|
+
const result = { webhooks: [], operations: [] };
|
|
11
|
+
for (const [path, pathItem] of Object.entries(document.paths ?? {})) {
|
|
12
|
+
if (!pathItem)
|
|
13
|
+
continue;
|
|
14
|
+
for (const methodKey of methodKeys) {
|
|
15
|
+
if (!pathItem[methodKey])
|
|
16
|
+
continue;
|
|
17
|
+
result.operations.push({
|
|
18
|
+
method: methodKey,
|
|
19
|
+
path,
|
|
20
|
+
tags: pathItem[methodKey]?.tags,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
for (const [name, pathItem] of Object.entries(document.webhooks ?? {})) {
|
|
25
|
+
if (!pathItem)
|
|
26
|
+
continue;
|
|
27
|
+
for (const methodKey of methodKeys) {
|
|
28
|
+
if (!pathItem[methodKey])
|
|
29
|
+
continue;
|
|
30
|
+
result.webhooks.push({
|
|
31
|
+
method: methodKey,
|
|
32
|
+
name,
|
|
33
|
+
tags: pathItem[methodKey]?.tags,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type GenerateOptions } from './generate';
|
|
2
|
+
export interface Config extends GenerateOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Schema files
|
|
5
|
+
*/
|
|
6
|
+
input: string[] | string;
|
|
7
|
+
/**
|
|
8
|
+
* Output directory
|
|
9
|
+
*/
|
|
10
|
+
output: string;
|
|
11
|
+
/**
|
|
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
|
|
15
|
+
*
|
|
16
|
+
* @defaultValue 'operation'
|
|
17
|
+
*/
|
|
18
|
+
per?: 'tag' | 'file' | 'operation';
|
|
19
|
+
/**
|
|
20
|
+
* Specify name for output file
|
|
21
|
+
*/
|
|
22
|
+
name?: (type: 'file' | 'tag', name: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Group output using folders (Only works on `operation` mode)
|
|
25
|
+
*
|
|
26
|
+
* @deprecated Use `groupBy` instead
|
|
27
|
+
* @defaultValue false
|
|
28
|
+
*/
|
|
29
|
+
groupByFolder?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Group output using folders (Only works on `operation` mode)
|
|
32
|
+
*
|
|
33
|
+
* @defaultValue 'none'
|
|
34
|
+
*/
|
|
35
|
+
groupBy?: 'tag' | 'route' | 'none';
|
|
36
|
+
}
|
|
37
|
+
export declare function generateFiles(options: Config): Promise<void>;
|
|
38
|
+
//# sourceMappingURL=generate-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-file.d.ts","sourceRoot":"","sources":["../src/generate-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,YAAY,CAAC;AAGpB,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,MAAM,KAAK,MAAM,CAAC;IAEtD;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;CACpC;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4HlE"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join, parse } from 'node:path';
|
|
3
|
+
import fg from 'fast-glob';
|
|
4
|
+
import { generatePages, } from './generate';
|
|
5
|
+
import { generateAll, generateTags } from './generate';
|
|
6
|
+
export async function generateFiles(options) {
|
|
7
|
+
const { input, output, name: nameFn, per = 'operation', groupBy = 'none', cwd = process.cwd(), } = options;
|
|
8
|
+
const outputDir = join(cwd, output);
|
|
9
|
+
const urlInputs = [];
|
|
10
|
+
const fileInputs = [];
|
|
11
|
+
for (const v of typeof input === 'string' ? [input] : input) {
|
|
12
|
+
if (isUrl(v)) {
|
|
13
|
+
urlInputs.push(v);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
fileInputs.push(v);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const resolvedInputs = [
|
|
20
|
+
...(await fg.glob(fileInputs, { cwd, absolute: false })),
|
|
21
|
+
...urlInputs,
|
|
22
|
+
];
|
|
23
|
+
function getOutputPaths(result) {
|
|
24
|
+
let file;
|
|
25
|
+
if (result.pathItem.summary) {
|
|
26
|
+
file = getFilename(result.pathItem.summary);
|
|
27
|
+
}
|
|
28
|
+
else if (result.type === 'operation') {
|
|
29
|
+
file = result.operation.operationId
|
|
30
|
+
? getFilename(result.operation.operationId)
|
|
31
|
+
: join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
file = getFilename(result.item.name);
|
|
35
|
+
}
|
|
36
|
+
const outPaths = [];
|
|
37
|
+
if (groupBy === 'tag') {
|
|
38
|
+
const tags = result.operation.tags;
|
|
39
|
+
if (tags && tags.length > 0) {
|
|
40
|
+
for (const tag of tags) {
|
|
41
|
+
outPaths.push(join(outputDir, getFilename(tag), `${file}.mdx`));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
outPaths.push(result.type === 'operation'
|
|
46
|
+
? join(outputDir, `${file}.mdx`)
|
|
47
|
+
: join(outputDir, 'webhooks', `${file}.mdx`));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (groupBy === 'route' || groupBy === 'none') {
|
|
51
|
+
outPaths.push(join(outputDir, `${file}.mdx`));
|
|
52
|
+
}
|
|
53
|
+
return outPaths;
|
|
54
|
+
}
|
|
55
|
+
async function generateFromDocument(pathOrUrl) {
|
|
56
|
+
if (per === 'file') {
|
|
57
|
+
let filename = isUrl(pathOrUrl) ? 'index' : parse(pathOrUrl).name;
|
|
58
|
+
if (nameFn)
|
|
59
|
+
filename = nameFn('file', filename);
|
|
60
|
+
const outPath = join(outputDir, `${filename}.mdx`);
|
|
61
|
+
const result = await generateAll(pathOrUrl, options);
|
|
62
|
+
await write(outPath, result);
|
|
63
|
+
console.log(`Generated: ${outPath}`);
|
|
64
|
+
}
|
|
65
|
+
if (per === 'operation') {
|
|
66
|
+
const metaFiles = new Set();
|
|
67
|
+
const results = await generatePages(pathOrUrl, options);
|
|
68
|
+
for (const result of results) {
|
|
69
|
+
const meta = JSON.stringify({
|
|
70
|
+
title: result.pathItem.summary,
|
|
71
|
+
}, null, 2);
|
|
72
|
+
for (const outPath of getOutputPaths(result)) {
|
|
73
|
+
await write(outPath, result.content);
|
|
74
|
+
console.log(`Generated: ${outPath}`);
|
|
75
|
+
if (groupBy === 'route') {
|
|
76
|
+
const metaFile = join(dirname(outPath), 'meta.json');
|
|
77
|
+
if (!result.pathItem.summary || metaFiles.has(metaFile))
|
|
78
|
+
continue;
|
|
79
|
+
metaFiles.add(metaFile);
|
|
80
|
+
await write(metaFile, meta);
|
|
81
|
+
console.log(`Generated Meta: ${metaFile}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (per === 'tag') {
|
|
87
|
+
const results = await generateTags(pathOrUrl, options);
|
|
88
|
+
for (const result of results) {
|
|
89
|
+
let tagName = result.tag;
|
|
90
|
+
tagName = nameFn?.('tag', tagName) ?? getFilename(tagName);
|
|
91
|
+
const outPath = join(outputDir, `${tagName}.mdx`);
|
|
92
|
+
await write(outPath, result.content);
|
|
93
|
+
console.log(`Generated: ${outPath}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
await Promise.all(resolvedInputs.map(generateFromDocument));
|
|
98
|
+
}
|
|
99
|
+
function isUrl(input) {
|
|
100
|
+
return input.startsWith('https://') || input.startsWith('http://');
|
|
101
|
+
}
|
|
102
|
+
function getOutputPathFromRoute(path) {
|
|
103
|
+
return (path
|
|
104
|
+
.replaceAll('.', '/')
|
|
105
|
+
.split('/')
|
|
106
|
+
.filter((v) => !v.startsWith('{') && !v.endsWith('}'))
|
|
107
|
+
.at(-1) ?? '');
|
|
108
|
+
}
|
|
109
|
+
function getFilename(s) {
|
|
110
|
+
return s
|
|
111
|
+
.replace(/[A-Z]/g, (match, idx) => idx === 0 ? match : `-${match.toLowerCase()}`)
|
|
112
|
+
.replace(/\s+/g, '-')
|
|
113
|
+
.toLowerCase();
|
|
114
|
+
}
|
|
115
|
+
async function write(path, content) {
|
|
116
|
+
await mkdir(dirname(path), { recursive: true });
|
|
117
|
+
await writeFile(path, content);
|
|
118
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type DocumentContext } from './utils/generate-document';
|
|
2
|
+
import type { OperationObject, PathItemObject } from './types';
|
|
3
|
+
import type { NoReference } from './utils/schema';
|
|
4
|
+
import type { OperationItem, WebhookItem } from './server/api-page';
|
|
5
|
+
import { type DocumentInput } from './utils/process-document';
|
|
6
|
+
export interface GenerateOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Additional imports of your MDX components.
|
|
9
|
+
*/
|
|
10
|
+
imports?: {
|
|
11
|
+
names: string[];
|
|
12
|
+
from: string;
|
|
13
|
+
}[];
|
|
14
|
+
/**
|
|
15
|
+
* Customise frontmatter.
|
|
16
|
+
*
|
|
17
|
+
* A `full: true` property will be added by default.
|
|
18
|
+
*/
|
|
19
|
+
frontmatter?: (title: string, description: string | undefined, context: DocumentContext) => Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Add description to document body
|
|
22
|
+
*
|
|
23
|
+
* @defaultValue false
|
|
24
|
+
*/
|
|
25
|
+
includeDescription?: boolean;
|
|
26
|
+
cwd?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface GenerateTagOutput {
|
|
29
|
+
tag: string;
|
|
30
|
+
content: string;
|
|
31
|
+
}
|
|
32
|
+
export type GeneratePageOutput = {
|
|
33
|
+
type: 'operation';
|
|
34
|
+
pathItem: NoReference<PathItemObject>;
|
|
35
|
+
operation: NoReference<OperationObject>;
|
|
36
|
+
item: OperationItem;
|
|
37
|
+
content: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: 'webhook';
|
|
40
|
+
pathItem: NoReference<PathItemObject>;
|
|
41
|
+
operation: NoReference<OperationObject>;
|
|
42
|
+
item: WebhookItem;
|
|
43
|
+
content: string;
|
|
44
|
+
};
|
|
45
|
+
export declare function generateAll(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<string>;
|
|
46
|
+
export declare function generatePages(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<GeneratePageOutput[]>;
|
|
47
|
+
export declare function generateTags(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<GenerateTagOutput[]>;
|
|
48
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,eAAe,EAErB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,0BAA0B,CAAC;AAE/E,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;IAEJ;;;;OAIG;IACH,WAAW,CAAC,EAAE,CACZ,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE7B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;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,QAAQ,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;IACtC,SAAS,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;IAExC,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;IACtC,SAAS,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;IAExC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAgBN,wBAAsB,WAAW,CAC/B,cAAc,EAAE,aAAa,EAC7B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAoBjB;AAED,wBAAsB,aAAa,CACjC,cAAc,EAAE,aAAa,EAC7B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAiE/B;AAED,wBAAsB,YAAY,CAChC,cAAc,EAAE,aAAa,EAC7B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAsC9B"}
|
package/dist/generate.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { getAPIPageItems } from './build-routes';
|
|
3
|
+
import { generateDocument, } from './utils/generate-document';
|
|
4
|
+
import { idToTitle } from './utils/id-to-title';
|
|
5
|
+
import { processDocument } from './utils/process-document';
|
|
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);
|
|
17
|
+
const items = getAPIPageItems(document);
|
|
18
|
+
return generateDocument({
|
|
19
|
+
...options,
|
|
20
|
+
dereferenced: document,
|
|
21
|
+
title: document.info.title,
|
|
22
|
+
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
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export async function generatePages(pathOrDocument, options = {}) {
|
|
35
|
+
const document = await dereference(pathOrDocument, options);
|
|
36
|
+
const items = getAPIPageItems(document);
|
|
37
|
+
const result = [];
|
|
38
|
+
for (const item of items.operations) {
|
|
39
|
+
const pathItem = document.paths?.[item.path];
|
|
40
|
+
if (!pathItem)
|
|
41
|
+
continue;
|
|
42
|
+
const operation = pathItem[item.method];
|
|
43
|
+
if (!operation)
|
|
44
|
+
continue;
|
|
45
|
+
result.push({
|
|
46
|
+
type: 'operation',
|
|
47
|
+
pathItem,
|
|
48
|
+
operation,
|
|
49
|
+
item,
|
|
50
|
+
content: generateDocument({
|
|
51
|
+
...options,
|
|
52
|
+
page: {
|
|
53
|
+
operations: [item],
|
|
54
|
+
hasHead: false,
|
|
55
|
+
document: pathOrDocument,
|
|
56
|
+
},
|
|
57
|
+
dereferenced: document,
|
|
58
|
+
title: operation.summary ??
|
|
59
|
+
pathItem.summary ??
|
|
60
|
+
idToTitle(operation.operationId ?? 'unknown'),
|
|
61
|
+
description: operation.description ?? pathItem.description,
|
|
62
|
+
context: {
|
|
63
|
+
type: 'operation',
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
for (const item of items.webhooks) {
|
|
69
|
+
const pathItem = document.webhooks?.[item.name];
|
|
70
|
+
if (!pathItem)
|
|
71
|
+
continue;
|
|
72
|
+
const operation = pathItem[item.method];
|
|
73
|
+
if (!operation)
|
|
74
|
+
continue;
|
|
75
|
+
result.push({
|
|
76
|
+
type: 'webhook',
|
|
77
|
+
pathItem,
|
|
78
|
+
operation,
|
|
79
|
+
item,
|
|
80
|
+
content: generateDocument({
|
|
81
|
+
...options,
|
|
82
|
+
page: {
|
|
83
|
+
webhooks: [item],
|
|
84
|
+
hasHead: false,
|
|
85
|
+
document: pathOrDocument,
|
|
86
|
+
},
|
|
87
|
+
dereferenced: document,
|
|
88
|
+
title: operation.summary ?? pathItem.summary ?? idToTitle(item.name),
|
|
89
|
+
description: operation.description ?? pathItem.description,
|
|
90
|
+
context: {
|
|
91
|
+
type: 'operation',
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
export async function generateTags(pathOrDocument, options = {}) {
|
|
99
|
+
const document = await dereference(pathOrDocument, options);
|
|
100
|
+
if (!document.tags)
|
|
101
|
+
return [];
|
|
102
|
+
const items = getAPIPageItems(document);
|
|
103
|
+
return document.tags.map((tag) => {
|
|
104
|
+
const webhooks = items.webhooks.filter((v) => v.tags && v.tags.includes(tag.name));
|
|
105
|
+
const operations = items.operations.filter((v) => v.tags && v.tags.includes(tag.name));
|
|
106
|
+
const displayName = tag && 'x-displayName' in tag && typeof tag['x-displayName'] === 'string'
|
|
107
|
+
? tag['x-displayName']
|
|
108
|
+
: idToTitle(tag.name);
|
|
109
|
+
return {
|
|
110
|
+
tag: tag.name,
|
|
111
|
+
content: generateDocument({
|
|
112
|
+
...options,
|
|
113
|
+
page: {
|
|
114
|
+
document: pathOrDocument,
|
|
115
|
+
operations,
|
|
116
|
+
webhooks,
|
|
117
|
+
hasHead: true,
|
|
118
|
+
},
|
|
119
|
+
dereferenced: document,
|
|
120
|
+
title: displayName,
|
|
121
|
+
description: tag?.description,
|
|
122
|
+
context: {
|
|
123
|
+
type: 'tag',
|
|
124
|
+
tag,
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,274 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type NoReference<T> = T extends (infer I)[] ? NoReference<I>[] : T extends ReferenceObject ? Exclude<T, ReferenceObject> : T extends object ? {
|
|
7
|
-
[K in keyof T]: NoReference<T[K]>;
|
|
8
|
-
} : T;
|
|
9
|
-
type ParsedSchema = OpenAPIV3_1.SchemaObject;
|
|
10
|
-
|
|
11
|
-
interface ResponsesProps {
|
|
12
|
-
items: string[];
|
|
13
|
-
children: ReactNode;
|
|
14
|
-
}
|
|
15
|
-
interface ResponseProps {
|
|
16
|
-
value: string;
|
|
17
|
-
children: ReactNode;
|
|
18
|
-
}
|
|
19
|
-
interface APIInfoProps {
|
|
20
|
-
method: string;
|
|
21
|
-
route: string;
|
|
22
|
-
head: ReactNode;
|
|
23
|
-
children: ReactNode;
|
|
24
|
-
}
|
|
25
|
-
interface PropertyProps {
|
|
26
|
-
name: string;
|
|
27
|
-
type: string;
|
|
28
|
-
required?: boolean;
|
|
29
|
-
deprecated?: boolean;
|
|
30
|
-
children?: ReactNode;
|
|
31
|
-
}
|
|
32
|
-
interface ObjectCollapsibleProps {
|
|
33
|
-
name: string;
|
|
34
|
-
children: ReactNode;
|
|
35
|
-
}
|
|
36
|
-
interface RequestProps {
|
|
37
|
-
language: string;
|
|
38
|
-
name: string;
|
|
39
|
-
code: string;
|
|
40
|
-
}
|
|
41
|
-
interface ResponseTypeProps {
|
|
42
|
-
lang: string;
|
|
43
|
-
code: string;
|
|
44
|
-
label: string;
|
|
45
|
-
}
|
|
46
|
-
interface RootProps {
|
|
47
|
-
baseUrl?: string;
|
|
48
|
-
servers: ServerObject[];
|
|
49
|
-
children: ReactNode;
|
|
50
|
-
}
|
|
51
|
-
interface Renderer {
|
|
52
|
-
Root: ComponentType<RootProps>;
|
|
53
|
-
API: ComponentType<{
|
|
54
|
-
children: ReactNode;
|
|
55
|
-
}>;
|
|
56
|
-
APIInfo: ComponentType<APIInfoProps>;
|
|
57
|
-
APIExample: ComponentType<{
|
|
58
|
-
children: ReactNode;
|
|
59
|
-
}>;
|
|
60
|
-
Responses: ComponentType<ResponsesProps>;
|
|
61
|
-
Response: ComponentType<ResponseProps>;
|
|
62
|
-
Requests: ComponentType<{
|
|
63
|
-
items: string[];
|
|
64
|
-
children: ReactNode;
|
|
65
|
-
}>;
|
|
66
|
-
Request: ComponentType<RequestProps>;
|
|
67
|
-
ResponseTypes: ComponentType<{
|
|
68
|
-
children: ReactNode;
|
|
69
|
-
}>;
|
|
70
|
-
ResponseType: ComponentType<ResponseTypeProps>;
|
|
71
|
-
/**
|
|
72
|
-
* Collapsible to show object schemas
|
|
73
|
-
*/
|
|
74
|
-
ObjectCollapsible: ComponentType<ObjectCollapsibleProps>;
|
|
75
|
-
Property: ComponentType<PropertyProps>;
|
|
76
|
-
APIPlayground: ComponentType<{
|
|
77
|
-
path: string;
|
|
78
|
-
method: MethodInformation;
|
|
79
|
-
ctx: RenderContext;
|
|
80
|
-
}>;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Sample info of endpoint
|
|
85
|
-
*/
|
|
86
|
-
interface EndpointSample {
|
|
87
|
-
/**
|
|
88
|
-
* Request URL, including path and query parameters
|
|
89
|
-
*/
|
|
90
|
-
url: string;
|
|
91
|
-
method: string;
|
|
92
|
-
body?: {
|
|
93
|
-
schema: ParsedSchema;
|
|
94
|
-
mediaType: string;
|
|
95
|
-
sample: unknown;
|
|
96
|
-
};
|
|
97
|
-
responses: Record<string, ResponseSample>;
|
|
98
|
-
parameters: ParameterSample[];
|
|
99
|
-
}
|
|
100
|
-
interface ResponseSample {
|
|
101
|
-
mediaType: string;
|
|
102
|
-
sample: unknown;
|
|
103
|
-
schema: ParsedSchema;
|
|
104
|
-
}
|
|
105
|
-
interface ParameterSample {
|
|
106
|
-
name: string;
|
|
107
|
-
in: string;
|
|
108
|
-
schema: ParsedSchema;
|
|
109
|
-
sample: unknown;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
interface CodeSample {
|
|
113
|
-
lang: string;
|
|
114
|
-
label: string;
|
|
115
|
-
source: string | ((endpoint: EndpointSample) => string | undefined) | false;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
type DocumentInput = string | OpenAPIV3_1.Document | OpenAPIV3.Document;
|
|
119
|
-
type ProcessedDocument = {
|
|
120
|
-
document: NoReference<Document>;
|
|
121
|
-
dereferenceMap: DereferenceMap;
|
|
122
|
-
downloaded: Document;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
type Document = OpenAPIV3_1.Document;
|
|
126
|
-
type OperationObject = OpenAPIV3_1.OperationObject;
|
|
127
|
-
type ParameterObject = OpenAPIV3_1.ParameterObject;
|
|
128
|
-
type SecurityRequirementObject = OpenAPIV3_1.SecurityRequirementObject;
|
|
129
|
-
type SecuritySchemeObject = OpenAPIV3_1.SecuritySchemeObject;
|
|
130
|
-
type ReferenceObject = OpenAPIV3_1.ReferenceObject;
|
|
131
|
-
type PathItemObject = OpenAPIV3_1.PathItemObject;
|
|
132
|
-
type TagObject = OpenAPIV3_1.TagObject;
|
|
133
|
-
type ServerObject = NoReference<OpenAPIV3_1.ServerObject>;
|
|
134
|
-
type CallbackObject = NoReference<OpenAPIV3_1.CallbackObject>;
|
|
135
|
-
type MethodInformation = NoReference<OperationObject> & {
|
|
136
|
-
method: string;
|
|
137
|
-
};
|
|
138
|
-
type Awaitable<T> = T | Promise<T>;
|
|
139
|
-
/**
|
|
140
|
-
* Dereferenced value and its original `$ref` value
|
|
141
|
-
*/
|
|
142
|
-
type DereferenceMap = Map<unknown, string>;
|
|
143
|
-
interface RenderContext {
|
|
144
|
-
/**
|
|
145
|
-
* The url of proxy to avoid CORS issues
|
|
146
|
-
*/
|
|
147
|
-
proxyUrl?: string;
|
|
148
|
-
renderer: Renderer;
|
|
149
|
-
baseUrl: string;
|
|
150
|
-
servers: ServerObject[];
|
|
151
|
-
slugger: Slugger;
|
|
152
|
-
/**
|
|
153
|
-
* dereferenced schema
|
|
154
|
-
*/
|
|
155
|
-
schema: ProcessedDocument;
|
|
156
|
-
/**
|
|
157
|
-
* Generate TypeScript definitions from response schema.
|
|
158
|
-
*
|
|
159
|
-
* Pass `false` to disable it.
|
|
160
|
-
*
|
|
161
|
-
* @param endpoint - the API endpoint
|
|
162
|
-
* @param code - status code
|
|
163
|
-
*/
|
|
164
|
-
generateTypeScriptSchema?: ((endpoint: EndpointSample, code: string) => Awaitable<string>) | false;
|
|
165
|
-
/**
|
|
166
|
-
* Generate code samples for endpoint.
|
|
167
|
-
*/
|
|
168
|
-
generateCodeSamples?: (endpoint: EndpointSample) => Awaitable<CodeSample[]>;
|
|
169
|
-
shikiOptions?: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BuiltinTheme>;
|
|
170
|
-
/**
|
|
171
|
-
* Show full response schema instead of only example response & Typescript definitions
|
|
172
|
-
*/
|
|
173
|
-
showResponseSchema?: boolean;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
interface WebhookItem {
|
|
177
|
-
name: string;
|
|
178
|
-
method: OpenAPIV3_1.HttpMethods;
|
|
179
|
-
}
|
|
180
|
-
interface OperationItem {
|
|
181
|
-
path: string;
|
|
182
|
-
method: OpenAPIV3_1.HttpMethods;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
type DocumentContext = {
|
|
186
|
-
type: 'tag';
|
|
187
|
-
tag: TagObject | undefined;
|
|
188
|
-
} | {
|
|
189
|
-
type: 'operation';
|
|
190
|
-
} | {
|
|
191
|
-
type: 'file';
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
interface GenerateOptions {
|
|
195
|
-
/**
|
|
196
|
-
* Additional imports of your MDX components.
|
|
197
|
-
*/
|
|
198
|
-
imports?: {
|
|
199
|
-
names: string[];
|
|
200
|
-
from: string;
|
|
201
|
-
}[];
|
|
202
|
-
/**
|
|
203
|
-
* Customise frontmatter.
|
|
204
|
-
*
|
|
205
|
-
* A `full: true` property will be added by default.
|
|
206
|
-
*/
|
|
207
|
-
frontmatter?: (title: string, description: string | undefined, context: DocumentContext) => Record<string, unknown>;
|
|
208
|
-
/**
|
|
209
|
-
* Add description to document body
|
|
210
|
-
*
|
|
211
|
-
* @defaultValue false
|
|
212
|
-
*/
|
|
213
|
-
includeDescription?: boolean;
|
|
214
|
-
cwd?: string;
|
|
215
|
-
}
|
|
216
|
-
interface GenerateTagOutput {
|
|
217
|
-
tag: string;
|
|
218
|
-
content: string;
|
|
219
|
-
}
|
|
220
|
-
type GeneratePageOutput = {
|
|
221
|
-
type: 'operation';
|
|
222
|
-
pathItem: NoReference<PathItemObject>;
|
|
223
|
-
operation: NoReference<OperationObject>;
|
|
224
|
-
item: OperationItem;
|
|
225
|
-
content: string;
|
|
226
|
-
} | {
|
|
227
|
-
type: 'webhook';
|
|
228
|
-
pathItem: NoReference<PathItemObject>;
|
|
229
|
-
operation: NoReference<OperationObject>;
|
|
230
|
-
item: WebhookItem;
|
|
231
|
-
content: string;
|
|
232
|
-
};
|
|
233
|
-
declare function generateAll(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<string>;
|
|
234
|
-
declare function generatePages(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<GeneratePageOutput[]>;
|
|
235
|
-
declare function generateTags(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<GenerateTagOutput[]>;
|
|
236
|
-
|
|
237
|
-
interface Config extends GenerateOptions {
|
|
238
|
-
/**
|
|
239
|
-
* Schema files
|
|
240
|
-
*/
|
|
241
|
-
input: string[] | string;
|
|
242
|
-
/**
|
|
243
|
-
* Output directory
|
|
244
|
-
*/
|
|
245
|
-
output: string;
|
|
246
|
-
/**
|
|
247
|
-
* tag: Generate a page for each tag
|
|
248
|
-
* file: Generate a page for each schema
|
|
249
|
-
* operation: Generate a page for each API endpoint/operation
|
|
250
|
-
*
|
|
251
|
-
* @defaultValue 'operation'
|
|
252
|
-
*/
|
|
253
|
-
per?: 'tag' | 'file' | 'operation';
|
|
254
|
-
/**
|
|
255
|
-
* Specify name for output file
|
|
256
|
-
*/
|
|
257
|
-
name?: (type: 'file' | 'tag', name: string) => string;
|
|
258
|
-
/**
|
|
259
|
-
* Group output using folders (Only works on `operation` mode)
|
|
260
|
-
*
|
|
261
|
-
* @deprecated Use `groupBy` instead
|
|
262
|
-
* @defaultValue false
|
|
263
|
-
*/
|
|
264
|
-
groupByFolder?: boolean;
|
|
265
|
-
/**
|
|
266
|
-
* Group output using folders (Only works on `operation` mode)
|
|
267
|
-
*
|
|
268
|
-
* @defaultValue 'none'
|
|
269
|
-
*/
|
|
270
|
-
groupBy?: 'tag' | 'route' | 'none';
|
|
271
|
-
}
|
|
272
|
-
declare function generateFiles(options: Config): Promise<void>;
|
|
273
|
-
|
|
274
|
-
export { type CallbackObject, type Config, type DereferenceMap, type Document, type GenerateOptions, type GeneratePageOutput, type GenerateTagOutput, type MethodInformation, type OperationObject, type ParameterObject, type PathItemObject, type ReferenceObject, type RenderContext, type SecurityRequirementObject, type SecuritySchemeObject, type ServerObject, type TagObject, generateAll, generateFiles, generatePages, generateTags };
|
|
1
|
+
export * from './generate';
|
|
2
|
+
export * from './generate-file';
|
|
3
|
+
export * from './types';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|