fumadocs-openapi 9.0.0 → 9.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/generate-file.js +3 -3
- package/dist/generate.d.ts +10 -4
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +33 -46
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/playground/client.js +47 -24
- package/dist/playground/fetcher.d.ts.map +1 -1
- package/dist/playground/fetcher.js +23 -17
- package/dist/playground/index.js +1 -1
- 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/server/proxy.d.ts +11 -1
- package/dist/server/proxy.d.ts.map +1 -1
- package/dist/server/proxy.js +10 -3
- 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 +5 -5
- package/package.json +3 -3
package/dist/generate-file.js
CHANGED
|
@@ -86,7 +86,7 @@ async function generateFromDocument(pathOrUrl, options) {
|
|
|
86
86
|
return [`${file}.mdx`];
|
|
87
87
|
}
|
|
88
88
|
if (options.per === 'file') {
|
|
89
|
-
const result = await generateAll(document, options);
|
|
89
|
+
const result = await generateAll(pathOrUrl, document, options);
|
|
90
90
|
const filename = nameFn({
|
|
91
91
|
pathOrUrl,
|
|
92
92
|
content: result,
|
|
@@ -96,7 +96,7 @@ async function generateFromDocument(pathOrUrl, options) {
|
|
|
96
96
|
console.log(`Generated: ${outPath}`);
|
|
97
97
|
}
|
|
98
98
|
else if (options.per === 'tag') {
|
|
99
|
-
const results = await generateTags(document, options);
|
|
99
|
+
const results = await generateTags(pathOrUrl, document, options);
|
|
100
100
|
for (const result of results) {
|
|
101
101
|
const filename = nameFn(result, document.document);
|
|
102
102
|
const outPath = path.join(outputDir, `${filename}.mdx`);
|
|
@@ -105,7 +105,7 @@ async function generateFromDocument(pathOrUrl, options) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
108
|
-
const results = await generatePages(document, options);
|
|
108
|
+
const results = await generatePages(pathOrUrl, document, options);
|
|
109
109
|
const mapping = new Map();
|
|
110
110
|
for (const result of results) {
|
|
111
111
|
for (const outputPath of getOutputPaths(options.groupBy, result)) {
|
package/dist/generate.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type DocumentContext } from './utils/generate-document.js';
|
|
2
2
|
import type { OperationItem, WebhookItem } from './render/api-page.js';
|
|
3
|
-
import type { ProcessedDocument } from './utils/process-document.js';
|
|
3
|
+
import type { DocumentInput, ProcessedDocument } from './utils/process-document.js';
|
|
4
4
|
export interface GenerateOptions {
|
|
5
5
|
/**
|
|
6
6
|
* Additional imports of your MDX components.
|
|
@@ -33,6 +33,12 @@ export interface GenerateOptions {
|
|
|
33
33
|
*/
|
|
34
34
|
addGeneratedComment?: boolean | string;
|
|
35
35
|
cwd?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Inline the entire OpenAPI document into the MDX file.
|
|
38
|
+
*
|
|
39
|
+
* @defaultValue false
|
|
40
|
+
*/
|
|
41
|
+
inlineDocument?: boolean;
|
|
36
42
|
}
|
|
37
43
|
export interface GenerateTagOutput {
|
|
38
44
|
tag: string;
|
|
@@ -47,7 +53,7 @@ export type GeneratePageOutput = {
|
|
|
47
53
|
item: WebhookItem;
|
|
48
54
|
content: string;
|
|
49
55
|
};
|
|
50
|
-
export declare function generateAll(
|
|
51
|
-
export declare function generatePages(
|
|
52
|
-
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[]>;
|
|
53
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":"AACA,OAAO,EACL,KAAK,eAAe,EAErB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,
|
|
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,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;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAEvC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;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,25 +1,23 @@
|
|
|
1
1
|
import { getAPIPageItems } from './build-routes.js';
|
|
2
2
|
import { generateDocument, } from './utils/generate-document.js';
|
|
3
3
|
import { idToTitle } from './utils/id-to-title.js';
|
|
4
|
-
export async function generateAll(
|
|
4
|
+
export async function generateAll(input, processed, options = {}) {
|
|
5
|
+
const { document } = processed;
|
|
5
6
|
const items = getAPIPageItems(document);
|
|
6
|
-
return generateDocument({
|
|
7
|
+
return generateDocument(input, processed, {
|
|
8
|
+
operations: items.operations,
|
|
9
|
+
webhooks: items.webhooks,
|
|
10
|
+
hasHead: true,
|
|
11
|
+
}, {
|
|
7
12
|
...options,
|
|
8
|
-
dereferenced: document,
|
|
9
13
|
title: document.info.title,
|
|
10
14
|
description: document.info.description,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
webhooks: items.webhooks,
|
|
14
|
-
hasHead: true,
|
|
15
|
-
document: downloaded,
|
|
16
|
-
},
|
|
17
|
-
context: {
|
|
18
|
-
type: 'file',
|
|
19
|
-
},
|
|
15
|
+
}, {
|
|
16
|
+
type: 'file',
|
|
20
17
|
});
|
|
21
18
|
}
|
|
22
|
-
export async function generatePages(
|
|
19
|
+
export async function generatePages(input, processed, options = {}) {
|
|
20
|
+
const { document } = processed;
|
|
23
21
|
const items = getAPIPageItems(document);
|
|
24
22
|
const result = [];
|
|
25
23
|
for (const item of items.operations) {
|
|
@@ -32,21 +30,17 @@ export async function generatePages({ document, downloaded }, options = {}) {
|
|
|
32
30
|
result.push({
|
|
33
31
|
type: 'operation',
|
|
34
32
|
item,
|
|
35
|
-
content: generateDocument({
|
|
33
|
+
content: generateDocument(input, processed, {
|
|
34
|
+
operations: [item],
|
|
35
|
+
hasHead: false,
|
|
36
|
+
}, {
|
|
36
37
|
...options,
|
|
37
|
-
page: {
|
|
38
|
-
operations: [item],
|
|
39
|
-
hasHead: false,
|
|
40
|
-
document: downloaded,
|
|
41
|
-
},
|
|
42
|
-
dereferenced: document,
|
|
43
38
|
title: operation.summary ??
|
|
44
39
|
pathItem.summary ??
|
|
45
40
|
idToTitle(operation.operationId ?? 'unknown'),
|
|
46
41
|
description: operation.description ?? pathItem.description,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
42
|
+
}, {
|
|
43
|
+
type: 'operation',
|
|
50
44
|
}),
|
|
51
45
|
});
|
|
52
46
|
}
|
|
@@ -60,25 +54,22 @@ export async function generatePages({ document, downloaded }, options = {}) {
|
|
|
60
54
|
result.push({
|
|
61
55
|
type: 'webhook',
|
|
62
56
|
item,
|
|
63
|
-
content: generateDocument({
|
|
57
|
+
content: generateDocument(input, processed, {
|
|
58
|
+
webhooks: [item],
|
|
59
|
+
hasHead: false,
|
|
60
|
+
}, {
|
|
64
61
|
...options,
|
|
65
|
-
page: {
|
|
66
|
-
webhooks: [item],
|
|
67
|
-
hasHead: false,
|
|
68
|
-
document: downloaded,
|
|
69
|
-
},
|
|
70
|
-
dereferenced: document,
|
|
71
62
|
title: operation.summary ?? pathItem.summary ?? idToTitle(item.name),
|
|
72
63
|
description: operation.description ?? pathItem.description,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
},
|
|
64
|
+
}, {
|
|
65
|
+
type: 'operation',
|
|
76
66
|
}),
|
|
77
67
|
});
|
|
78
68
|
}
|
|
79
69
|
return result;
|
|
80
70
|
}
|
|
81
|
-
export async function generateTags(
|
|
71
|
+
export async function generateTags(input, processed, options = {}) {
|
|
72
|
+
const { document } = processed;
|
|
82
73
|
if (!document.tags)
|
|
83
74
|
return [];
|
|
84
75
|
const items = getAPIPageItems(document);
|
|
@@ -90,21 +81,17 @@ export async function generateTags({ document, downloaded }, options = {}) {
|
|
|
90
81
|
: idToTitle(tag.name);
|
|
91
82
|
return {
|
|
92
83
|
tag: tag.name,
|
|
93
|
-
content: generateDocument({
|
|
84
|
+
content: generateDocument(input, processed, {
|
|
85
|
+
operations,
|
|
86
|
+
webhooks,
|
|
87
|
+
hasHead: true,
|
|
88
|
+
}, {
|
|
94
89
|
...options,
|
|
95
|
-
page: {
|
|
96
|
-
document: downloaded,
|
|
97
|
-
operations,
|
|
98
|
-
webhooks,
|
|
99
|
-
hasHead: true,
|
|
100
|
-
},
|
|
101
|
-
dereferenced: document,
|
|
102
90
|
title: displayName,
|
|
103
91
|
description: tag?.description,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
},
|
|
92
|
+
}, {
|
|
93
|
+
type: 'tag',
|
|
94
|
+
tag,
|
|
108
95
|
}),
|
|
109
96
|
};
|
|
110
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
|
@@ -65,7 +65,7 @@ export default function Client({ route, method = 'GET', authorization, parameter
|
|
|
65
65
|
const value = _value;
|
|
66
66
|
if (authorization && value.authorization) {
|
|
67
67
|
authInfo.saveInfo(value.authorization);
|
|
68
|
-
|
|
68
|
+
writeAuthInfo(authorization, value.authorization, value.header, value.query, value.cookie);
|
|
69
69
|
}
|
|
70
70
|
requestData.saveData(toRequestData(method, body?.mediaType, value));
|
|
71
71
|
});
|
|
@@ -85,38 +85,61 @@ function FormBody({ authorization, parameters = [], fields = {}, body, }) {
|
|
|
85
85
|
const params = useMemo(() => {
|
|
86
86
|
return paramTypes.map((param) => parameters.filter((v) => v.in === param));
|
|
87
87
|
}, [parameters]);
|
|
88
|
-
|
|
88
|
+
const auth = useMemo(() => {
|
|
89
89
|
if (!authorization)
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
return;
|
|
91
|
+
if (authorization.type === 'http' && authorization.scheme === 'basic') {
|
|
92
|
+
return {
|
|
93
|
+
in: 'header',
|
|
94
|
+
field: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
required: ['username', 'password'],
|
|
97
|
+
description: authorization.description,
|
|
98
|
+
properties: {
|
|
99
|
+
username: {
|
|
100
|
+
type: 'string',
|
|
101
|
+
},
|
|
102
|
+
password: {
|
|
103
|
+
type: 'string',
|
|
104
|
+
},
|
|
101
105
|
},
|
|
102
106
|
},
|
|
103
|
-
}
|
|
104
|
-
: {
|
|
105
|
-
type: 'string',
|
|
106
|
-
description: 'The Authorization access token',
|
|
107
107
|
};
|
|
108
|
+
}
|
|
109
|
+
else if (authorization.type === 'http' ||
|
|
110
|
+
authorization.type === 'oauth2') {
|
|
111
|
+
return {
|
|
112
|
+
in: 'header',
|
|
113
|
+
field: {
|
|
114
|
+
type: 'string',
|
|
115
|
+
description: authorization.description ?? `The Authorization access token.`,
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
else if (authorization.type === 'apiKey') {
|
|
120
|
+
return {
|
|
121
|
+
in: authorization.in,
|
|
122
|
+
field: {
|
|
123
|
+
type: 'string',
|
|
124
|
+
description: authorization.description ?? 'The API key.',
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// TODO: handle OpenID connect
|
|
129
|
+
}, [authorization]);
|
|
130
|
+
function renderAuth() {
|
|
131
|
+
if (!auth)
|
|
132
|
+
return null;
|
|
108
133
|
if (fields?.auth)
|
|
109
|
-
return renderCustomField('authorization',
|
|
110
|
-
return (_jsx(FieldSet, { fieldName: "authorization", name: "Authorization", field:
|
|
134
|
+
return renderCustomField('authorization', auth.field, fields.auth);
|
|
135
|
+
return (_jsx(FieldSet, { fieldName: "authorization", name: "Authorization", field: auth.field, isRequired: true }));
|
|
111
136
|
}
|
|
112
137
|
return (_jsxs(_Fragment, { children: [params.map((param, i) => {
|
|
113
138
|
const name = paramNames[i];
|
|
114
139
|
const type = paramTypes[i];
|
|
115
|
-
if (type !==
|
|
116
|
-
return;
|
|
117
|
-
if (type === 'header' && !authorization && param.length === 0)
|
|
140
|
+
if ((!auth || type !== auth.in) && param.length === 0)
|
|
118
141
|
return;
|
|
119
|
-
return (_jsxs(CollapsiblePanel, { title: name, children: [type ===
|
|
142
|
+
return (_jsxs(CollapsiblePanel, { title: name, children: [auth && type === auth.in ? renderAuth() : null, param.map((field) => {
|
|
120
143
|
const fieldName = `${type}.${field.name}`;
|
|
121
144
|
if (fields?.parameter) {
|
|
122
145
|
return renderCustomField(fieldName, field.schema, fields.parameter, field.name);
|
|
@@ -209,7 +232,7 @@ function usePersistentAuthInfo(authorization) {
|
|
|
209
232
|
function CollapsiblePanel({ title, children, ...props }) {
|
|
210
233
|
return (_jsxs(Collapsible, { ...props, className: "border-b last:border-b-0", children: [_jsxs(CollapsibleTrigger, { className: "group w-full flex items-center gap-2 p-3 text-sm font-medium", children: [title, _jsx(ChevronDown, { className: "ms-auto size-3.5 text-fd-muted-foreground group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { children: _jsx("div", { className: "flex flex-col gap-3 p-3 pt-1", children: children }) })] }));
|
|
211
234
|
}
|
|
212
|
-
function
|
|
235
|
+
function writeAuthInfo(authorization, input, header, query, cookie) {
|
|
213
236
|
if (authorization.type === 'apiKey') {
|
|
214
237
|
if (authorization.in === 'header') {
|
|
215
238
|
header[authorization.name] = input;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/playground/fetcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;CACvE;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GACrC,OAAO,
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/playground/fetcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;CACvE;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GACrC,OAAO,CAkGT"}
|
|
@@ -13,23 +13,6 @@ export function createBrowserFetcher(adapters) {
|
|
|
13
13
|
const proxyUrl = options.proxyUrl
|
|
14
14
|
? new URL(options.proxyUrl, window.location.origin)
|
|
15
15
|
: null;
|
|
16
|
-
if (typeof document !== 'undefined') {
|
|
17
|
-
for (const key in options.cookie) {
|
|
18
|
-
const value = options.cookie[key];
|
|
19
|
-
if (!value)
|
|
20
|
-
continue;
|
|
21
|
-
document.cookie = [
|
|
22
|
-
`${key}=${value}`,
|
|
23
|
-
'HttpOnly',
|
|
24
|
-
proxyUrl &&
|
|
25
|
-
proxyUrl.origin !== window.location.origin &&
|
|
26
|
-
`domain=${proxyUrl.host}`,
|
|
27
|
-
'path=/',
|
|
28
|
-
]
|
|
29
|
-
.filter(Boolean)
|
|
30
|
-
.join(';');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
16
|
let url = getPathnameFromInput(route, options.path, options.query);
|
|
34
17
|
if (proxyUrl) {
|
|
35
18
|
proxyUrl.searchParams.append('url', url);
|
|
@@ -46,6 +29,29 @@ export function createBrowserFetcher(adapters) {
|
|
|
46
29
|
};
|
|
47
30
|
body = await adapter.encode(options);
|
|
48
31
|
}
|
|
32
|
+
// cookies
|
|
33
|
+
for (const key in options.cookie) {
|
|
34
|
+
const value = options.cookie[key];
|
|
35
|
+
if (!value)
|
|
36
|
+
continue;
|
|
37
|
+
const cookie = {
|
|
38
|
+
[key]: value,
|
|
39
|
+
domain: proxyUrl && proxyUrl.origin !== window.location.origin
|
|
40
|
+
? `domain=${proxyUrl.host}`
|
|
41
|
+
: undefined,
|
|
42
|
+
path: '/',
|
|
43
|
+
'max-age': 30,
|
|
44
|
+
};
|
|
45
|
+
let str = '';
|
|
46
|
+
for (const [key, value] of Object.entries(cookie)) {
|
|
47
|
+
if (value) {
|
|
48
|
+
if (str.length > 0)
|
|
49
|
+
str += '; ';
|
|
50
|
+
str += `${key}=${value}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
document.cookie = str;
|
|
54
|
+
}
|
|
49
55
|
return fetch(url, {
|
|
50
56
|
method: options.method,
|
|
51
57
|
cache: 'no-cache',
|
package/dist/playground/index.js
CHANGED
|
@@ -81,7 +81,7 @@ function getAuthorizationField(method, { schema: { document } }) {
|
|
|
81
81
|
item = requirements;
|
|
82
82
|
}
|
|
83
83
|
if (!item) {
|
|
84
|
-
console.warn(`Cannot find suitable security scheme for API Playground from ${JSON.stringify(security, null, 2)}. Only schemes with one requirement are allowed.`);
|
|
84
|
+
console.warn(`Cannot find suitable security scheme for API Playground from ${JSON.stringify(security, null, 2)}. Only schemes with one requirement are allowed at the moment.`);
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
const scheme = getSecurities(item, document)[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-page.d.ts","sourceRoot":"","sources":["../../src/render/api-page.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAIlC,KAAK,mBAAmB,GAAG,IAAI,CAC7B,OAAO,CAAC,aAAa,CAAC,EACpB,cAAc,GACd,0BAA0B,GAC1B,qBAAqB,GACrB,UAAU,GACV,oBAAoB,GACpB,mBAAmB,GACnB,eAAe,CAClB,CAAC;AAEF,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACvD,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IAEjB,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE7B;;OAEG;IACH,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAE7B,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IAEzB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC;CACjC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC;CACjC;AAED,wBAAsB,OAAO,CAAC,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"api-page.d.ts","sourceRoot":"","sources":["../../src/render/api-page.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAIlC,KAAK,mBAAmB,GAAG,IAAI,CAC7B,OAAO,CAAC,aAAa,CAAC,EACpB,cAAc,GACd,0BAA0B,GAC1B,qBAAqB,GACrB,UAAU,GACV,oBAAoB,GACpB,mBAAmB,GACnB,eAAe,CAClB,CAAC;AAEF,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACvD,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IAEjB,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE7B;;OAEG;IACH,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAE7B,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IAEzB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC;CACjC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC;CACjC;AAED,wBAAsB,OAAO,CAAC,KAAK,EAAE,YAAY,oDAqEhD;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,mBAAmB,GAAG;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;CACzB,GACL,OAAO,CAAC,aAAa,CAAC,CA0CxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/render/markdown.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/render/markdown.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,OAAO,CAAC;AAkC1C,wBAAsB,QAAQ,CAAC,EAC7B,IAAI,GACL,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,YAAY,CAAC,CAIxB"}
|
package/dist/render/markdown.js
CHANGED
|
@@ -3,7 +3,7 @@ import defaultMdxComponents from 'fumadocs-ui/mdx';
|
|
|
3
3
|
import { remark } from 'remark';
|
|
4
4
|
import remarkRehype from 'remark-rehype';
|
|
5
5
|
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
|
|
6
|
-
import
|
|
6
|
+
import * as JsxRuntime from 'react/jsx-runtime';
|
|
7
7
|
const processor = remark()
|
|
8
8
|
.use(remarkGfm)
|
|
9
9
|
.use(remarkImage, { useImport: false })
|
|
@@ -11,15 +11,19 @@ const processor = remark()
|
|
|
11
11
|
.use(rehypeCode, {
|
|
12
12
|
langs: [],
|
|
13
13
|
lazy: true,
|
|
14
|
-
})
|
|
14
|
+
})
|
|
15
|
+
.use(rehypeReact);
|
|
16
|
+
function rehypeReact() {
|
|
17
|
+
this.compiler = (tree, file) => {
|
|
18
|
+
return toJsxRuntime(tree, {
|
|
19
|
+
development: false,
|
|
20
|
+
filePath: file.path,
|
|
21
|
+
...JsxRuntime,
|
|
22
|
+
components: defaultMdxComponents,
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
15
26
|
export async function Markdown({ text, }) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
return toJsxRuntime(hast, {
|
|
19
|
-
development: false,
|
|
20
|
-
jsx: jsx,
|
|
21
|
-
jsxs: jsxs,
|
|
22
|
-
Fragment,
|
|
23
|
-
components: defaultMdxComponents,
|
|
24
|
-
});
|
|
27
|
+
const out = await processor.process(text);
|
|
28
|
+
return out.result;
|
|
25
29
|
}
|
|
@@ -45,7 +45,8 @@ export function getAPIExamples(path, method, ctx) {
|
|
|
45
45
|
data: getRequestData(path, method, key, ctx),
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
if (result.length > 0)
|
|
49
|
+
return result;
|
|
49
50
|
}
|
|
50
51
|
return [
|
|
51
52
|
{
|
|
@@ -68,7 +69,7 @@ export async function APIExample({ method, examples, ctx, }) {
|
|
|
68
69
|
title: sample.name,
|
|
69
70
|
description: sample.description ? (_jsx(Markdown, { text: sample.description })) : null,
|
|
70
71
|
value: sample.key,
|
|
71
|
-
})) })), generators.length > 0 && (_jsx(renderer.Requests, { items: generators.map((s) => s.label), children: generators.map((generator) => (_jsx(renderer.Request, { name: generator.label, children: _jsx(CodeExample, { ...generator }) },
|
|
72
|
+
})) })), generators.length > 0 && (_jsx(renderer.Requests, { items: generators.map((s) => s.label ?? s.lang), children: generators.map((generator, i) => (_jsx(renderer.Request, { name: generator.label ?? generator.lang, children: _jsx(CodeExample, { ...generator }) }, i))) })), _jsx(ResponseTabs, { operation: method, ctx: ctx })] }));
|
|
72
73
|
}
|
|
73
74
|
/**
|
|
74
75
|
* Remove duplicated labels
|
|
@@ -77,10 +78,13 @@ function dedupe(samples) {
|
|
|
77
78
|
const set = new Set();
|
|
78
79
|
const out = [];
|
|
79
80
|
for (let i = samples.length - 1; i >= 0; i--) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
const item = samples[i];
|
|
82
|
+
if (item.label) {
|
|
83
|
+
if (set.has(item.label))
|
|
84
|
+
continue;
|
|
85
|
+
set.add(item.label);
|
|
86
|
+
}
|
|
87
|
+
out.unshift(item);
|
|
84
88
|
}
|
|
85
89
|
return out;
|
|
86
90
|
}
|
|
@@ -3,7 +3,7 @@ import type { MethodInformation, RenderContext } from '../../types.js';
|
|
|
3
3
|
import { type SampleGenerator } from '../../requests/_shared.js';
|
|
4
4
|
export interface CodeSample {
|
|
5
5
|
lang: string;
|
|
6
|
-
label
|
|
6
|
+
label?: string;
|
|
7
7
|
source?: string | SampleGenerator | false;
|
|
8
8
|
}
|
|
9
9
|
export declare function Operation({ type, path, method, ctx, hasHead, headingLevel, }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/render/operation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAmBjB,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAK1D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/render/operation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAmBjB,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAK1D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,KAAK,CAAC;CAC3C;AASD,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,CA6Kf"}
|
package/dist/server/proxy.d.ts
CHANGED
|
@@ -3,6 +3,16 @@ declare const keys: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"];
|
|
|
3
3
|
type Proxy = {
|
|
4
4
|
[K in (typeof keys)[number]]: (req: NextRequest) => Promise<Response>;
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
interface CreateProxyOptions {
|
|
7
|
+
allowedUrls?: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Override original request/response with yours
|
|
10
|
+
*/
|
|
11
|
+
overrides?: {
|
|
12
|
+
request?: (request: Request) => Request;
|
|
13
|
+
response?: (response: Response) => Response;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function createProxy(options?: CreateProxyOptions): Proxy;
|
|
7
17
|
export {};
|
|
8
18
|
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/server/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,QAAA,MAAM,IAAI,4DAA6D,CAAC;AAExE,KAAK,KAAK,GAAG;KACV,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC;CACtE,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/server/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,QAAA,MAAM,IAAI,4DAA6D,CAAC;AAExE,KAAK,KAAK,GAAG;KACV,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC;CACtE,CAAC;AAEF,UAAU,kBAAkB;IAC1B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IAEvB;;OAEG;IACH,SAAS,CAAC,EAAE;QACV,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;QACxC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,QAAQ,CAAC;KAC7C,CAAC;CACH;AAED,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,KAAK,CA8EnE"}
|
package/dist/server/proxy.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const keys = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'];
|
|
2
|
-
export function createProxy(
|
|
2
|
+
export function createProxy(options = {}) {
|
|
3
|
+
const { allowedUrls, overrides } = options;
|
|
3
4
|
const handlers = {};
|
|
4
5
|
async function handler(req) {
|
|
5
6
|
const url = req.nextUrl.searchParams.get('url');
|
|
@@ -14,11 +15,14 @@ export function createProxy(allowedUrls) {
|
|
|
14
15
|
status: 400,
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
let clonedReq = new Request(url, {
|
|
18
19
|
...req,
|
|
19
20
|
cache: 'no-cache',
|
|
20
21
|
mode: 'cors',
|
|
21
22
|
});
|
|
23
|
+
if (overrides?.request) {
|
|
24
|
+
clonedReq = overrides.request(clonedReq);
|
|
25
|
+
}
|
|
22
26
|
clonedReq.headers.forEach((_value, originalKey) => {
|
|
23
27
|
const key = originalKey.toLowerCase();
|
|
24
28
|
const notAllowed = key === 'origin';
|
|
@@ -26,12 +30,15 @@ export function createProxy(allowedUrls) {
|
|
|
26
30
|
clonedReq.headers.delete(originalKey);
|
|
27
31
|
}
|
|
28
32
|
});
|
|
29
|
-
|
|
33
|
+
let res = await fetch(clonedReq).catch((e) => new Error(e.toString()));
|
|
30
34
|
if (res instanceof Error) {
|
|
31
35
|
return Response.json(`Failed to proxy request: ${res.message}`, {
|
|
32
36
|
status: 400,
|
|
33
37
|
});
|
|
34
38
|
}
|
|
39
|
+
if (overrides?.response) {
|
|
40
|
+
res = overrides.response(res);
|
|
41
|
+
}
|
|
35
42
|
const headers = new Headers(res.headers);
|
|
36
43
|
headers.forEach((_value, originalKey) => {
|
|
37
44
|
const key = originalKey.toLowerCase();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ApiPageProps } from '../render/api-page.js';
|
|
2
2
|
import type { GenerateOptions } from '../generate.js';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { TagObject } from '../types.js';
|
|
4
|
+
import type { DocumentInput, ProcessedDocument } from '../utils/process-document.js';
|
|
5
5
|
export type DocumentContext = {
|
|
6
6
|
type: 'tag';
|
|
7
7
|
tag: TagObject | undefined;
|
|
@@ -10,11 +10,8 @@ export type DocumentContext = {
|
|
|
10
10
|
} | {
|
|
11
11
|
type: 'file';
|
|
12
12
|
};
|
|
13
|
-
export declare function generateDocument(options: GenerateOptions & {
|
|
14
|
-
dereferenced: NoReference<Document>;
|
|
15
|
-
page: ApiPageProps;
|
|
13
|
+
export declare function generateDocument(input: DocumentInput, processed: ProcessedDocument, pageProps: Omit<ApiPageProps, 'document'>, options: GenerateOptions & {
|
|
16
14
|
title: string;
|
|
17
15
|
description?: string;
|
|
18
|
-
|
|
19
|
-
}): string;
|
|
16
|
+
}, context: DocumentContext): string;
|
|
20
17
|
//# sourceMappingURL=generate-document.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-document.d.ts","sourceRoot":"","sources":["../../src/utils/generate-document.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"generate-document.d.ts","sourceRoot":"","sources":["../../src/utils/generate-document.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAY,SAAS,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAOlC,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,SAAS,GAAG,SAAS,CAAC;CAC5B,GACD;IACE,IAAI,EAAE,WAAW,CAAC;CACnB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,aAAa,EACpB,SAAS,EAAE,iBAAiB,EAC5B,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,EACzC,OAAO,EAAE,eAAe,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,EACD,OAAO,EAAE,eAAe,GACvB,MAAM,CAkER"}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { dump } from 'js-yaml';
|
|
2
2
|
import Slugger from 'github-slugger';
|
|
3
3
|
import { idToTitle } from '../utils/id-to-title.js';
|
|
4
|
-
export function generateDocument(options) {
|
|
4
|
+
export function generateDocument(input, processed, pageProps, options, context) {
|
|
5
5
|
const { frontmatter, includeDescription = false, addGeneratedComment = true, } = options;
|
|
6
6
|
const out = [];
|
|
7
|
-
const extend = frontmatter?.(options.title, options.description,
|
|
7
|
+
const extend = frontmatter?.(options.title, options.description, context);
|
|
8
|
+
const page = {
|
|
9
|
+
...pageProps,
|
|
10
|
+
document: options.inlineDocument ? processed.downloaded : input,
|
|
11
|
+
};
|
|
8
12
|
let meta;
|
|
9
|
-
if (
|
|
10
|
-
const operation =
|
|
13
|
+
if (page.operations?.length === 1) {
|
|
14
|
+
const operation = page.operations[0];
|
|
11
15
|
meta = {
|
|
12
16
|
method: operation.method.toUpperCase(),
|
|
13
17
|
route: operation.path,
|
|
14
18
|
};
|
|
15
19
|
}
|
|
16
|
-
const data = generateStaticData(
|
|
20
|
+
const data = generateStaticData(processed.document, page);
|
|
17
21
|
const banner = dump({
|
|
18
22
|
title: options.title,
|
|
19
23
|
description: !includeDescription ? options.description : undefined,
|
|
@@ -43,7 +47,7 @@ export function generateDocument(options) {
|
|
|
43
47
|
}
|
|
44
48
|
if (options.description && includeDescription)
|
|
45
49
|
out.push(options.description);
|
|
46
|
-
out.push(pageContent(
|
|
50
|
+
out.push(pageContent(page));
|
|
47
51
|
return out.join('\n\n');
|
|
48
52
|
}
|
|
49
53
|
function generateStaticData(dereferenced, props) {
|
|
@@ -10,5 +10,5 @@ export type ProcessedDocument = {
|
|
|
10
10
|
/**
|
|
11
11
|
* process & reference input document to a Fumadocs OpenAPI compatible format
|
|
12
12
|
*/
|
|
13
|
-
export declare function processDocument(
|
|
13
|
+
export declare function processDocument(input: DocumentInput, disableCache?: boolean): Promise<ProcessedDocument>;
|
|
14
14
|
//# sourceMappingURL=process-document.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-document.d.ts","sourceRoot":"","sources":["../../src/utils/process-document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5D,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,WAAW,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;AAE/E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAChC,cAAc,EAAE,cAAc,CAAC;IAC/B,UAAU,EAAE,QAAQ,CAAC;CACtB,CAAC;AAIF;;GAEG;AACH,wBAAsB,eAAe,CACnC,
|
|
1
|
+
{"version":3,"file":"process-document.d.ts","sourceRoot":"","sources":["../../src/utils/process-document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5D,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,WAAW,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;AAE/E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAChC,cAAc,EAAE,cAAc,CAAC;IAC/B,UAAU,EAAE,QAAQ,CAAC;CACtB,CAAC;AAIF;;GAEG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,aAAa,EACpB,YAAY,UAAQ,GACnB,OAAO,CAAC,iBAAiB,CAAC,CAoC5B"}
|
|
@@ -5,12 +5,12 @@ const cache = new Map();
|
|
|
5
5
|
/**
|
|
6
6
|
* process & reference input document to a Fumadocs OpenAPI compatible format
|
|
7
7
|
*/
|
|
8
|
-
export async function processDocument(
|
|
9
|
-
const cached = !disableCache && typeof
|
|
8
|
+
export async function processDocument(input, disableCache = false) {
|
|
9
|
+
const cached = !disableCache && typeof input === 'string' ? cache.get(input) : null;
|
|
10
10
|
if (cached)
|
|
11
11
|
return cached;
|
|
12
12
|
const dereferenceMap = new Map();
|
|
13
|
-
const loaded = await load(
|
|
13
|
+
const loaded = await load(input, {
|
|
14
14
|
plugins: [readFiles(), fetchUrls()],
|
|
15
15
|
});
|
|
16
16
|
if (loaded.errors && loaded.errors.length > 0) {
|
|
@@ -28,8 +28,8 @@ export async function processDocument(document, disableCache = false) {
|
|
|
28
28
|
dereferenceMap,
|
|
29
29
|
downloaded: loaded.specification,
|
|
30
30
|
};
|
|
31
|
-
if (!disableCache && typeof
|
|
32
|
-
cache.set(
|
|
31
|
+
if (!disableCache && typeof input === 'string') {
|
|
32
|
+
cache.set(input, processed);
|
|
33
33
|
}
|
|
34
34
|
return processed;
|
|
35
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.2",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"shiki": "^3.4.2",
|
|
64
64
|
"tinyglobby": "^0.2.13",
|
|
65
65
|
"xml-js": "^1.6.11",
|
|
66
|
-
"fumadocs-core": "15.4.
|
|
67
|
-
"fumadocs-ui": "15.4.
|
|
66
|
+
"fumadocs-core": "15.4.1",
|
|
67
|
+
"fumadocs-ui": "15.4.1"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@scalar/api-client-react": "^1.3.3",
|