fumadocs-openapi 6.0.1 → 6.0.3
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-CsHhplmD.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 +8 -8
- package/dist/scalar/client-client-BXAjVueF.js +0 -93
- package/dist/ui/client-client-CYO00OiB.js +0 -107
- package/dist/ui/index-client-BUeWwFWK.js +0 -1116
- package/dist/ui/server-select-client-Ct_HJ46K.js +0 -86
package/dist/index.js
CHANGED
|
@@ -1,389 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { load, upgrade, dereference as dereference$1 } from '@scalar/openapi-parser';
|
|
5
|
-
import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls';
|
|
6
|
-
import { readFiles } from '@scalar/openapi-parser/plugins/read-files';
|
|
7
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
8
|
-
import fg from 'fast-glob';
|
|
9
|
-
|
|
10
|
-
const methodKeys = [
|
|
11
|
-
'get',
|
|
12
|
-
'post',
|
|
13
|
-
'patch',
|
|
14
|
-
'delete',
|
|
15
|
-
'head',
|
|
16
|
-
'put'
|
|
17
|
-
];
|
|
18
|
-
function getAPIPageItems(document) {
|
|
19
|
-
const result = {
|
|
20
|
-
webhooks: [],
|
|
21
|
-
operations: []
|
|
22
|
-
};
|
|
23
|
-
for (const [path, pathItem] of Object.entries(document.paths ?? {})){
|
|
24
|
-
if (!pathItem) continue;
|
|
25
|
-
for (const methodKey of methodKeys){
|
|
26
|
-
if (!pathItem[methodKey]) continue;
|
|
27
|
-
result.operations.push({
|
|
28
|
-
method: methodKey,
|
|
29
|
-
path,
|
|
30
|
-
tags: pathItem[methodKey]?.tags
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
for (const [name, pathItem] of Object.entries(document.webhooks ?? {})){
|
|
35
|
-
if (!pathItem) continue;
|
|
36
|
-
for (const methodKey of methodKeys){
|
|
37
|
-
if (!pathItem[methodKey]) continue;
|
|
38
|
-
result.webhooks.push({
|
|
39
|
-
method: methodKey,
|
|
40
|
-
name,
|
|
41
|
-
tags: pathItem[methodKey]?.tags
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function idToTitle(id) {
|
|
49
|
-
let result = [];
|
|
50
|
-
for (const c of id){
|
|
51
|
-
if (result.length === 0) result.push(c.toLocaleUpperCase());
|
|
52
|
-
else if (c === '.') result = [];
|
|
53
|
-
else if (/^[A-Z]$/.test(c) && result.at(-1) !== ' ') result.push(' ', c);
|
|
54
|
-
else if (c === '-') result.push(' ');
|
|
55
|
-
else result.push(c);
|
|
56
|
-
}
|
|
57
|
-
return result.join('');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function generateDocument(options) {
|
|
61
|
-
const { frontmatter, includeDescription = false } = options;
|
|
62
|
-
const out = [];
|
|
63
|
-
const extend = frontmatter?.(options.title, options.description, options.context);
|
|
64
|
-
let meta;
|
|
65
|
-
if (options.page.operations?.length === 1) {
|
|
66
|
-
const operation = options.page.operations[0];
|
|
67
|
-
meta = {
|
|
68
|
-
method: operation.method.toUpperCase(),
|
|
69
|
-
route: operation.path
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const data = generateStaticData(options.dereferenced, options.page);
|
|
73
|
-
const banner = dump({
|
|
74
|
-
title: options.title,
|
|
75
|
-
description: options.description,
|
|
76
|
-
full: true,
|
|
77
|
-
...extend,
|
|
78
|
-
_openapi: {
|
|
79
|
-
...meta,
|
|
80
|
-
...data,
|
|
81
|
-
...extend?._openapi
|
|
82
|
-
}
|
|
83
|
-
}).trim();
|
|
84
|
-
if (banner.length > 0) out.push(`---\n${banner}\n---`);
|
|
85
|
-
const imports = options.imports?.map((item)=>`import { ${item.names.join(', ')} } from ${JSON.stringify(item.from)};`).join('\n');
|
|
86
|
-
if (imports) {
|
|
87
|
-
out.push(imports);
|
|
88
|
-
}
|
|
89
|
-
if (options.description && includeDescription) out.push(options.description);
|
|
90
|
-
out.push(pageContent(options.page));
|
|
91
|
-
return out.join('\n\n');
|
|
92
|
-
}
|
|
93
|
-
function generateStaticData(dereferenced, props) {
|
|
94
|
-
const slugger = new Slugger();
|
|
95
|
-
const toc = [];
|
|
96
|
-
const structuredData = {
|
|
97
|
-
headings: [],
|
|
98
|
-
contents: []
|
|
99
|
-
};
|
|
100
|
-
for (const item of props.operations ?? []){
|
|
101
|
-
const operation = dereferenced.paths?.[item.path]?.[item.method];
|
|
102
|
-
if (!operation) continue;
|
|
103
|
-
if (props.hasHead && operation.operationId) {
|
|
104
|
-
const title = operation.summary ?? (operation.operationId ? idToTitle(operation.operationId) : item.path);
|
|
105
|
-
const id = slugger.slug(title);
|
|
106
|
-
toc.push({
|
|
107
|
-
depth: 2,
|
|
108
|
-
title,
|
|
109
|
-
url: `#${id}`
|
|
110
|
-
});
|
|
111
|
-
structuredData.headings.push({
|
|
112
|
-
content: title,
|
|
113
|
-
id
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
if (operation.description) structuredData.contents.push({
|
|
117
|
-
content: operation.description,
|
|
118
|
-
heading: structuredData.headings.at(-1)?.id
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
toc,
|
|
123
|
-
structuredData
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function pageContent(props) {
|
|
127
|
-
// filter extra properties in props
|
|
128
|
-
const operations = (props.operations ?? []).map((item)=>({
|
|
129
|
-
path: item.path,
|
|
130
|
-
method: item.method
|
|
131
|
-
}));
|
|
132
|
-
const webhooks = (props.webhooks ?? []).map((item)=>({
|
|
133
|
-
name: item.name,
|
|
134
|
-
method: item.method
|
|
135
|
-
}));
|
|
136
|
-
return `<APIPage document={${JSON.stringify(props.document)}} operations={${JSON.stringify(operations)}} webhooks={${JSON.stringify(webhooks)}} hasHead={${JSON.stringify(props.hasHead)}} />`;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const cache = new Map();
|
|
140
|
-
/**
|
|
141
|
-
* process & reference input document to a Fumadocs OpenAPI compatible format
|
|
142
|
-
*/ async function processDocument(document, disableCache = false) {
|
|
143
|
-
const cached = !disableCache && typeof document === 'string' ? cache.get(document) : null;
|
|
144
|
-
if (cached) return cached;
|
|
145
|
-
const dereferenceMap = new Map();
|
|
146
|
-
const loaded = await load(document, {
|
|
147
|
-
plugins: [
|
|
148
|
-
readFiles(),
|
|
149
|
-
fetchUrls()
|
|
150
|
-
]
|
|
151
|
-
});
|
|
152
|
-
// upgrade
|
|
153
|
-
loaded.specification = upgrade(loaded.specification).specification;
|
|
154
|
-
const { schema: dereferenced } = await dereference$1(loaded.filesystem, {
|
|
155
|
-
onDereference ({ ref, schema }) {
|
|
156
|
-
dereferenceMap.set(schema, ref);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
const processed = {
|
|
160
|
-
document: dereferenced,
|
|
161
|
-
dereferenceMap,
|
|
162
|
-
downloaded: loaded.specification
|
|
163
|
-
};
|
|
164
|
-
if (!disableCache && typeof document === 'string') {
|
|
165
|
-
cache.set(document, processed);
|
|
166
|
-
}
|
|
167
|
-
return processed;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async function dereference(pathOrDocument, options) {
|
|
171
|
-
return await processDocument(// resolve paths
|
|
172
|
-
typeof pathOrDocument === 'string' && !pathOrDocument.startsWith('http://') && !pathOrDocument.startsWith('https://') ? resolve(options.cwd ?? process.cwd(), pathOrDocument) : pathOrDocument).then((res)=>res.document);
|
|
173
|
-
}
|
|
174
|
-
async function generateAll(pathOrDocument, options = {}) {
|
|
175
|
-
const document = await dereference(pathOrDocument, options);
|
|
176
|
-
const items = getAPIPageItems(document);
|
|
177
|
-
return generateDocument({
|
|
178
|
-
...options,
|
|
179
|
-
dereferenced: document,
|
|
180
|
-
title: document.info.title,
|
|
181
|
-
description: document.info.description,
|
|
182
|
-
page: {
|
|
183
|
-
operations: items.operations,
|
|
184
|
-
webhooks: items.webhooks,
|
|
185
|
-
hasHead: true,
|
|
186
|
-
document: pathOrDocument
|
|
187
|
-
},
|
|
188
|
-
context: {
|
|
189
|
-
type: 'file'
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
async function generatePages(pathOrDocument, options = {}) {
|
|
194
|
-
const document = await dereference(pathOrDocument, options);
|
|
195
|
-
const items = getAPIPageItems(document);
|
|
196
|
-
const result = [];
|
|
197
|
-
for (const item of items.operations){
|
|
198
|
-
const pathItem = document.paths?.[item.path];
|
|
199
|
-
if (!pathItem) continue;
|
|
200
|
-
const operation = pathItem[item.method];
|
|
201
|
-
if (!operation) continue;
|
|
202
|
-
result.push({
|
|
203
|
-
type: 'operation',
|
|
204
|
-
pathItem,
|
|
205
|
-
operation,
|
|
206
|
-
item,
|
|
207
|
-
content: generateDocument({
|
|
208
|
-
...options,
|
|
209
|
-
page: {
|
|
210
|
-
operations: [
|
|
211
|
-
item
|
|
212
|
-
],
|
|
213
|
-
hasHead: false,
|
|
214
|
-
document: pathOrDocument
|
|
215
|
-
},
|
|
216
|
-
dereferenced: document,
|
|
217
|
-
title: operation.summary ?? pathItem.summary ?? idToTitle(operation.operationId ?? 'unknown'),
|
|
218
|
-
description: operation.description ?? pathItem.description,
|
|
219
|
-
context: {
|
|
220
|
-
type: 'operation'
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
for (const item of items.webhooks){
|
|
226
|
-
const pathItem = document.webhooks?.[item.name];
|
|
227
|
-
if (!pathItem) continue;
|
|
228
|
-
const operation = pathItem[item.method];
|
|
229
|
-
if (!operation) continue;
|
|
230
|
-
result.push({
|
|
231
|
-
type: 'webhook',
|
|
232
|
-
pathItem,
|
|
233
|
-
operation,
|
|
234
|
-
item,
|
|
235
|
-
content: generateDocument({
|
|
236
|
-
...options,
|
|
237
|
-
page: {
|
|
238
|
-
webhooks: [
|
|
239
|
-
item
|
|
240
|
-
],
|
|
241
|
-
hasHead: false,
|
|
242
|
-
document: pathOrDocument
|
|
243
|
-
},
|
|
244
|
-
dereferenced: document,
|
|
245
|
-
title: operation.summary ?? pathItem.summary ?? idToTitle(item.name),
|
|
246
|
-
description: operation.description ?? pathItem.description,
|
|
247
|
-
context: {
|
|
248
|
-
type: 'operation'
|
|
249
|
-
}
|
|
250
|
-
})
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
return result;
|
|
254
|
-
}
|
|
255
|
-
async function generateTags(pathOrDocument, options = {}) {
|
|
256
|
-
const document = await dereference(pathOrDocument, options);
|
|
257
|
-
if (!document.tags) return [];
|
|
258
|
-
const items = getAPIPageItems(document);
|
|
259
|
-
return document.tags.map((tag)=>{
|
|
260
|
-
const webhooks = items.webhooks.filter((v)=>v.tags && v.tags.includes(tag.name));
|
|
261
|
-
const operations = items.operations.filter((v)=>v.tags && v.tags.includes(tag.name));
|
|
262
|
-
const displayName = tag && 'x-displayName' in tag && typeof tag['x-displayName'] === 'string' ? tag['x-displayName'] : idToTitle(tag.name);
|
|
263
|
-
return {
|
|
264
|
-
tag: tag.name,
|
|
265
|
-
content: generateDocument({
|
|
266
|
-
...options,
|
|
267
|
-
page: {
|
|
268
|
-
document: pathOrDocument,
|
|
269
|
-
operations,
|
|
270
|
-
webhooks,
|
|
271
|
-
hasHead: true
|
|
272
|
-
},
|
|
273
|
-
dereferenced: document,
|
|
274
|
-
title: displayName,
|
|
275
|
-
description: tag?.description,
|
|
276
|
-
context: {
|
|
277
|
-
type: 'tag',
|
|
278
|
-
tag
|
|
279
|
-
}
|
|
280
|
-
})
|
|
281
|
-
};
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
async function generateFiles(options) {
|
|
286
|
-
const { input, output, name: nameFn, per = 'operation', groupBy = 'none', cwd = process.cwd() } = options;
|
|
287
|
-
const outputDir = join(cwd, output);
|
|
288
|
-
const urlInputs = [];
|
|
289
|
-
const fileInputs = [];
|
|
290
|
-
for (const v of typeof input === 'string' ? [
|
|
291
|
-
input
|
|
292
|
-
] : input){
|
|
293
|
-
if (isUrl(v)) {
|
|
294
|
-
urlInputs.push(v);
|
|
295
|
-
} else {
|
|
296
|
-
fileInputs.push(v);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
const resolvedInputs = [
|
|
300
|
-
...await fg.glob(fileInputs, {
|
|
301
|
-
cwd,
|
|
302
|
-
absolute: false
|
|
303
|
-
}),
|
|
304
|
-
...urlInputs
|
|
305
|
-
];
|
|
306
|
-
function getOutputPaths(result) {
|
|
307
|
-
let file;
|
|
308
|
-
if (result.pathItem.summary) {
|
|
309
|
-
file = getFilename(result.pathItem.summary);
|
|
310
|
-
} else if (result.type === 'operation') {
|
|
311
|
-
file = result.operation.operationId ? getFilename(result.operation.operationId) : join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
|
|
312
|
-
} else {
|
|
313
|
-
file = getFilename(result.item.name);
|
|
314
|
-
}
|
|
315
|
-
const outPaths = [];
|
|
316
|
-
if (groupBy === 'tag') {
|
|
317
|
-
const tags = result.operation.tags;
|
|
318
|
-
if (tags && tags.length > 0) {
|
|
319
|
-
for (const tag of tags){
|
|
320
|
-
outPaths.push(join(outputDir, getFilename(tag), `${file}.mdx`));
|
|
321
|
-
}
|
|
322
|
-
} else {
|
|
323
|
-
outPaths.push(result.type === 'operation' ? join(outputDir, `${file}.mdx`) : join(outputDir, 'webhooks', `${file}.mdx`));
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
if (groupBy === 'route' || groupBy === 'none') {
|
|
327
|
-
outPaths.push(join(outputDir, `${file}.mdx`));
|
|
328
|
-
}
|
|
329
|
-
return outPaths;
|
|
330
|
-
}
|
|
331
|
-
async function generateFromDocument(pathOrUrl) {
|
|
332
|
-
if (per === 'file') {
|
|
333
|
-
let filename = isUrl(pathOrUrl) ? 'index' : parse(pathOrUrl).name;
|
|
334
|
-
if (nameFn) filename = nameFn('file', filename);
|
|
335
|
-
const outPath = join(outputDir, `${filename}.mdx`);
|
|
336
|
-
const result = await generateAll(pathOrUrl, options);
|
|
337
|
-
await write(outPath, result);
|
|
338
|
-
console.log(`Generated: ${outPath}`);
|
|
339
|
-
}
|
|
340
|
-
if (per === 'operation') {
|
|
341
|
-
const metaFiles = new Set();
|
|
342
|
-
const results = await generatePages(pathOrUrl, options);
|
|
343
|
-
for (const result of results){
|
|
344
|
-
const meta = JSON.stringify({
|
|
345
|
-
title: result.pathItem.summary
|
|
346
|
-
}, null, 2);
|
|
347
|
-
for (const outPath of getOutputPaths(result)){
|
|
348
|
-
await write(outPath, result.content);
|
|
349
|
-
console.log(`Generated: ${outPath}`);
|
|
350
|
-
if (groupBy === 'route') {
|
|
351
|
-
const metaFile = join(dirname(outPath), 'meta.json');
|
|
352
|
-
if (!result.pathItem.summary || metaFiles.has(metaFile)) continue;
|
|
353
|
-
metaFiles.add(metaFile);
|
|
354
|
-
await write(metaFile, meta);
|
|
355
|
-
console.log(`Generated Meta: ${metaFile}`);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (per === 'tag') {
|
|
361
|
-
const results = await generateTags(pathOrUrl, options);
|
|
362
|
-
for (const result of results){
|
|
363
|
-
let tagName = result.tag;
|
|
364
|
-
tagName = nameFn?.('tag', tagName) ?? getFilename(tagName);
|
|
365
|
-
const outPath = join(outputDir, `${tagName}.mdx`);
|
|
366
|
-
await write(outPath, result.content);
|
|
367
|
-
console.log(`Generated: ${outPath}`);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
await Promise.all(resolvedInputs.map(generateFromDocument));
|
|
372
|
-
}
|
|
373
|
-
function isUrl(input) {
|
|
374
|
-
return input.startsWith('https://') || input.startsWith('http://');
|
|
375
|
-
}
|
|
376
|
-
function getOutputPathFromRoute(path) {
|
|
377
|
-
return path.replaceAll('.', '/').split('/').filter((v)=>!v.startsWith('{') && !v.endsWith('}')).at(-1) ?? '';
|
|
378
|
-
}
|
|
379
|
-
function getFilename(s) {
|
|
380
|
-
return s.replace(/[A-Z]/g, (match, idx)=>idx === 0 ? match : `-${match.toLowerCase()}`).replace(/\s+/g, '-').toLowerCase();
|
|
381
|
-
}
|
|
382
|
-
async function write(path, content) {
|
|
383
|
-
await mkdir(dirname(path), {
|
|
384
|
-
recursive: true
|
|
385
|
-
});
|
|
386
|
-
await writeFile(path, content);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
export { generateAll, generateFiles, generatePages, generateTags };
|
|
1
|
+
export * from './generate.js';
|
|
2
|
+
export * from './generate-file.js';
|
|
3
|
+
export * from './types.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type HTMLAttributes } from 'react';
|
|
2
|
+
import type { RenderContext } from '../types.js';
|
|
3
|
+
export type CodeBlockProps = HTMLAttributes<HTMLPreElement> & {
|
|
4
|
+
code: string;
|
|
5
|
+
lang: string;
|
|
6
|
+
options?: RenderContext['shikiOptions'];
|
|
7
|
+
};
|
|
8
|
+
export declare function CodeBlock({ code, lang, options, ...rest }: CodeBlockProps): Promise<React.ReactElement>;
|
|
9
|
+
//# sourceMappingURL=codeblock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeblock.d.ts","sourceRoot":"","sources":["../../src/render/codeblock.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C,MAAM,MAAM,cAAc,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;CACzC,CAAC;AAEF,wBAAsB,SAAS,CAAC,EAC9B,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,GAAG,IAAI,EACR,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAU9C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as Base from 'fumadocs-ui/components/codeblock';
|
|
3
|
+
import { highlight } from 'fumadocs-core/server';
|
|
4
|
+
export async function CodeBlock({ code, lang, options, ...rest }) {
|
|
5
|
+
const rendered = await highlight(code, {
|
|
6
|
+
lang,
|
|
7
|
+
...options,
|
|
8
|
+
components: {
|
|
9
|
+
pre: (props) => _jsx(Base.Pre, { ...props, ...rest }),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
return _jsx(Base.CodeBlock, { className: "my-0", children: rendered });
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/render/heading.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,wBAAgB,OAAO,CACrB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,aAAa,GACjB,SAAS,CAQX"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Heading } from 'fumadocs-ui/components/heading';
|
|
3
|
+
export function heading(depth, child, ctx) {
|
|
4
|
+
const id = ctx.slugger.slug(child);
|
|
5
|
+
return (_jsx(Heading, { id: id, as: `h${depth.toString()}`, children: child.trim() }, id));
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/render/markdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,OAAO,CAAC;AAsB1C,wBAAsB,QAAQ,CAAC,EAC7B,IAAI,GACL,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,YAAY,CAAC,CAWxB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { rehypeCode, remarkGfm, remarkImage, } from 'fumadocs-core/mdx-plugins';
|
|
2
|
+
import defaultMdxComponents from 'fumadocs-ui/mdx';
|
|
3
|
+
import { remark } from 'remark';
|
|
4
|
+
import remarkRehype from 'remark-rehype';
|
|
5
|
+
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
|
|
6
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
|
+
const processor = remark()
|
|
8
|
+
.use(remarkGfm)
|
|
9
|
+
.use(remarkImage, { useImport: false })
|
|
10
|
+
.use(remarkRehype)
|
|
11
|
+
.use(rehypeCode, {
|
|
12
|
+
langs: [],
|
|
13
|
+
lazy: true,
|
|
14
|
+
});
|
|
15
|
+
export async function Markdown({ text, }) {
|
|
16
|
+
const nodes = processor.parse({ value: text });
|
|
17
|
+
const hast = await processor.run(nodes);
|
|
18
|
+
return toJsxRuntime(hast, {
|
|
19
|
+
development: false,
|
|
20
|
+
jsx: jsx,
|
|
21
|
+
jsxs: jsxs,
|
|
22
|
+
Fragment,
|
|
23
|
+
components: defaultMdxComponents,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type EndpointSample } from '../utils/generate-sample.js';
|
|
3
|
+
import type { MethodInformation, RenderContext } from '../types.js';
|
|
4
|
+
export interface CodeSample {
|
|
5
|
+
lang: string;
|
|
6
|
+
label: string;
|
|
7
|
+
source: string | ((endpoint: EndpointSample) => string | undefined) | false;
|
|
8
|
+
}
|
|
9
|
+
export declare function Operation({ type, path, method, ctx, hasHead, headingLevel, }: {
|
|
10
|
+
type?: 'webhook' | 'operation';
|
|
11
|
+
path: string;
|
|
12
|
+
method: MethodInformation;
|
|
13
|
+
ctx: RenderContext;
|
|
14
|
+
hasHead?: boolean;
|
|
15
|
+
headingLevel?: number;
|
|
16
|
+
}): ReactElement;
|
|
17
|
+
//# sourceMappingURL=operation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/render/operation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAK9E,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAgBjB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,cAAc,KAAK,MAAM,GAAG,SAAS,CAAC,GAAG,KAAK,CAAC;CAC7E;AAQD,wBAAgB,SAAS,CAAC,EACxB,IAAkB,EAClB,IAAI,EACJ,MAAM,EACN,GAAG,EACH,OAAO,EACP,YAAgB,GACjB,EAAE;IACD,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;IAEnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,YAAY,CAoLf"}
|