fumadocs-openapi 8.1.5 → 8.1.7
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/media/adapter.d.ts +62 -0
- package/dist/media/adapter.d.ts.map +1 -0
- package/dist/media/adapter.js +126 -0
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +6 -3
- 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 -3
- 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 +17 -6
- package/dist/render/operation/api-example.d.ts.map +1 -1
- package/dist/render/operation/api-example.js +1 -1
- 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 +4 -4
- 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 +18 -27
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/client.d.ts +0 -1
- package/dist/ui/client.d.ts.map +1 -1
- package/dist/ui/client.js +0 -1
- package/dist/ui/contexts/api.d.ts +8 -5
- package/dist/ui/contexts/api.d.ts.map +1 -1
- package/dist/ui/contexts/api.js +16 -8
- 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 +3 -3
- package/dist/ui/lazy.d.ts +14 -0
- package/dist/ui/lazy.d.ts.map +1 -0
- package/dist/ui/lazy.js +7 -0
- 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 +7 -1
- package/package.json +6 -6
- package/dist/playground/client.lazy.d.ts +0 -2
- package/dist/playground/client.lazy.d.ts.map +0 -1
- package/dist/playground/client.lazy.js +0 -3
- package/dist/ui/contexts/code-example.lazy.d.ts +0 -12
- package/dist/ui/contexts/code-example.lazy.d.ts.map +0 -1
- package/dist/ui/contexts/code-example.lazy.js +0 -5
|
@@ -0,0 +1,62 @@
|
|
|
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: {
|
|
36
|
+
'application/json': {
|
|
37
|
+
encode(data: RequestData): string;
|
|
38
|
+
generateExample(data: RequestData, ctx: MediaContext): string | undefined;
|
|
39
|
+
};
|
|
40
|
+
'application/xml': {
|
|
41
|
+
encode(data: RequestData): Promise<any>;
|
|
42
|
+
generateExample(data: RequestData, ctx: MediaContext): string | undefined;
|
|
43
|
+
};
|
|
44
|
+
'application/x-ndjson': {
|
|
45
|
+
encode(data: RequestData): string;
|
|
46
|
+
generateExample(data: RequestData, ctx: MediaContext): string | undefined;
|
|
47
|
+
};
|
|
48
|
+
'application/x-www-form-urlencoded': {
|
|
49
|
+
encode(data: RequestData): URLSearchParams;
|
|
50
|
+
generateExample(data: RequestData, ctx: MediaContext): string | undefined;
|
|
51
|
+
};
|
|
52
|
+
'multipart/form-data': {
|
|
53
|
+
encode(data: RequestData): FormData;
|
|
54
|
+
generateExample(data: RequestData, ctx: MediaContext): string | undefined;
|
|
55
|
+
};
|
|
56
|
+
'application/octet-stream': {
|
|
57
|
+
encode(data: RequestData): BodyInit;
|
|
58
|
+
generateExample(): undefined;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/media/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,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;;;;;;;;;;;;;;;;;;;;;;mCAwHF,QAAQ;;;CAOM,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { inputToString } from '../utils/input-to-string.js';
|
|
3
|
+
export const defaultAdapters = {
|
|
4
|
+
'application/json': {
|
|
5
|
+
encode(data) {
|
|
6
|
+
return JSON.stringify(data.body);
|
|
7
|
+
},
|
|
8
|
+
generateExample(data, ctx) {
|
|
9
|
+
return str(data.body, 'json', ctx);
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
'application/xml': {
|
|
13
|
+
async encode(data) {
|
|
14
|
+
// @ts-expect-error -- untyped
|
|
15
|
+
const { js2xml } = await import('xml-js/lib/js2xml');
|
|
16
|
+
return js2xml(data.body, {
|
|
17
|
+
compact: true,
|
|
18
|
+
spaces: 2,
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
generateExample(data, ctx) {
|
|
22
|
+
return str(data.body, 'xml', ctx);
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
'application/x-ndjson': {
|
|
26
|
+
encode(data) {
|
|
27
|
+
if (Array.isArray(data.body)) {
|
|
28
|
+
return data.body.map((v) => JSON.stringify(v)).join('\n');
|
|
29
|
+
}
|
|
30
|
+
return JSON.stringify(data.body);
|
|
31
|
+
},
|
|
32
|
+
generateExample(data, ctx) {
|
|
33
|
+
return str(data.body, 'ndjson', ctx);
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
'application/x-www-form-urlencoded': {
|
|
37
|
+
encode(data) {
|
|
38
|
+
if (typeof data.body !== 'object')
|
|
39
|
+
throw new Error(`Input value must be object, received: ${typeof data.body}`);
|
|
40
|
+
const params = new URLSearchParams();
|
|
41
|
+
for (const key in data.body) {
|
|
42
|
+
params.set(key, String(data.body[key]));
|
|
43
|
+
}
|
|
44
|
+
return params;
|
|
45
|
+
},
|
|
46
|
+
generateExample(data, ctx) {
|
|
47
|
+
if (ctx.lang === 'js') {
|
|
48
|
+
return `const body = new URLSearchParams(${JSON.stringify(data.body, null, 2)})`;
|
|
49
|
+
}
|
|
50
|
+
return str(data.body, 'url', ctx);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
'multipart/form-data': {
|
|
54
|
+
encode(data) {
|
|
55
|
+
const formData = new FormData();
|
|
56
|
+
const body = data.body;
|
|
57
|
+
if (typeof body !== 'object' || !body) {
|
|
58
|
+
throw new Error(`Unsupported body type: ${typeof body}, expected: object`);
|
|
59
|
+
}
|
|
60
|
+
for (const key in body) {
|
|
61
|
+
const prop = body[key];
|
|
62
|
+
if (typeof prop === 'object' && prop instanceof File) {
|
|
63
|
+
formData.set(key, prop);
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(prop) && prop.every((item) => item instanceof File)) {
|
|
66
|
+
for (const item of prop) {
|
|
67
|
+
formData.append(key, item);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (prop && !(prop instanceof File)) {
|
|
71
|
+
formData.set(key, JSON.stringify(prop));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return formData;
|
|
75
|
+
},
|
|
76
|
+
generateExample(data, ctx) {
|
|
77
|
+
if (ctx.lang === 'python') {
|
|
78
|
+
return `body = ${JSON.stringify(data.body, null, 2)}`;
|
|
79
|
+
}
|
|
80
|
+
const s = [];
|
|
81
|
+
if (ctx.lang === 'js') {
|
|
82
|
+
s.push(`const body = new FormData();`);
|
|
83
|
+
for (const [key, value] of Object.entries(data.body)) {
|
|
84
|
+
s.push(`body.set(${key}, ${inputToString(value)})`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (ctx.lang === 'go' && 'addImport' in ctx) {
|
|
88
|
+
ctx.addImport('mime/multipart');
|
|
89
|
+
ctx.addImport('bytes');
|
|
90
|
+
s.push('body := new(bytes.Buffer)');
|
|
91
|
+
s.push('mp := multipart.NewWriter(payload)');
|
|
92
|
+
for (const [key, value] of Object.entries(data.body)) {
|
|
93
|
+
s.push(`mp.WriteField("${key}", ${inputToString(value, 'json', 'backtick')})`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (s.length > 0)
|
|
97
|
+
return s.join('\n');
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
'application/octet-stream': {
|
|
101
|
+
encode(data) {
|
|
102
|
+
return data.body;
|
|
103
|
+
},
|
|
104
|
+
generateExample() {
|
|
105
|
+
// not supported
|
|
106
|
+
return undefined;
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
function str(init, format, ctx) {
|
|
111
|
+
if (ctx.lang === 'js') {
|
|
112
|
+
if (format === 'json') {
|
|
113
|
+
return `const body = JSON.stringify(${JSON.stringify(init, null, 2)})`;
|
|
114
|
+
}
|
|
115
|
+
return `const body = ${inputToString(init, format, 'backtick')}`;
|
|
116
|
+
}
|
|
117
|
+
if (ctx.lang === 'python') {
|
|
118
|
+
if (format === 'json')
|
|
119
|
+
return `body = ${JSON.stringify(init, null, 2)}`;
|
|
120
|
+
return `body = ${inputToString(init, format, 'python')}`;
|
|
121
|
+
}
|
|
122
|
+
if (ctx.lang === 'go' && 'addImport' in ctx) {
|
|
123
|
+
ctx.addImport('strings');
|
|
124
|
+
return `body := strings.NewReader(${inputToString(init, format, 'backtick')})`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -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;AAYrD,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,KAA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requestData = useRequestData();
|
|
34
34
|
const fieldInfoMap = useMemo(() => new Map(), []);
|
|
35
35
|
const authInfo = usePersistentAuthInfo(authorization);
|
|
36
|
+
const { mediaAdapters } = useApiContext();
|
|
36
37
|
const defaultValues = useMemo(() => ({
|
|
37
38
|
authorization: authInfo.info,
|
|
38
39
|
path: requestData.data.path,
|
|
@@ -45,7 +46,7 @@ export default function Client({ route, method = 'GET', authorization, parameter
|
|
|
45
46
|
defaultValues,
|
|
46
47
|
});
|
|
47
48
|
const testQuery = useQuery(async (input) => {
|
|
48
|
-
const fetcher = await import('./fetcher.js').then((mod) => mod.createBrowserFetcher());
|
|
49
|
+
const fetcher = await import('./fetcher.js').then((mod) => mod.createBrowserFetcher(mediaAdapters));
|
|
49
50
|
const serverUrl = server
|
|
50
51
|
? getUrl(server.url, server.variables)
|
|
51
52
|
: window.location.origin;
|
|
@@ -122,12 +123,14 @@ function FormBody({ authorization, parameters = [], fields = {}, body, }) {
|
|
|
122
123
|
}
|
|
123
124
|
return (_jsx(FieldSet, { name: field.name, fieldName: fieldName, field: field.schema }, fieldName));
|
|
124
125
|
})] }, name));
|
|
125
|
-
}), body
|
|
126
|
+
}), body && (_jsx(CollapsiblePanel, { title: "Body", children: fields.body ? (renderCustomField('body', body.schema, fields.body)) : (_jsx(BodyInput, { field: body.schema })) }))] }));
|
|
126
127
|
}
|
|
127
128
|
function BodyInput({ field: _field }) {
|
|
128
129
|
const field = useResolvedSchema(_field);
|
|
129
130
|
const [isJson, setIsJson] = useState(false);
|
|
130
|
-
|
|
131
|
+
if (field.format === 'binary')
|
|
132
|
+
return _jsx(FieldSet, { field: field, fieldName: "body" });
|
|
133
|
+
return (_jsx(_Fragment, { children: isJson ? (_jsx(JsonInput, { fieldName: "body", children: _jsx("button", { className: cn(buttonVariants({
|
|
131
134
|
color: 'ghost',
|
|
132
135
|
size: 'sm',
|
|
133
136
|
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,oDAuCpB"}
|
package/dist/playground/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { getPreferredType } from '../utils/schema.js';
|
|
3
3
|
import { getSecurities } from '../utils/get-security.js';
|
|
4
|
-
import { ClientLazy } from '../
|
|
4
|
+
import { ClientLazy } from '../ui/lazy.js';
|
|
5
5
|
export async function APIPlayground({ path, method, ctx, client, }) {
|
|
6
6
|
let currentId = 0;
|
|
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),
|
|
@@ -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,EAA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AAa,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,oDAsEhD;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"}
|
package/dist/render/api-page.js
CHANGED
|
@@ -10,22 +10,22 @@ export async function APIPage(props) {
|
|
|
10
10
|
const processed = await processDocument(props.document, disableCache);
|
|
11
11
|
const ctx = await getContext(processed, props);
|
|
12
12
|
const { document } = processed;
|
|
13
|
-
return (_jsxs(ctx.renderer.Root, {
|
|
13
|
+
return (_jsxs(ctx.renderer.Root, { ctx: ctx, children: [operations?.map((item) => {
|
|
14
14
|
const pathItem = document.paths?.[item.path];
|
|
15
15
|
if (!pathItem)
|
|
16
|
-
|
|
16
|
+
throw new Error(`[Fumadocs OpenAPI] Path not found in OpenAPI schema: ${item.path}`);
|
|
17
17
|
const operation = pathItem[item.method];
|
|
18
18
|
if (!operation)
|
|
19
|
-
|
|
19
|
+
throw new Error(`[Fumadocs OpenAPI] Method ${item.method} not found in operation: ${item.path}`);
|
|
20
20
|
const method = createMethod(item.method, pathItem, operation);
|
|
21
21
|
return (_jsx(Operation, { method: method, path: item.path, ctx: ctx, hasHead: hasHead }, `${item.path}:${item.method}`));
|
|
22
22
|
}), webhooks?.map((item) => {
|
|
23
23
|
const webhook = document.webhooks?.[item.name];
|
|
24
24
|
if (!webhook)
|
|
25
|
-
|
|
25
|
+
throw new Error(`[Fumadocs OpenAPI] Webhook not found in OpenAPI schema: ${item.name}`);
|
|
26
26
|
const hook = webhook[item.method];
|
|
27
27
|
if (!hook)
|
|
28
|
-
|
|
28
|
+
throw new Error(`[Fumadocs OpenAPI] Method ${item.method} not found in webhook: ${item.name}`);
|
|
29
29
|
const method = createMethod(item.method, webhook, hook);
|
|
30
30
|
return (_jsx(Operation, { type: "webhook", method: method, ctx: {
|
|
31
31
|
...ctx,
|
|
@@ -45,7 +45,7 @@ export async function getContext(schema, options = {}) {
|
|
|
45
45
|
disablePlayground: options.disablePlayground,
|
|
46
46
|
showResponseSchema: options.showResponseSchema,
|
|
47
47
|
renderer: {
|
|
48
|
-
...createRenders(
|
|
48
|
+
...createRenders(),
|
|
49
49
|
...options.renderer,
|
|
50
50
|
},
|
|
51
51
|
shikiOptions: options.shikiOptions,
|
|
@@ -55,6 +55,17 @@ export async function getContext(schema, options = {}) {
|
|
|
55
55
|
? Object.fromEntries(Object.entries(server.variables).map(([k, v]) => [k, v.default]))
|
|
56
56
|
: {}),
|
|
57
57
|
servers,
|
|
58
|
+
mediaAdapters: {
|
|
59
|
+
...{
|
|
60
|
+
'application/octet-stream': true,
|
|
61
|
+
'application/json': true,
|
|
62
|
+
'multipart/form-data': true,
|
|
63
|
+
'application/xml': true,
|
|
64
|
+
'application/x-ndjson': true,
|
|
65
|
+
'application/x-www-form-urlencoded': true,
|
|
66
|
+
},
|
|
67
|
+
...options.mediaAdapters,
|
|
68
|
+
},
|
|
58
69
|
slugger: new Slugger(),
|
|
59
70
|
};
|
|
60
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-example.d.ts","sourceRoot":"","sources":["../../../src/render/operation/api-example.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"api-example.d.ts","sourceRoot":"","sources":["../../../src/render/operation/api-example.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAM3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBtD,UAAU,cAAc;IACtB,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,UAAU,eAAe;IACvB,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,MAAM,EAAE,iBAAiB,GAAG,cAAc,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAeA;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,GAAG,EAAE,aAAa,GACjB,eAAe,EAAE,CA8BnB;AAED,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,MAAM,EAAE,iBAAiB,GAAG,cAAc,CAAC;IAC3C,GAAG,EAAE,aAAa,CAAC;CACpB,oDAmCA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Markdown } from '../../render/markdown.js';
|
|
3
3
|
import { CodeBlock } from '../../render/codeblock.js';
|
|
4
|
-
import { CodeExample, CodeExampleProvider
|
|
4
|
+
import { CodeExample, CodeExampleProvider } from '../../ui/lazy.js';
|
|
5
5
|
import { getPreferredType } from '../../utils/schema.js';
|
|
6
6
|
import { getRequestData } from '../../render/operation/get-request-data.js';
|
|
7
7
|
import { sample } from 'openapi-sampler';
|
|
@@ -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,CA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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
|
-
import { CodeExampleSelector } from '../ui/
|
|
7
|
-
export function createRenders(
|
|
6
|
+
import { CodeExampleSelector } from '../ui/lazy.js';
|
|
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"}
|