fumadocs-openapi 8.1.4 → 8.1.6
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 +1 -1
- package/dist/media/adapter.client.d.ts +8 -0
- package/dist/media/adapter.client.d.ts.map +1 -0
- package/dist/media/adapter.client.js +118 -0
- package/dist/media/adapter.d.ts +37 -0
- package/dist/media/adapter.d.ts.map +1 -0
- package/dist/media/adapter.js +9 -0
- package/dist/playground/client.d.ts +3 -1
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +6 -4
- package/dist/playground/fetcher.d.ts +3 -6
- package/dist/playground/fetcher.d.ts.map +1 -1
- package/dist/playground/fetcher.js +17 -52
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +1 -2
- package/dist/playground/inputs.d.ts.map +1 -1
- package/dist/playground/inputs.js +1 -1
- package/dist/render/api-page.d.ts +1 -1
- package/dist/render/api-page.d.ts.map +1 -1
- package/dist/render/api-page.js +7 -2
- package/dist/render/operation/index.d.ts +2 -2
- package/dist/render/operation/index.d.ts.map +1 -1
- package/dist/render/operation/index.js +1 -3
- package/dist/render/renderer.d.ts +3 -5
- package/dist/render/renderer.d.ts.map +1 -1
- package/dist/render/renderer.js +3 -3
- package/dist/requests/_shared.d.ts +5 -7
- package/dist/requests/_shared.d.ts.map +1 -1
- package/dist/requests/_shared.js +0 -11
- package/dist/requests/curl.d.ts +2 -2
- package/dist/requests/curl.d.ts.map +1 -1
- package/dist/requests/curl.js +16 -9
- package/dist/requests/go.d.ts +2 -2
- package/dist/requests/go.d.ts.map +1 -1
- package/dist/requests/go.js +13 -21
- package/dist/requests/index.js +4 -4
- package/dist/requests/javascript.d.ts +2 -2
- package/dist/requests/javascript.d.ts.map +1 -1
- package/dist/requests/javascript.js +20 -27
- package/dist/requests/python.d.ts +2 -2
- package/dist/requests/python.d.ts.map +1 -1
- package/dist/requests/python.js +23 -26
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/contexts/api.d.ts +2 -0
- package/dist/ui/contexts/api.d.ts.map +1 -1
- package/dist/ui/contexts/api.js +2 -2
- package/dist/ui/contexts/code-example.d.ts.map +1 -1
- package/dist/ui/contexts/code-example.js +5 -3
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +2 -2
- package/dist/utils/input-to-string.d.ts +1 -1
- package/dist/utils/input-to-string.d.ts.map +1 -1
- package/dist/utils/input-to-string.js +5 -0
- package/dist/utils/process-document.js +1 -1
- package/package.json +6 -6
package/dist/generate-file.js
CHANGED
|
@@ -82,7 +82,7 @@ export async function generateFiles(options) {
|
|
|
82
82
|
let outputPath = key;
|
|
83
83
|
const isSharedDir = Array.from(mapping.keys()).some((item) => item !== outputPath &&
|
|
84
84
|
path.dirname(item) === path.dirname(outputPath));
|
|
85
|
-
if (!isSharedDir && path.dirname(outputPath)
|
|
85
|
+
if (!isSharedDir && path.dirname(outputPath) !== '.') {
|
|
86
86
|
outputPath = path.join(path.dirname(outputPath) + '.mdx');
|
|
87
87
|
}
|
|
88
88
|
await write(path.join(outputDir, outputPath), output.content);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MediaAdapter } from '../media/adapter.js';
|
|
2
|
+
export declare const json: MediaAdapter;
|
|
3
|
+
export declare const xml: MediaAdapter;
|
|
4
|
+
export declare const url: MediaAdapter;
|
|
5
|
+
export declare const formData: MediaAdapter;
|
|
6
|
+
export declare const ndJson: MediaAdapter;
|
|
7
|
+
export declare const octet: MediaAdapter;
|
|
8
|
+
//# sourceMappingURL=adapter.client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.client.d.ts","sourceRoot":"","sources":["../../src/media/adapter.client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,iBAAiB,CAAC;AAElE,eAAO,MAAM,IAAI,EAAE,YAOlB,CAAC;AACF,eAAO,MAAM,GAAG,EAAE,YAYjB,CAAC;AAEF,eAAO,MAAM,GAAG,EAAE,YAqBjB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,YAyDtB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,YAUpB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,YAQnB,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { inputToString } from '../utils/input-to-string.js';
|
|
3
|
+
export const json = {
|
|
4
|
+
encode(data) {
|
|
5
|
+
return JSON.stringify(data.body);
|
|
6
|
+
},
|
|
7
|
+
generateExample(data, ctx) {
|
|
8
|
+
return str(data.body, 'json', ctx);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
export const xml = {
|
|
12
|
+
async encode(data) {
|
|
13
|
+
const { js2xml } = await import('xml-js');
|
|
14
|
+
return js2xml(data.body, {
|
|
15
|
+
compact: true,
|
|
16
|
+
spaces: 2,
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
generateExample(data, ctx) {
|
|
20
|
+
return str(data.body, 'xml', ctx);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export const url = {
|
|
24
|
+
encode(data) {
|
|
25
|
+
if (typeof data.body !== 'object')
|
|
26
|
+
throw new Error(`Input value must be object, received: ${typeof data.body}`);
|
|
27
|
+
const params = new URLSearchParams();
|
|
28
|
+
for (const key in data.body) {
|
|
29
|
+
params.set(key, String(data.body[key]));
|
|
30
|
+
}
|
|
31
|
+
return params;
|
|
32
|
+
},
|
|
33
|
+
generateExample(data, ctx) {
|
|
34
|
+
if (ctx.lang === 'js') {
|
|
35
|
+
return `const body = new URLSearchParams(${JSON.stringify(data.body, null, 2)})`;
|
|
36
|
+
}
|
|
37
|
+
return str(data.body, 'url', ctx);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export const formData = {
|
|
41
|
+
encode(data) {
|
|
42
|
+
const formData = new FormData();
|
|
43
|
+
const body = data.body;
|
|
44
|
+
if (typeof body !== 'object' || !body) {
|
|
45
|
+
throw new Error(`Unsupported body type: ${typeof body}, expected: object`);
|
|
46
|
+
}
|
|
47
|
+
for (const key in body) {
|
|
48
|
+
const prop = body[key];
|
|
49
|
+
if (typeof prop === 'object' && prop instanceof File) {
|
|
50
|
+
formData.set(key, prop);
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(prop) && prop.every((item) => item instanceof File)) {
|
|
53
|
+
for (const item of prop) {
|
|
54
|
+
formData.append(key, item);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (prop && !(prop instanceof File)) {
|
|
58
|
+
formData.set(key, JSON.stringify(prop));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return formData;
|
|
62
|
+
},
|
|
63
|
+
generateExample(data, ctx) {
|
|
64
|
+
const s = [];
|
|
65
|
+
if (ctx.lang === 'js') {
|
|
66
|
+
s.push(`const body = new FormData();`);
|
|
67
|
+
for (const [key, value] of Object.entries(data.body)) {
|
|
68
|
+
s.push(`body.set(${key}, ${inputToString(value)})`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (ctx.lang === 'go' && 'addImport' in ctx) {
|
|
72
|
+
ctx.addImport('mime/multipart');
|
|
73
|
+
ctx.addImport('bytes');
|
|
74
|
+
s.push('body := new(bytes.Buffer)');
|
|
75
|
+
s.push('mp := multipart.NewWriter(payload)');
|
|
76
|
+
for (const [key, value] of Object.entries(data.body)) {
|
|
77
|
+
s.push(`mp.WriteField("${key}", ${inputToString(value, 'json', 'backtick')})`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (s.length > 0)
|
|
81
|
+
return s.join('\n');
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
export const ndJson = {
|
|
85
|
+
encode(data) {
|
|
86
|
+
if (Array.isArray(data.body)) {
|
|
87
|
+
return data.body.map((v) => JSON.stringify(v)).join('\n');
|
|
88
|
+
}
|
|
89
|
+
return JSON.stringify(data.body);
|
|
90
|
+
},
|
|
91
|
+
generateExample(data, ctx) {
|
|
92
|
+
return str(data.body, 'ndjson', ctx);
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
export const octet = {
|
|
96
|
+
encode(data) {
|
|
97
|
+
return data.body;
|
|
98
|
+
},
|
|
99
|
+
generateExample() {
|
|
100
|
+
// not supported
|
|
101
|
+
return undefined;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
function str(init, format, ctx) {
|
|
105
|
+
if (ctx.lang === 'js') {
|
|
106
|
+
if (format === 'json') {
|
|
107
|
+
return `const body = JSON.stringify(${JSON.stringify(init, null, 2)})`;
|
|
108
|
+
}
|
|
109
|
+
return `const body = ${inputToString(init, format, 'backtick')}`;
|
|
110
|
+
}
|
|
111
|
+
if (ctx.lang === 'python') {
|
|
112
|
+
return `body = ${inputToString(init, format, 'python')}`;
|
|
113
|
+
}
|
|
114
|
+
if (ctx.lang === 'go' && 'addImport' in ctx) {
|
|
115
|
+
ctx.addImport('strings');
|
|
116
|
+
return `body := strings.NewReader(${inputToString(init, format, 'backtick')})`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RequestData } from '../requests/_shared.js';
|
|
2
|
+
interface GoContext {
|
|
3
|
+
lang: 'go';
|
|
4
|
+
addImport: (name: string) => void;
|
|
5
|
+
}
|
|
6
|
+
interface JavaScriptContext {
|
|
7
|
+
lang: 'js';
|
|
8
|
+
addImport: (pkg: string, name: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export type MediaContext = GoContext | JavaScriptContext | {
|
|
11
|
+
lang: string;
|
|
12
|
+
/**
|
|
13
|
+
* Passed by your custom example generator, for your custom media adapter to receive.
|
|
14
|
+
*/
|
|
15
|
+
customData?: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
export interface MediaAdapter {
|
|
18
|
+
/**
|
|
19
|
+
* encode request data into body for `fetch()`.
|
|
20
|
+
*
|
|
21
|
+
* Return the encoded form of `data.body` property.
|
|
22
|
+
*/
|
|
23
|
+
encode: (data: RequestData) => BodyInit | Promise<BodyInit>;
|
|
24
|
+
/**
|
|
25
|
+
* generate code for usage examples in a given programming language.
|
|
26
|
+
*
|
|
27
|
+
* @param data - request data.
|
|
28
|
+
* @param lang - name of programming language.
|
|
29
|
+
* @param ctx - context passed from the generator of programming language.
|
|
30
|
+
*
|
|
31
|
+
* @returns code that inits a `body` variable, or undefined if not supported (skip example for that language).
|
|
32
|
+
*/
|
|
33
|
+
generateExample: (data: RequestData, ctx: MediaContext) => string | undefined;
|
|
34
|
+
}
|
|
35
|
+
export declare const defaultAdapters: Record<string, MediaAdapter>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/media/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,UAAU,SAAS;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,iBAAiB,GACjB;IACE,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC,CAAC;AAEN,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE5D;;;;;;;;OAQG;IACH,eAAe,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,YAAY,KAAK,MAAM,GAAG,SAAS,CAAC;CAC/E;AAED,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAOxD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as adapters from './adapter.client.js';
|
|
2
|
+
export const defaultAdapters = {
|
|
3
|
+
'application/json': adapters.json,
|
|
4
|
+
'application/xml': adapters.xml,
|
|
5
|
+
'application/x-ndjson': adapters.ndJson,
|
|
6
|
+
'application/x-www-form-urlencoded': adapters.url,
|
|
7
|
+
'multipart/form-data': adapters.formData,
|
|
8
|
+
'application/octet-stream': adapters.octet,
|
|
9
|
+
};
|
|
@@ -3,6 +3,7 @@ import type { ControllerFieldState, ControllerRenderProps, FieldPath, UseFormSta
|
|
|
3
3
|
import type { FetchResult } from '../playground/fetcher.js';
|
|
4
4
|
import type { ParameterField, RequestSchema } from '../playground/index.js';
|
|
5
5
|
import type { Security } from '../utils/get-security.js';
|
|
6
|
+
import type { MediaAdapter } from '../media/adapter.js';
|
|
6
7
|
interface FormValues {
|
|
7
8
|
authorization: string | {
|
|
8
9
|
username: string;
|
|
@@ -51,7 +52,8 @@ export type ClientProps = HTMLAttributes<HTMLFormElement> & {
|
|
|
51
52
|
data: FetchResult;
|
|
52
53
|
}>;
|
|
53
54
|
}>;
|
|
55
|
+
mediaAdapters: Record<string, MediaAdapter>;
|
|
54
56
|
};
|
|
55
|
-
export default function Client({ route, method, authorization, parameters, body, fields, references, proxyUrl, components: { ResultDisplay }, ...rest }: ClientProps): import("react/jsx-runtime").JSX.Element;
|
|
57
|
+
export default function Client({ route, method, authorization, parameters, body, fields, references, proxyUrl, mediaAdapters, components: { ResultDisplay }, ...rest }: ClientProps): import("react/jsx-runtime").JSX.Element;
|
|
56
58
|
export {};
|
|
57
59
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/playground/client.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAAE,EAEP,KAAK,cAAc,EAEnB,KAAK,YAAY,EAKlB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAQzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAYxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/playground/client.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAAE,EAEP,KAAK,cAAc,EAEnB,KAAK,YAAY,EAKlB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAQzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAYxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAWrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,UAAU,UAAU;IAClB,aAAa,EACT,MAAM,GACN;QACE,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACN,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,WAAW,CAAC,KAAK,SAAS,SAAS,CAAC,UAAU,CAAC,EAAE,IAAI;IACpE,MAAM,EAAE,CAAC,KAAK,EAAE;QACd;;WAEG;QACH,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,qBAAqB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAChD,UAAU,EAAE,oBAAoB,CAAC;QACjC,SAAS,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;KAC3C,KAAK,YAAY,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC,eAAe,CAAC,GAAG;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,QAAQ,GAAG;QACzB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,aAAa,CAAC;QACtB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,MAAM,CAAC,EAAE;QACP,SAAS,CAAC,EAAE,WAAW,CACrB,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,MAAM,EAAE,EACnC,cAAc,CACf,CAAC;QACF,IAAI,CAAC,EAAE,WAAW,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;QACnD,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;KAC3C,CAAC;IAEF,UAAU,CAAC,EAAE,OAAO,CAAC;QACnB,aAAa,EAAE,EAAE,CAAC;YAAE,IAAI,EAAE,WAAW,CAAA;SAAE,CAAC,CAAC;KAC1C,CAAC,CAAC;IAEH,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC7C,CAAC;AAoBF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAC7B,KAAK,EACL,MAAc,EACd,aAAa,EACb,UAAU,EACV,IAAI,EACJ,MAAM,EACN,UAAU,EACV,QAAQ,EACR,aAAa,EACb,UAAU,EAAE,EAAE,aAAoC,EAAO,EACzD,GAAG,IAAI,EACR,EAAE,WAAW,2CAiHb"}
|
|
@@ -28,7 +28,7 @@ function toRequestData(method, mediaType, value) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
const ServerSelect = lazy(() => import('../ui/server-select.js'));
|
|
31
|
-
export default function Client({ route, method = 'GET', authorization, parameters, body, fields, references, proxyUrl, components: { ResultDisplay = DefaultResultDisplay } = {}, ...rest }) {
|
|
31
|
+
export default function Client({ route, method = 'GET', authorization, parameters, body, fields, references, proxyUrl, mediaAdapters, components: { ResultDisplay = DefaultResultDisplay } = {}, ...rest }) {
|
|
32
32
|
const { server } = useServerSelectContext();
|
|
33
33
|
const requestData = useRequestData();
|
|
34
34
|
const fieldInfoMap = useMemo(() => new Map(), []);
|
|
@@ -45,7 +45,7 @@ export default function Client({ route, method = 'GET', authorization, parameter
|
|
|
45
45
|
defaultValues,
|
|
46
46
|
});
|
|
47
47
|
const testQuery = useQuery(async (input) => {
|
|
48
|
-
const fetcher = await import('./fetcher.js').then((mod) => mod.createBrowserFetcher());
|
|
48
|
+
const fetcher = await import('./fetcher.js').then((mod) => mod.createBrowserFetcher(mediaAdapters));
|
|
49
49
|
const serverUrl = server
|
|
50
50
|
? getUrl(server.url, server.variables)
|
|
51
51
|
: window.location.origin;
|
|
@@ -122,12 +122,14 @@ function FormBody({ authorization, parameters = [], fields = {}, body, }) {
|
|
|
122
122
|
}
|
|
123
123
|
return (_jsx(FieldSet, { name: field.name, fieldName: fieldName, field: field.schema }, fieldName));
|
|
124
124
|
})] }, name));
|
|
125
|
-
}), body
|
|
125
|
+
}), body && (_jsx(CollapsiblePanel, { title: "Body", children: fields.body ? (renderCustomField('body', body.schema, fields.body)) : (_jsx(BodyInput, { field: body.schema })) }))] }));
|
|
126
126
|
}
|
|
127
127
|
function BodyInput({ field: _field }) {
|
|
128
128
|
const field = useResolvedSchema(_field);
|
|
129
129
|
const [isJson, setIsJson] = useState(false);
|
|
130
|
-
|
|
130
|
+
if (field.format === 'binary')
|
|
131
|
+
return _jsx(FieldSet, { field: field, fieldName: "body" });
|
|
132
|
+
return (_jsx(_Fragment, { children: isJson ? (_jsx(JsonInput, { fieldName: "body", children: _jsx("button", { className: cn(buttonVariants({
|
|
131
133
|
color: 'ghost',
|
|
132
134
|
size: 'sm',
|
|
133
135
|
className: 'p-2',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { RequestData } from '../requests/_shared.js';
|
|
1
|
+
import type { RequestData } from '../requests/_shared.js';
|
|
2
|
+
import type { MediaAdapter } from '../media/adapter.js';
|
|
2
3
|
export interface FetchOptions extends RequestData {
|
|
3
4
|
proxyUrl?: string;
|
|
4
5
|
}
|
|
@@ -10,9 +11,5 @@ export interface FetchResult {
|
|
|
10
11
|
export interface Fetcher {
|
|
11
12
|
fetch: (route: string, options: FetchOptions) => Promise<FetchResult>;
|
|
12
13
|
}
|
|
13
|
-
export declare function createBrowserFetcher(): Fetcher;
|
|
14
|
-
/**
|
|
15
|
-
* Create request body from value
|
|
16
|
-
*/
|
|
17
|
-
export declare function createBodyFromValue(mediaType: Required<RequestData>['bodyMediaType'], value: unknown): Promise<BodyInit>;
|
|
14
|
+
export declare function createBrowserFetcher(adapters: Record<string, MediaAdapter>): Fetcher;
|
|
18
15
|
//# sourceMappingURL=fetcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/playground/fetcher.ts"],"names":[],"mappings":"
|
|
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,CAyFT"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { getPathnameFromInput } from '../utils/get-pathname-from-input.js';
|
|
2
|
-
|
|
3
|
-
export function createBrowserFetcher() {
|
|
2
|
+
export function createBrowserFetcher(adapters) {
|
|
4
3
|
return {
|
|
5
4
|
async fetch(route, options) {
|
|
6
5
|
const headers = new Headers();
|
|
7
|
-
if (options.bodyMediaType
|
|
8
|
-
options.bodyMediaType !== 'multipart/form-data')
|
|
6
|
+
if (options.bodyMediaType)
|
|
9
7
|
headers.append('Content-Type', options.bodyMediaType);
|
|
10
8
|
for (const key in options.header) {
|
|
11
9
|
const paramValue = options.header[key];
|
|
@@ -23,9 +21,9 @@ export function createBrowserFetcher() {
|
|
|
23
21
|
document.cookie = [
|
|
24
22
|
`${key}=${value}`,
|
|
25
23
|
'HttpOnly',
|
|
26
|
-
proxyUrl &&
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
proxyUrl &&
|
|
25
|
+
proxyUrl.origin !== window.location.origin &&
|
|
26
|
+
`domain=${proxyUrl.host}`,
|
|
29
27
|
'path=/',
|
|
30
28
|
]
|
|
31
29
|
.filter(Boolean)
|
|
@@ -37,13 +35,22 @@ export function createBrowserFetcher() {
|
|
|
37
35
|
proxyUrl.searchParams.append('url', url);
|
|
38
36
|
url = proxyUrl.toString();
|
|
39
37
|
}
|
|
38
|
+
let body = undefined;
|
|
39
|
+
if (options.bodyMediaType && options.body) {
|
|
40
|
+
const adapter = adapters[options.bodyMediaType];
|
|
41
|
+
if (!adapter)
|
|
42
|
+
return {
|
|
43
|
+
status: 400,
|
|
44
|
+
type: 'text',
|
|
45
|
+
data: `[Fumadocs] No adapter for ${options.bodyMediaType}, you need to specify one from 'createOpenAPI()'.`,
|
|
46
|
+
};
|
|
47
|
+
body = await adapter.encode(options);
|
|
48
|
+
}
|
|
40
49
|
return fetch(url, {
|
|
41
50
|
method: options.method,
|
|
42
51
|
cache: 'no-cache',
|
|
43
52
|
headers,
|
|
44
|
-
body
|
|
45
|
-
? await createBodyFromValue(options.bodyMediaType, options.body)
|
|
46
|
-
: undefined,
|
|
53
|
+
body,
|
|
47
54
|
signal: AbortSignal.timeout(10 * 1000),
|
|
48
55
|
})
|
|
49
56
|
.then(async (res) => {
|
|
@@ -71,45 +78,3 @@ export function createBrowserFetcher() {
|
|
|
71
78
|
},
|
|
72
79
|
};
|
|
73
80
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Create request body from value
|
|
76
|
-
*/
|
|
77
|
-
export async function createBodyFromValue(mediaType, value) {
|
|
78
|
-
if (mediaType === 'application/json') {
|
|
79
|
-
return JSON.stringify(value);
|
|
80
|
-
}
|
|
81
|
-
if (mediaType === 'application/xml') {
|
|
82
|
-
return js2xml(value, {
|
|
83
|
-
compact: true,
|
|
84
|
-
spaces: 2,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
if (mediaType === 'application/x-www-form-urlencoded') {
|
|
88
|
-
if (typeof value !== 'object')
|
|
89
|
-
throw new Error(`Input value must be object, received: ${typeof value}`);
|
|
90
|
-
const params = new URLSearchParams();
|
|
91
|
-
for (const key in value) {
|
|
92
|
-
params.set(key, String(value[key]));
|
|
93
|
-
}
|
|
94
|
-
return params;
|
|
95
|
-
}
|
|
96
|
-
const formData = new FormData();
|
|
97
|
-
if (typeof value !== 'object' || !value) {
|
|
98
|
-
throw new Error(`Unsupported body type: ${typeof value}, expected: object`);
|
|
99
|
-
}
|
|
100
|
-
for (const key in value) {
|
|
101
|
-
const prop = value[key];
|
|
102
|
-
if (typeof prop === 'object' && prop instanceof File) {
|
|
103
|
-
formData.set(key, prop);
|
|
104
|
-
}
|
|
105
|
-
if (Array.isArray(prop) && prop.every((item) => item instanceof File)) {
|
|
106
|
-
for (const item of prop) {
|
|
107
|
-
formData.append(key, item);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (prop && !(prop instanceof File)) {
|
|
111
|
-
formData.set(key, JSON.stringify(prop));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return formData;
|
|
115
|
-
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/playground/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;IACrB,EAAE,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/playground/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;IACrB,EAAE,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC;AAQzC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;IAEnB,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;CAC/B;AAED,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzD,wBAAsB,aAAa,CAAC,EAClC,IAAI,EACJ,MAAM,EACN,GAAG,EACH,MAAM,GACP,EAAE,kBAAkB,oDAwCpB"}
|
package/dist/playground/index.js
CHANGED
|
@@ -7,18 +7,17 @@ export async function APIPlayground({ path, method, ctx, client, }) {
|
|
|
7
7
|
const bodyContent = method.requestBody?.content;
|
|
8
8
|
const mediaType = bodyContent ? getPreferredType(bodyContent) : undefined;
|
|
9
9
|
const context = {
|
|
10
|
-
allowFile: mediaType === 'multipart/form-data',
|
|
11
10
|
references: {},
|
|
12
11
|
nextId() {
|
|
13
12
|
return String(currentId++);
|
|
14
13
|
},
|
|
15
14
|
registered: new WeakMap(),
|
|
16
|
-
render: ctx,
|
|
17
15
|
};
|
|
18
16
|
const props = {
|
|
19
17
|
authorization: getAuthorizationField(method, ctx),
|
|
20
18
|
method: method.method,
|
|
21
19
|
route: path,
|
|
20
|
+
mediaAdapters: ctx.mediaAdapters,
|
|
22
21
|
parameters: method.parameters?.map((v) => ({
|
|
23
22
|
name: v.name,
|
|
24
23
|
in: v.in,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAef,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA8CxD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EACT,GAAG,KAAK,EACT,EAAE;IACD,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAAC,cAAc,CAAC,2CAqCjC;AAED,wBAAgB,SAAS,CAAC,EACxB,SAAS,EACT,QAAQ,GACT,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;CACrB,2CA0BA;AAyFD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAS,EACT,UAAU,EACV,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,
|
|
1
|
+
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAef,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA8CxD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EACT,GAAG,KAAK,EACT,EAAE;IACD,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAAC,cAAc,CAAC,2CAqCjC;AAED,wBAAgB,SAAS,CAAC,EACxB,SAAS,EACT,QAAQ,GACT,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;CACrB,2CA0BA;AAyFD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAS,EACT,UAAU,EACV,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,2CAmGA;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,KAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,SAAS,CAAC;CACrB,kDA2HA"}
|
|
@@ -90,7 +90,7 @@ export function FieldInput({ field, fieldName, isRequired, ...props }) {
|
|
|
90
90
|
if (!e.target.files)
|
|
91
91
|
return;
|
|
92
92
|
onChange(e.target.files.item(0));
|
|
93
|
-
}, ...props, ...restField })) }));
|
|
93
|
+
}, ...props, className: cn('border rounded-lg bg-fd-background text-fd-muted-foreground p-2 font-medium text-sm', props.className), ...restField })) }));
|
|
94
94
|
}
|
|
95
95
|
if (field.type === 'boolean') {
|
|
96
96
|
return (_jsx(Controller, { control: control, name: fieldName, render: ({ field: { value, onChange, ...restField } }) => (_jsxs(Select, { value: String(value), onValueChange: (value) => onChange(value === 'null' ? null : value === 'true'), disabled: restField.disabled, children: [_jsx(SelectTrigger, { id: fieldName, className: props.className, ...restField, children: _jsx(SelectValue, {}) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "true", children: "True" }), _jsx(SelectItem, { value: "false", children: "False" }), !isRequired && _jsx(SelectItem, { value: "null", children: "Null" })] })] })) }));
|
|
@@ -2,7 +2,7 @@ import type { RenderContext } from '../types.js';
|
|
|
2
2
|
import { type Renderer } from '../render/renderer.js';
|
|
3
3
|
import type { OpenAPIV3_1 } from 'openapi-types';
|
|
4
4
|
import { type DocumentInput, type ProcessedDocument } from '../utils/process-document.js';
|
|
5
|
-
type ApiPageContextProps = Pick<Partial<RenderContext>, 'shikiOptions' | 'generateTypeScriptSchema' | 'generateCodeSamples' | 'proxyUrl' | 'showResponseSchema' | 'disablePlayground'>;
|
|
5
|
+
type ApiPageContextProps = Pick<Partial<RenderContext>, 'shikiOptions' | 'generateTypeScriptSchema' | 'generateCodeSamples' | 'proxyUrl' | 'showResponseSchema' | 'disablePlayground' | 'mediaAdapters'>;
|
|
6
6
|
export interface ApiPageProps extends ApiPageContextProps {
|
|
7
7
|
document: DocumentInput;
|
|
8
8
|
hasHead: boolean;
|
|
@@ -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;
|
|
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,oDA0DhD;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,CAmCxB"}
|
package/dist/render/api-page.js
CHANGED
|
@@ -5,12 +5,13 @@ import { createMethod } from '../server/create-method.js';
|
|
|
5
5
|
import { createRenders } from '../render/renderer.js';
|
|
6
6
|
import { processDocument, } from '../utils/process-document.js';
|
|
7
7
|
import { getUrl } from '../utils/server-url.js';
|
|
8
|
+
import { defaultAdapters } from '../media/adapter.js';
|
|
8
9
|
export async function APIPage(props) {
|
|
9
10
|
const { operations, hasHead = true, webhooks, disableCache = process.env.NODE_ENV === 'development', } = props;
|
|
10
11
|
const processed = await processDocument(props.document, disableCache);
|
|
11
12
|
const ctx = await getContext(processed, props);
|
|
12
13
|
const { document } = processed;
|
|
13
|
-
return (_jsxs(ctx.renderer.Root, {
|
|
14
|
+
return (_jsxs(ctx.renderer.Root, { ctx: ctx, children: [operations?.map((item) => {
|
|
14
15
|
const pathItem = document.paths?.[item.path];
|
|
15
16
|
if (!pathItem)
|
|
16
17
|
return null;
|
|
@@ -45,7 +46,7 @@ export async function getContext(schema, options = {}) {
|
|
|
45
46
|
disablePlayground: options.disablePlayground,
|
|
46
47
|
showResponseSchema: options.showResponseSchema,
|
|
47
48
|
renderer: {
|
|
48
|
-
...createRenders(
|
|
49
|
+
...createRenders(),
|
|
49
50
|
...options.renderer,
|
|
50
51
|
},
|
|
51
52
|
shikiOptions: options.shikiOptions,
|
|
@@ -55,6 +56,10 @@ export async function getContext(schema, options = {}) {
|
|
|
55
56
|
? Object.fromEntries(Object.entries(server.variables).map(([k, v]) => [k, v.default]))
|
|
56
57
|
: {}),
|
|
57
58
|
servers,
|
|
59
|
+
mediaAdapters: {
|
|
60
|
+
...defaultAdapters,
|
|
61
|
+
...options.mediaAdapters,
|
|
62
|
+
},
|
|
58
63
|
slugger: new Slugger(),
|
|
59
64
|
};
|
|
60
65
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type ReactElement } from 'react';
|
|
2
2
|
import type { MethodInformation, RenderContext } from '../../types.js';
|
|
3
|
-
import { type
|
|
3
|
+
import { type SampleGenerator } from '../../requests/_shared.js';
|
|
4
4
|
export interface CodeSample {
|
|
5
5
|
lang: string;
|
|
6
6
|
label: string;
|
|
7
|
-
source?: string |
|
|
7
|
+
source?: string | SampleGenerator | false;
|
|
8
8
|
}
|
|
9
9
|
export declare function Operation({ type, path, method, ctx, hasHead, headingLevel, }: {
|
|
10
10
|
type?: 'webhook' | 'operation';
|
|
@@ -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,
|
|
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;IACd,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,CA+Kf"}
|
|
@@ -10,7 +10,6 @@ import { createMethod } from '../../server/create-method.js';
|
|
|
10
10
|
import { methodKeys } from '../../build-routes.js';
|
|
11
11
|
import { APIExample, APIExampleProvider, getAPIExamples, } from '../../render/operation/api-example.js';
|
|
12
12
|
import { MethodLabel } from '../../ui/components/method-label.js';
|
|
13
|
-
import { supportedMediaTypes } from '../../requests/_shared.js';
|
|
14
13
|
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
|
|
15
14
|
import { getTypescriptSchema } from '../../utils/get-typescript-schema.js';
|
|
16
15
|
import { CopyResponseTypeScript } from '../../ui/client.js';
|
|
@@ -34,8 +33,7 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
|
|
|
34
33
|
}
|
|
35
34
|
if (body) {
|
|
36
35
|
const type = getPreferredType(body.content);
|
|
37
|
-
if (!type ||
|
|
38
|
-
!supportedMediaTypes.includes(String(type)))
|
|
36
|
+
if (!type || !(type in ctx.mediaAdapters))
|
|
39
37
|
throw new Error(`No supported media type for body content: ${path}, received: ${type}`);
|
|
40
38
|
bodyNode = (_jsxs(_Fragment, { children: [heading(headingLevel, 'Request Body', ctx), _jsxs("div", { className: "mb-4 p-3 bg-fd-card rounded-xl border flex flex-row items-center justify-between gap-2", children: [_jsx("code", { children: type }), _jsx("span", { className: "text-xs", children: body.required ? 'Required' : 'Optional' })] }), body.description ? _jsx(Markdown, { text: body.description }) : null, _jsx(Schema, { name: "body", schema: (body.content[type].schema ?? {}), required: body.required, ctx: {
|
|
41
39
|
readOnly: method.method === 'GET',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
-
import type { RenderContext
|
|
2
|
+
import type { RenderContext } from '../types.js';
|
|
3
3
|
import { type APIPlaygroundProps } from '../playground/index.js';
|
|
4
4
|
export interface ResponsesProps {
|
|
5
5
|
items: string[];
|
|
@@ -42,9 +42,7 @@ export interface ResponseTypeProps {
|
|
|
42
42
|
children: ReactNode;
|
|
43
43
|
}
|
|
44
44
|
export interface RootProps {
|
|
45
|
-
|
|
46
|
-
shikiOptions?: RenderContext['shikiOptions'];
|
|
47
|
-
servers: ServerObject[];
|
|
45
|
+
ctx: RenderContext;
|
|
48
46
|
children: ReactNode;
|
|
49
47
|
}
|
|
50
48
|
export interface Renderer {
|
|
@@ -76,5 +74,5 @@ export interface Renderer {
|
|
|
76
74
|
Property: ComponentType<PropertyProps>;
|
|
77
75
|
APIPlayground: ComponentType<APIPlaygroundProps>;
|
|
78
76
|
}
|
|
79
|
-
export declare function createRenders(
|
|
77
|
+
export declare function createRenders(): Renderer;
|
|
80
78
|
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAWtD,OAAO,KAAK,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAWtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGtE,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IAEd,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IAEb,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,SAAS,CAAC;QACxB,KAAK,EAAE,MAAM,CAAC;KACf,EAAE,CAAC;CACL;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,aAAa,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IAC/B,GAAG,EAAE,aAAa,CAAC;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IAC5C,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,UAAU,EAAE,aAAa,CAAC;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IAEnD,SAAS,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACzC,QAAQ,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IACvC,mBAAmB,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACjD,QAAQ,EAAE,aAAa,CAAC;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IAClE,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,aAAa,EAAE,aAAa,CAAC;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IAC7E,YAAY,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAE/C;;OAEG;IACH,iBAAiB,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;IACzD,QAAQ,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;CAClD;AAED,wBAAgB,aAAa,IAAI,QAAQ,CAqCxC"}
|
package/dist/render/renderer.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
|
|
3
3
|
import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
|
|
4
4
|
import { API, APIExample, APIInfo, ObjectCollapsible, Property, Root, } from '../ui/index.js';
|
|
5
5
|
import { APIPlayground } from '../playground/index.js';
|
|
6
6
|
import { CodeExampleSelector } from '../ui/contexts/code-example.lazy.js';
|
|
7
|
-
export function createRenders(
|
|
7
|
+
export function createRenders() {
|
|
8
8
|
return {
|
|
9
|
-
Root
|
|
9
|
+
Root,
|
|
10
10
|
API,
|
|
11
11
|
APIInfo: ({ children, head }) => (_jsxs(APIInfo, { children: [head, children] })),
|
|
12
12
|
APIExample,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { MediaAdapter } from '../media/adapter.js';
|
|
2
|
+
export type SampleGenerator = (url: string, data: RequestData, context: {
|
|
3
|
+
mediaAdapters: Record<string, MediaAdapter>;
|
|
4
|
+
}) => string;
|
|
2
5
|
export interface RequestData {
|
|
3
6
|
method: string;
|
|
4
7
|
path: Record<string, string>;
|
|
@@ -6,13 +9,8 @@ export interface RequestData {
|
|
|
6
9
|
header: Record<string, string>;
|
|
7
10
|
cookie: Record<string, string>;
|
|
8
11
|
body?: unknown;
|
|
9
|
-
bodyMediaType?:
|
|
12
|
+
bodyMediaType?: string;
|
|
10
13
|
}
|
|
11
|
-
export declare const MediaTypeFormatMap: {
|
|
12
|
-
readonly 'application/json': "json";
|
|
13
|
-
readonly 'application/xml': "xml";
|
|
14
|
-
readonly 'application/x-www-form-urlencoded': "url";
|
|
15
|
-
};
|
|
16
14
|
export declare function getUrl(url: string, data: RequestData): string;
|
|
17
15
|
export declare function ident(code: string, tab?: number): string;
|
|
18
16
|
//# sourceMappingURL=_shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../src/requests/_shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../src/requests/_shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,MAAM,eAAe,GAAG,CAC5B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE;IACP,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC7C,KACE,MAAM,CAAC;AAEZ,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IAEf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAE7D;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAU,UAKlD"}
|
package/dist/requests/_shared.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
import { getPathnameFromInput } from '../utils/get-pathname-from-input.js';
|
|
2
|
-
export const supportedMediaTypes = [
|
|
3
|
-
'multipart/form-data',
|
|
4
|
-
'application/json',
|
|
5
|
-
'application/xml',
|
|
6
|
-
'application/x-www-form-urlencoded',
|
|
7
|
-
];
|
|
8
|
-
export const MediaTypeFormatMap = {
|
|
9
|
-
'application/json': 'json',
|
|
10
|
-
'application/xml': 'xml',
|
|
11
|
-
'application/x-www-form-urlencoded': 'url',
|
|
12
|
-
};
|
|
13
2
|
export function getUrl(url, data) {
|
|
14
3
|
return getPathnameFromInput(url, data.path, data.query);
|
|
15
4
|
}
|
package/dist/requests/curl.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare
|
|
1
|
+
import { type SampleGenerator } from '../requests/_shared.js';
|
|
2
|
+
export declare const generator: SampleGenerator;
|
|
3
3
|
//# sourceMappingURL=curl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAQzE,eAAO,MAAM,SAAS,EAAE,eA0CvB,CAAC"}
|
package/dist/requests/curl.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { inputToString } from '../utils/input-to-string.js';
|
|
3
|
-
import { getUrl, ident
|
|
4
|
-
|
|
3
|
+
import { getUrl, ident } from '../requests/_shared.js';
|
|
4
|
+
const MediaTypeFormatMap = {
|
|
5
|
+
'application/json': 'json',
|
|
6
|
+
'application/xml': 'xml',
|
|
7
|
+
'application/x-www-form-urlencoded': 'url',
|
|
8
|
+
};
|
|
9
|
+
export const generator = (url, data) => {
|
|
5
10
|
const s = [];
|
|
6
11
|
s.push(`curl -X ${data.method} "${getUrl(url, data)}"`);
|
|
7
12
|
for (const header in data.header) {
|
|
@@ -12,16 +17,18 @@ export function getSampleRequest(url, data) {
|
|
|
12
17
|
const value = JSON.stringify(`${cookie}=${data.cookie[cookie]}`);
|
|
13
18
|
s.push(`--cookie ${value}`);
|
|
14
19
|
}
|
|
15
|
-
if (data.bodyMediaType === 'multipart/form-data') {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
+
if (data.body && data.bodyMediaType === 'multipart/form-data') {
|
|
21
|
+
if (typeof data.body !== 'object')
|
|
22
|
+
throw new Error('[CURL] request body must be an object.');
|
|
23
|
+
for (const [key, value] of Object.entries(data.body)) {
|
|
24
|
+
s.push(`-F ${key}=${inputToString(value)}`);
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
|
-
else if (data.body &&
|
|
27
|
+
else if (data.body &&
|
|
28
|
+
data.bodyMediaType &&
|
|
29
|
+
data.bodyMediaType in MediaTypeFormatMap) {
|
|
23
30
|
s.push(`-H "Content-Type: ${data.bodyMediaType}"`);
|
|
24
31
|
s.push(`-d ${inputToString(data.body, MediaTypeFormatMap[data.bodyMediaType], 'single-quote')}`);
|
|
25
32
|
}
|
|
26
33
|
return s.flatMap((v, i) => ident(v, i > 0 ? 1 : 0)).join(' \\\n');
|
|
27
|
-
}
|
|
34
|
+
};
|
package/dist/requests/go.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare
|
|
1
|
+
import { SampleGenerator } from '../requests/_shared.js';
|
|
2
|
+
export declare const generator: SampleGenerator;
|
|
3
3
|
//# sourceMappingURL=go.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/requests/go.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/requests/go.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEpE,eAAO,MAAM,SAAS,EAAE,eAqDvB,CAAC"}
|
package/dist/requests/go.js
CHANGED
|
@@ -1,33 +1,25 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export function getSampleRequest(url, data) {
|
|
2
|
+
import { getUrl, ident } from '../requests/_shared.js';
|
|
3
|
+
export const generator = (url, data, { mediaAdapters }) => {
|
|
5
4
|
const imports = ['fmt', 'net/http', 'io/ioutil'];
|
|
6
5
|
const headers = new Map();
|
|
7
6
|
const variables = new Map();
|
|
8
7
|
variables.set('url', JSON.stringify(getUrl(url, data)));
|
|
9
|
-
// additional lines before initializing request
|
|
10
|
-
const additional = [];
|
|
11
8
|
for (const header in data.header) {
|
|
12
9
|
headers.set(header, JSON.stringify(data.header[header]));
|
|
13
10
|
}
|
|
14
11
|
const cookies = Object.keys(data.cookie);
|
|
15
12
|
if (cookies.length > 0)
|
|
16
13
|
headers.set('Cookie', JSON.stringify(cookies.map((p) => `${p}=${data.cookie[p]}`).join('; ')));
|
|
17
|
-
|
|
14
|
+
let body;
|
|
15
|
+
if (data.body && data.bodyMediaType && data.bodyMediaType in mediaAdapters) {
|
|
18
16
|
headers.set('Content-Type', `"${data.bodyMediaType}"`);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
imports.push('strings');
|
|
29
|
-
variables.set('payload', `strings.NewReader(${inputToString(data.body, MediaTypeFormatMap[data.bodyMediaType], 'backtick')})`);
|
|
30
|
-
}
|
|
17
|
+
body = mediaAdapters[data.bodyMediaType].generateExample(data, {
|
|
18
|
+
lang: 'go',
|
|
19
|
+
addImport(from) {
|
|
20
|
+
imports.push(from);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
31
23
|
}
|
|
32
24
|
return `package main
|
|
33
25
|
|
|
@@ -39,8 +31,8 @@ func main() {
|
|
|
39
31
|
${Array.from(variables.entries())
|
|
40
32
|
.map(([k, v]) => ident(`${k} := ${v}`))
|
|
41
33
|
.join('\n')}
|
|
42
|
-
${ident(
|
|
43
|
-
req, _ := http.NewRequest("${data.method}", url, ${
|
|
34
|
+
${body ? ident(body) : ''}
|
|
35
|
+
req, _ := http.NewRequest("${data.method}", url, ${body ? 'body' : 'nil'})
|
|
44
36
|
${ident(Array.from(headers.entries())
|
|
45
37
|
.map(([key, value]) => `req.Header.Add("${key}", ${value})`)
|
|
46
38
|
.join('\n'))}
|
|
@@ -51,4 +43,4 @@ ${ident(Array.from(headers.entries())
|
|
|
51
43
|
fmt.Println(res)
|
|
52
44
|
fmt.Println(string(body))
|
|
53
45
|
}`;
|
|
54
|
-
}
|
|
46
|
+
};
|
package/dist/requests/index.js
CHANGED
|
@@ -5,22 +5,22 @@ import * as Python from '../requests/python.js';
|
|
|
5
5
|
export const defaultSamples = [
|
|
6
6
|
{
|
|
7
7
|
label: 'cURL',
|
|
8
|
-
source: CURL.
|
|
8
|
+
source: CURL.generator,
|
|
9
9
|
lang: 'bash',
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
label: 'JavaScript',
|
|
13
|
-
source: JS.
|
|
13
|
+
source: JS.generator,
|
|
14
14
|
lang: 'js',
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
label: 'Go',
|
|
18
|
-
source: Go.
|
|
18
|
+
source: Go.generator,
|
|
19
19
|
lang: 'go',
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
label: 'Python',
|
|
23
|
-
source: Python.
|
|
23
|
+
source: Python.generator,
|
|
24
24
|
lang: 'python',
|
|
25
25
|
},
|
|
26
26
|
];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare
|
|
1
|
+
import { type SampleGenerator } from '../requests/_shared.js';
|
|
2
|
+
export declare const generator: SampleGenerator;
|
|
3
3
|
//# sourceMappingURL=javascript.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/requests/javascript.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/requests/javascript.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEzE,eAAO,MAAM,SAAS,EAAE,eA0CvB,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { inputToString } from '../utils/input-to-string.js';
|
|
3
2
|
import { getUrl, ident } from '../requests/_shared.js';
|
|
4
|
-
export
|
|
3
|
+
export const generator = (url, data, { mediaAdapters }) => {
|
|
5
4
|
const s = [];
|
|
6
5
|
const options = new Map();
|
|
7
6
|
const headers = { ...data.header };
|
|
@@ -13,32 +12,26 @@ export function getSampleRequest(url, data) {
|
|
|
13
12
|
if (Object.keys(headers).length > 0) {
|
|
14
13
|
options.set('headers', JSON.stringify(headers, null, 2));
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
let body;
|
|
16
|
+
if (data.body && data.bodyMediaType && data.bodyMediaType in mediaAdapters) {
|
|
17
|
+
body = mediaAdapters[data.bodyMediaType].generateExample(data, {
|
|
18
|
+
lang: 'js',
|
|
19
|
+
addImport(from, name) {
|
|
20
|
+
s.unshift(`import { ${name} } from "${from}"`);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
options.set('body',
|
|
24
|
+
if (body) {
|
|
25
|
+
s.push(body);
|
|
26
|
+
options.set('body', 'body');
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
: `JSON.stringify(${JSON.stringify(data.body, null, 2)})`;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
code = inputToString(data.body, 'xml', 'backtick');
|
|
36
|
-
}
|
|
37
|
-
options.set('body', code);
|
|
28
|
+
const params = [JSON.stringify(getUrl(url, data))];
|
|
29
|
+
if (options.size > 0) {
|
|
30
|
+
const str = Array.from(options.entries())
|
|
31
|
+
.map(([k, v]) => ident(k === v ? k : `${k}: ${v}`))
|
|
32
|
+
.join(',\n');
|
|
33
|
+
params.push(`{\n${str}\n}`);
|
|
38
34
|
}
|
|
39
|
-
|
|
40
|
-
.map(([k, v]) => ident(`${k}: ${v}`))
|
|
41
|
-
.join(',\n');
|
|
42
|
-
s.push(`fetch(${JSON.stringify(getUrl(url, data))}, {\n${optionsStr}\n});`);
|
|
35
|
+
s.push(`fetch(${params.join(', ')})`);
|
|
43
36
|
return s.join('\n\n');
|
|
44
|
-
}
|
|
37
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare
|
|
1
|
+
import { type SampleGenerator } from '../requests/_shared.js';
|
|
2
|
+
export declare const generator: SampleGenerator;
|
|
3
3
|
//# sourceMappingURL=python.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/requests/python.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/requests/python.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAElE,eAAO,MAAM,SAAS,EAAE,eAwCvB,CAAC"}
|
package/dist/requests/python.js
CHANGED
|
@@ -1,41 +1,38 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export function getSampleRequest(url, data) {
|
|
5
|
-
const variables = new Map();
|
|
2
|
+
import { getUrl } from '../requests/_shared.js';
|
|
3
|
+
export const generator = (url, data, { mediaAdapters }) => {
|
|
6
4
|
const headers = { ...data.header };
|
|
5
|
+
const params = [`"${data.method}"`, 'url'];
|
|
6
|
+
let body;
|
|
7
7
|
if (data.body && data.bodyMediaType) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
if (data.bodyMediaType === 'application/json') {
|
|
9
|
+
params.push(`json = ${JSON.stringify(data.body, null, 2)}`);
|
|
10
|
+
}
|
|
11
|
+
else if (data.bodyMediaType === 'multipart/form-data') {
|
|
12
|
+
headers['Content-Type'] = data.bodyMediaType;
|
|
13
|
+
params.push(`data = ${JSON.stringify(data.body, null, 2)}`);
|
|
14
|
+
}
|
|
15
|
+
else if (data.bodyMediaType in mediaAdapters) {
|
|
16
|
+
headers['Content-Type'] = data.bodyMediaType;
|
|
17
|
+
body = mediaAdapters[data.bodyMediaType].generateExample(data, {
|
|
18
|
+
lang: 'python',
|
|
19
|
+
});
|
|
20
|
+
if (body) {
|
|
21
|
+
params.push('data = body');
|
|
22
|
+
}
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
if (Object.keys(headers).length > 0) {
|
|
22
|
-
|
|
26
|
+
params.push(`headers = ${JSON.stringify(headers, null, 2)}`);
|
|
23
27
|
}
|
|
24
28
|
if (Object.keys(data.cookie).length > 0) {
|
|
25
|
-
|
|
29
|
+
params.push(`cookies = ${JSON.stringify(data.cookie, null, 2)}`);
|
|
26
30
|
}
|
|
27
|
-
const params = [
|
|
28
|
-
`"${data.method}"`,
|
|
29
|
-
'url',
|
|
30
|
-
...Array.from(variables.keys()).map((k) => `${k}=${k}`),
|
|
31
|
-
];
|
|
32
31
|
return `import requests
|
|
33
32
|
|
|
34
33
|
url = ${JSON.stringify(getUrl(url, data))}
|
|
35
|
-
${
|
|
36
|
-
.map(([k, v]) => `${k} = ${v}`)
|
|
37
|
-
.join('\n')}
|
|
34
|
+
${body ?? ''}
|
|
38
35
|
response = requests.request(${params.join(', ')})
|
|
39
36
|
|
|
40
37
|
print(response.text)`;
|
|
41
|
-
}
|
|
38
|
+
};
|
package/dist/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { CodeSample } from './render/operation/index.js';
|
|
|
5
5
|
import type { BuiltinTheme, CodeOptionsThemes, CodeToHastOptionsCommon } from 'shiki';
|
|
6
6
|
import type { NoReference } from './utils/schema.js';
|
|
7
7
|
import type { ProcessedDocument } from './utils/process-document.js';
|
|
8
|
+
import type { MediaAdapter } from './media/adapter.js';
|
|
8
9
|
export type Document = V3_1.Document;
|
|
9
10
|
export type OperationObject = V3_1.OperationObject;
|
|
10
11
|
export type ParameterObject = V3_1.ParameterObject;
|
|
@@ -52,7 +53,7 @@ export interface RenderContext {
|
|
|
52
53
|
/**
|
|
53
54
|
* Generate code samples for endpoint.
|
|
54
55
|
*/
|
|
55
|
-
generateCodeSamples?: (method:
|
|
56
|
+
generateCodeSamples?: (method: MethodInformation) => Awaitable<CodeSample[]>;
|
|
56
57
|
shikiOptions?: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BuiltinTheme>;
|
|
57
58
|
/**
|
|
58
59
|
* Show full response schema instead of only example response & Typescript definitions
|
|
@@ -60,6 +61,7 @@ export interface RenderContext {
|
|
|
60
61
|
* @default true
|
|
61
62
|
*/
|
|
62
63
|
showResponseSchema?: boolean;
|
|
64
|
+
mediaAdapters: Record<string, MediaAdapter>;
|
|
63
65
|
}
|
|
64
66
|
export {};
|
|
65
67
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;AACrC,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,yBAAyB,CAAC;AACvE,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;AACjD,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;AACvC,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAC1D,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAE9D,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,eAAe,CAAC,GAAG;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,YAAY,EAAE,CAAC;IAExB,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,iBAAiB,CAAC;IAE1B;;;;;;;OAOG;IACH,wBAAwB,CAAC,EACrB,CAAC,CACC,MAAM,EAAE,WAAW,CAAC,iBAAiB,CAAC,EACtC,UAAU,EAAE,MAAM,KACf,SAAS,CAAC,MAAM,CAAC,CAAC,GACvB,KAAK,CAAC;IAEV;;OAEG;IACH,mBAAmB,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC;IAE7E,YAAY,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC,GAClD,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAElC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC7C"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { RenderContext, ServerObject } from '../../types.js';
|
|
3
|
+
import type { MediaAdapter } from '../../media/adapter.js';
|
|
3
4
|
export interface ApiProviderProps {
|
|
4
5
|
/**
|
|
5
6
|
* Base URL for API requests
|
|
@@ -7,6 +8,7 @@ export interface ApiProviderProps {
|
|
|
7
8
|
defaultBaseUrl?: string;
|
|
8
9
|
servers: ServerObject[];
|
|
9
10
|
shikiOptions: RenderContext['shikiOptions'];
|
|
11
|
+
mediaAdapters: Record<string, MediaAdapter>;
|
|
10
12
|
children?: ReactNode;
|
|
11
13
|
}
|
|
12
14
|
export interface SelectedServer {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/api.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/api.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC5C,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAE5C,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,KAAK,cAAc,GAAG,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,gBAAgB,CAAC,CAAC;AAE5E,UAAU,gBAAgB;IACxB,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC7D;AAKD,wBAAgB,aAAa,IAAI,cAAc,CAK9C;AAED,wBAAgB,sBAAsB,IAAI,gBAAgB,CAKzD;AAED,wBAAgB,WAAW,CAAC,EAC1B,cAAc,EACd,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,gBAAgB,2CA+DlB"}
|
package/dist/ui/contexts/api.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext, useEffect, useMemo, useState, } from 'react';
|
|
4
|
-
const ApiContext = createContext(
|
|
5
|
-
const ServerSelectContext = createContext(
|
|
4
|
+
const ApiContext = createContext(null);
|
|
5
|
+
const ServerSelectContext = createContext(null);
|
|
6
6
|
export function useApiContext() {
|
|
7
7
|
const ctx = useContext(ApiContext);
|
|
8
8
|
if (!ctx)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-example.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBtD,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,WAAW,CAAC;KACnB,EAAE,CAAC;IACJ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,2CAqDA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"code-example.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBtD,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,WAAW,CAAC;KACnB,EAAE,CAAC;IACJ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,2CAqDA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,kDAwC5C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,2CAoB1D;AAgBD,wBAAgB,cAAc;IAUxB;;OAEG;;IAEH;;OAEG;qBAxKS,WAAW,KAAK,IAAI;EA6KrC"}
|
|
@@ -48,7 +48,7 @@ export function CodeExampleProvider({ route, examples, initialKey, children, })
|
|
|
48
48
|
}), [addListener, examples, key, removeListener, route, setData, updateKey]), children: children }));
|
|
49
49
|
}
|
|
50
50
|
export function CodeExample(props) {
|
|
51
|
-
const { shikiOptions } = useApiContext();
|
|
51
|
+
const { shikiOptions, mediaAdapters } = useApiContext();
|
|
52
52
|
const { examples, key, route, addListener, removeListener } = useContext(CodeExampleContext);
|
|
53
53
|
const { server } = useServerSelectContext();
|
|
54
54
|
const [data, setData] = useState(() => {
|
|
@@ -69,8 +69,10 @@ export function CodeExample(props) {
|
|
|
69
69
|
return;
|
|
70
70
|
if (typeof sample.source === 'string')
|
|
71
71
|
return sample.source;
|
|
72
|
-
return sample.source(`${server ? getUrl(server.url, server.variables) : '/'}${route}`, data
|
|
73
|
-
|
|
72
|
+
return sample.source(`${server ? getUrl(server.url, server.variables) : '/'}${route}`, data, {
|
|
73
|
+
mediaAdapters,
|
|
74
|
+
});
|
|
75
|
+
}, [mediaAdapters, sample, server, route, data]);
|
|
74
76
|
if (!code || !sample)
|
|
75
77
|
return null;
|
|
76
78
|
return (_jsx(DynamicCodeBlock, { lang: sample.lang, code: code, options: shikiOptions }));
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
2
|
import type { PropertyProps, RootProps } from '../render/renderer.js';
|
|
3
|
-
export declare function Root({ children,
|
|
3
|
+
export declare function Root({ children, className, ctx, ...props }: RootProps & HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
export declare function APIInfo({ className, ...props }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
export declare function API({ children, ...props }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
export declare function Property({ name, type, required, deprecated, children, }: PropertyProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/ui/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWlE,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWlE,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,SAAS,EACT,GAAG,EACH,GAAG,KAAK,EACT,EAAE,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC,2CAmB5C;AAED,wBAAgB,OAAO,CAAC,EACtB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,2CAMhC;AAED,wBAAgB,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,CAAC,cAAc,CAAC,2CAmBzE;AAED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE,aAAa,2CAsBf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,2CAY/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAiBA;AAED,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/ui/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import { ChevronDown } from '../icons.js';
|
|
|
5
5
|
import { ApiProvider } from '../ui/contexts/api.js';
|
|
6
6
|
import { cn } from 'fumadocs-ui/utils/cn';
|
|
7
7
|
import { buttonVariants } from 'fumadocs-ui/components/ui/button';
|
|
8
|
-
export function Root({ children,
|
|
9
|
-
return (_jsx("div", { className: cn('flex flex-col gap-24 text-sm text-fd-muted-foreground', className), ...props, children: _jsx(ApiProvider, { servers: servers, shikiOptions: shikiOptions, defaultBaseUrl: baseUrl, children: children }) }));
|
|
8
|
+
export function Root({ children, className, ctx, ...props }) {
|
|
9
|
+
return (_jsx("div", { className: cn('flex flex-col gap-24 text-sm text-fd-muted-foreground', className), ...props, children: _jsx(ApiProvider, { mediaAdapters: ctx.mediaAdapters, servers: ctx.servers, shikiOptions: ctx.shikiOptions, defaultBaseUrl: ctx.baseUrl, children: children }) }));
|
|
10
10
|
}
|
|
11
11
|
export function APIInfo({ className, ...props }) {
|
|
12
12
|
return (_jsx("div", { className: cn('min-w-0 flex-1', className), ...props, children: props.children }));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Convert input value to hardcoded string (with quotes)
|
|
3
3
|
*/
|
|
4
|
-
export declare function inputToString(value: unknown, format?: 'xml' | 'json' | 'url', multiLine?: 'single-quote' | 'backtick' | 'python' | 'none'): string;
|
|
4
|
+
export declare function inputToString(value: unknown, format?: 'xml' | 'json' | 'url' | 'ndjson', multiLine?: 'single-quote' | 'backtick' | 'python' | 'none'): string;
|
|
5
5
|
//# sourceMappingURL=input-to-string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/input-to-string.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,KAAK,GAAG,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"input-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/input-to-string.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAiB,EAClD,SAAS,GAAE,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAe,GAClE,MAAM,CAyCR"}
|
|
@@ -14,6 +14,11 @@ export function inputToString(value, format = 'json', multiLine = 'none') {
|
|
|
14
14
|
if (format === 'json') {
|
|
15
15
|
return getStr(JSON.stringify(value, null, 2));
|
|
16
16
|
}
|
|
17
|
+
if (format === 'ndjson') {
|
|
18
|
+
return getStr(Array.isArray(value)
|
|
19
|
+
? value.map((v) => JSON.stringify(v)).join('\n')
|
|
20
|
+
: JSON.stringify(value, null, 2));
|
|
21
|
+
}
|
|
17
22
|
if (format === 'url') {
|
|
18
23
|
const params = new URLSearchParams();
|
|
19
24
|
if (typeof value !== 'object')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dereference, load, upgrade } from '@scalar/openapi-parser';
|
|
2
2
|
import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls';
|
|
3
3
|
import { readFiles } from '@scalar/openapi-parser/plugins/read-files';
|
|
4
4
|
const cache = new Map();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.6",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@radix-ui/react-dialog": "^1.1.11",
|
|
50
50
|
"@radix-ui/react-select": "^2.2.2",
|
|
51
51
|
"@radix-ui/react-slot": "^1.2.0",
|
|
52
|
-
"@scalar/openapi-parser": "0.10.
|
|
52
|
+
"@scalar/openapi-parser": "0.10.17",
|
|
53
53
|
"ajv": "^8.17.1",
|
|
54
54
|
"class-variance-authority": "^0.7.1",
|
|
55
55
|
"fast-glob": "^3.3.3",
|
|
@@ -58,16 +58,16 @@
|
|
|
58
58
|
"js-yaml": "^4.1.0",
|
|
59
59
|
"next-themes": "^0.4.6",
|
|
60
60
|
"openapi-sampler": "^1.6.1",
|
|
61
|
-
"react-hook-form": "^7.56.
|
|
61
|
+
"react-hook-form": "^7.56.2",
|
|
62
62
|
"remark": "^15.0.1",
|
|
63
63
|
"remark-rehype": "^11.1.2",
|
|
64
64
|
"shiki": "^3.3.0",
|
|
65
65
|
"xml-js": "^1.6.11",
|
|
66
|
-
"fumadocs-core": "15.2.
|
|
67
|
-
"fumadocs-ui": "15.2.
|
|
66
|
+
"fumadocs-core": "15.2.14",
|
|
67
|
+
"fumadocs-ui": "15.2.14"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@scalar/api-client-react": "^1.2.
|
|
70
|
+
"@scalar/api-client-react": "^1.2.31",
|
|
71
71
|
"@types/js-yaml": "^4.0.9",
|
|
72
72
|
"@types/node": "22.15.3",
|
|
73
73
|
"@types/openapi-sampler": "^1.0.3",
|