fumadocs-openapi 9.0.17 → 9.1.0
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 +47 -16
- package/dist/media/adapter.d.ts.map +1 -1
- package/dist/media/adapter.js +3 -4
- package/dist/playground/client.d.ts +6 -4
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +19 -18
- package/dist/playground/fetcher.d.ts.map +1 -1
- package/dist/playground/fetcher.js +14 -24
- package/dist/playground/index.d.ts +3 -5
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +2 -4
- package/dist/render/api-page.d.ts.map +1 -1
- package/dist/render/api-page.js +2 -8
- package/dist/render/operation/api-example.d.ts +3 -2
- package/dist/render/operation/api-example.d.ts.map +1 -1
- package/dist/render/operation/api-example.js +8 -6
- package/dist/render/operation/get-request-data.d.ts +2 -2
- package/dist/render/operation/get-request-data.d.ts.map +1 -1
- package/dist/render/renderer.d.ts.map +1 -1
- package/dist/render/renderer.js +3 -2
- package/dist/render/schema.d.ts +1 -1
- package/dist/render/schema.d.ts.map +1 -1
- package/dist/render/schema.js +11 -12
- package/dist/requests/_shared.d.ts +20 -4
- package/dist/requests/_shared.d.ts.map +1 -1
- package/dist/requests/_shared.js +113 -0
- package/dist/requests/csharp.d.ts.map +1 -1
- package/dist/requests/csharp.js +12 -8
- package/dist/requests/curl.d.ts.map +1 -1
- package/dist/requests/curl.js +5 -6
- package/dist/requests/go.d.ts +1 -1
- package/dist/requests/go.d.ts.map +1 -1
- package/dist/requests/go.js +6 -6
- package/dist/requests/java.d.ts.map +1 -1
- package/dist/requests/java.js +8 -8
- package/dist/requests/javascript.d.ts.map +1 -1
- package/dist/requests/javascript.js +9 -6
- package/dist/requests/python.d.ts.map +1 -1
- package/dist/requests/python.js +12 -5
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/components/accordion.d.ts.map +1 -1
- package/dist/ui/components/accordion.js +1 -1
- package/dist/ui/contexts/api.d.ts +2 -1
- package/dist/ui/contexts/api.d.ts.map +1 -1
- package/dist/ui/contexts/code-example.d.ts +5 -4
- package/dist/ui/contexts/code-example.d.ts.map +1 -1
- package/dist/ui/contexts/code-example.js +14 -11
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +8 -2
- package/dist/ui/lazy.d.ts +2 -1
- package/dist/ui/lazy.d.ts.map +1 -1
- package/dist/utils/get-typescript-schema.d.ts.map +1 -1
- package/dist/utils/get-typescript-schema.js +13 -8
- package/dist/utils/process-document.d.ts.map +1 -1
- package/dist/utils/process-document.js +8 -11
- package/dist/utils/schema-to-string.d.ts +2 -1
- package/dist/utils/schema-to-string.d.ts.map +1 -1
- package/dist/utils/schema-to-string.js +54 -46
- package/dist/utils/url.js +10 -12
- package/package.json +5 -5
package/dist/media/adapter.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { RequestData } from '../requests/_shared.js';
|
|
2
1
|
interface BaseContext {
|
|
3
2
|
/**
|
|
4
3
|
* Passed by your custom example generator, for your custom media adapter to receive.
|
|
@@ -26,13 +25,21 @@ export type MediaContext = JavaContext | GoContext | JavaScriptContext | CSharpC
|
|
|
26
25
|
});
|
|
27
26
|
export interface MediaAdapter {
|
|
28
27
|
/**
|
|
29
|
-
*
|
|
28
|
+
* the same adapter that's passed from a client component.
|
|
29
|
+
*
|
|
30
|
+
* It is needed for client-side serialization of values.
|
|
31
|
+
*/
|
|
32
|
+
client?: MediaAdapter;
|
|
33
|
+
/**
|
|
34
|
+
* encode data into specified media type for `fetch()`.
|
|
30
35
|
*
|
|
31
36
|
* Return the encoded form of `data.body` property.
|
|
32
37
|
*/
|
|
33
|
-
encode: (data:
|
|
38
|
+
encode: (data: {
|
|
39
|
+
body: unknown;
|
|
40
|
+
}) => BodyInit;
|
|
34
41
|
/**
|
|
35
|
-
* generate code for
|
|
42
|
+
* generate code example for creating the body in a given programming language.
|
|
36
43
|
*
|
|
37
44
|
* @param data - request data.
|
|
38
45
|
* @param lang - name of programming language.
|
|
@@ -40,31 +47,55 @@ export interface MediaAdapter {
|
|
|
40
47
|
*
|
|
41
48
|
* @returns code that inits a `body` variable, or undefined if not supported (skip example for that language).
|
|
42
49
|
*/
|
|
43
|
-
generateExample: (data:
|
|
50
|
+
generateExample: (data: {
|
|
51
|
+
body: unknown;
|
|
52
|
+
}, ctx: MediaContext) => string | undefined;
|
|
44
53
|
}
|
|
45
54
|
export declare const defaultAdapters: {
|
|
46
55
|
'application/json': {
|
|
47
|
-
encode(data:
|
|
48
|
-
|
|
56
|
+
encode(data: {
|
|
57
|
+
body: unknown;
|
|
58
|
+
}): string;
|
|
59
|
+
generateExample(data: {
|
|
60
|
+
body: unknown;
|
|
61
|
+
}, ctx: MediaContext): string | undefined;
|
|
49
62
|
};
|
|
50
63
|
'application/xml': {
|
|
51
|
-
encode(data:
|
|
52
|
-
|
|
64
|
+
encode(data: {
|
|
65
|
+
body: unknown;
|
|
66
|
+
}): any;
|
|
67
|
+
generateExample(data: {
|
|
68
|
+
body: unknown;
|
|
69
|
+
}, ctx: MediaContext): string | undefined;
|
|
53
70
|
};
|
|
54
71
|
'application/x-ndjson': {
|
|
55
|
-
encode(data:
|
|
56
|
-
|
|
72
|
+
encode(data: {
|
|
73
|
+
body: unknown;
|
|
74
|
+
}): string;
|
|
75
|
+
generateExample(data: {
|
|
76
|
+
body: unknown;
|
|
77
|
+
}, ctx: MediaContext): string | undefined;
|
|
57
78
|
};
|
|
58
79
|
'application/x-www-form-urlencoded': {
|
|
59
|
-
encode(data:
|
|
60
|
-
|
|
80
|
+
encode(data: {
|
|
81
|
+
body: unknown;
|
|
82
|
+
}): URLSearchParams;
|
|
83
|
+
generateExample(data: {
|
|
84
|
+
body: unknown;
|
|
85
|
+
}, ctx: MediaContext): string | undefined;
|
|
61
86
|
};
|
|
62
87
|
'multipart/form-data': {
|
|
63
|
-
encode(data:
|
|
64
|
-
|
|
88
|
+
encode(data: {
|
|
89
|
+
body: unknown;
|
|
90
|
+
}): FormData;
|
|
91
|
+
generateExample(data: {
|
|
92
|
+
body: unknown;
|
|
93
|
+
}, ctx: MediaContext): string | undefined;
|
|
65
94
|
};
|
|
66
95
|
'application/octet-stream': {
|
|
67
|
-
encode(data:
|
|
96
|
+
encode(data: {
|
|
97
|
+
body: unknown;
|
|
98
|
+
}): BodyInit;
|
|
68
99
|
generateExample(): undefined;
|
|
69
100
|
};
|
|
70
101
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/media/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/media/adapter.ts"],"names":[],"mappings":"AAIA,UAAU,WAAW;IACnB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,UAAU,SAAU,SAAQ,WAAW;IACrC,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,UAAU,iBAAkB,SAAQ,WAAW;IAC7C,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,UAAU,WAAY,SAAQ,WAAW;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED,UAAU,aAAc,SAAQ,WAAW;IACzC,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,SAAS,GACT,iBAAiB,GACjB,aAAa,GACb,CAAC,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IAEtB;;;;OAIG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,QAAQ,CAAC;IAE9C;;;;;;;;OAQG;IACH,eAAe,EAAE,CACf,IAAI,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,EACvB,GAAG,EAAE,YAAY,KACd,MAAM,GAAG,SAAS,CAAC;CACzB;AAED,eAAO,MAAM,eAAe;;;kBAjBH,OAAO;;;kBAYd,OAAO;;;;;kBAZA,OAAO;;;kBAYd,OAAO;;;;;kBAZA,OAAO;;;kBAYd,OAAO;;;;;kBAZA,OAAO;;;kBAYd,OAAO;;;;;kBAZA,OAAO;;;kBAYd,OAAO;;;;;kBAZA,OAAO;YAwJN,QAAQ;;;CAOM,CAAC"}
|
package/dist/media/adapter.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
'use client';
|
|
2
1
|
import { escapeString, inputToString } from '../utils/input-to-string.js';
|
|
2
|
+
// @ts-expect-error -- untyped
|
|
3
|
+
import { js2xml } from 'xml-js/lib/js2xml';
|
|
3
4
|
export const defaultAdapters = {
|
|
4
5
|
'application/json': {
|
|
5
6
|
encode(data) {
|
|
@@ -10,9 +11,7 @@ export const defaultAdapters = {
|
|
|
10
11
|
},
|
|
11
12
|
},
|
|
12
13
|
'application/xml': {
|
|
13
|
-
|
|
14
|
-
// @ts-expect-error -- untyped
|
|
15
|
-
const { js2xml } = await import('xml-js/lib/js2xml');
|
|
14
|
+
encode(data) {
|
|
16
15
|
return js2xml(data.body, {
|
|
17
16
|
compact: true,
|
|
18
17
|
spaces: 2,
|
|
@@ -2,12 +2,14 @@ import { type FC, type HTMLAttributes, type ReactElement } from 'react';
|
|
|
2
2
|
import type { ControllerFieldState, ControllerRenderProps, FieldPath, UseFormStateReturn } from 'react-hook-form';
|
|
3
3
|
import type { FetchResult } from '../playground/fetcher.js';
|
|
4
4
|
import type { ParameterField, RequestSchema, SecurityEntry } from '../playground/index.js';
|
|
5
|
+
import { type RequestData } from '../requests/_shared.js';
|
|
5
6
|
interface FormValues {
|
|
6
|
-
path: Record<string,
|
|
7
|
-
query: Record<string,
|
|
8
|
-
header: Record<string,
|
|
9
|
-
cookie: Record<string,
|
|
7
|
+
path: Record<string, unknown>;
|
|
8
|
+
query: Record<string, unknown>;
|
|
9
|
+
header: Record<string, unknown>;
|
|
10
|
+
cookie: Record<string, unknown>;
|
|
10
11
|
body: unknown;
|
|
12
|
+
_encoded?: RequestData;
|
|
11
13
|
}
|
|
12
14
|
export interface CustomField<TName extends FieldPath<FormValues>, Info> {
|
|
13
15
|
render: (props: {
|
|
@@ -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,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACd,MAAM,oBAAoB,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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,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,SAAS,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,CAAC;QACzD,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;CACJ;AAgBD,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAC7B,KAAK,EACL,MAAc,EACd,UAAU,EACV,UAAe,EACf,IAAI,EACJ,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EAAE,EAAE,aAAoC,EAAO,EACzD,GAAG,IAAI,EACR,EAAE,WAAW,2CAyLb"}
|
|
@@ -11,6 +11,7 @@ import { MethodLabel } from '../ui/components/method-label.js';
|
|
|
11
11
|
import { useQuery } from '../utils/use-query.js';
|
|
12
12
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from 'fumadocs-ui/components/ui/collapsible';
|
|
13
13
|
import { ChevronDown, LoaderCircle } from '../icons.js';
|
|
14
|
+
import { encodeRequestData } from '../requests/_shared.js';
|
|
14
15
|
import { buttonVariants } from 'fumadocs-ui/components/ui/button';
|
|
15
16
|
import { cn } from 'fumadocs-ui/utils/cn';
|
|
16
17
|
import { SchemaProvider, useResolvedSchema, } from '../playground/schema.js';
|
|
@@ -20,17 +21,6 @@ import { useOnChange } from 'fumadocs-core/utils/use-on-change';
|
|
|
20
21
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/components/select.js';
|
|
21
22
|
import { labelVariants } from '../ui/components/input.js';
|
|
22
23
|
const AuthPrefix = '__fumadocs_auth';
|
|
23
|
-
function toRequestData(method, mediaType, value) {
|
|
24
|
-
return {
|
|
25
|
-
path: value.path,
|
|
26
|
-
method,
|
|
27
|
-
header: value.header,
|
|
28
|
-
body: value.body,
|
|
29
|
-
bodyMediaType: mediaType,
|
|
30
|
-
cookie: value.cookie,
|
|
31
|
-
query: value.query,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
24
|
const ServerSelect = lazy(() => import('../ui/server-select.js'));
|
|
35
25
|
const OauthDialog = lazy(() => import('./auth/oauth-dialog.js').then((mod) => ({
|
|
36
26
|
default: mod.OauthDialog,
|
|
@@ -38,7 +28,7 @@ const OauthDialog = lazy(() => import('./auth/oauth-dialog.js').then((mod) => ({
|
|
|
38
28
|
const OauthDialogTrigger = lazy(() => import('./auth/oauth-dialog.js').then((mod) => ({
|
|
39
29
|
default: mod.OauthDialogTrigger,
|
|
40
30
|
})));
|
|
41
|
-
export default function Client({ route, method = 'GET', securities, parameters, body, fields, references, proxyUrl, components: { ResultDisplay = DefaultResultDisplay } = {}, ...rest }) {
|
|
31
|
+
export default function Client({ route, method = 'GET', securities, parameters = [], body, fields, references, proxyUrl, components: { ResultDisplay = DefaultResultDisplay } = {}, ...rest }) {
|
|
42
32
|
const { server } = useServerSelectContext();
|
|
43
33
|
const requestData = useRequestInitialData();
|
|
44
34
|
const updater = useRequestDataUpdater();
|
|
@@ -58,10 +48,10 @@ export default function Client({ route, method = 'GET', securities, parameters,
|
|
|
58
48
|
});
|
|
59
49
|
const testQuery = useQuery(async (input) => {
|
|
60
50
|
const fetcher = await import('./fetcher.js').then((mod) => mod.createBrowserFetcher(mediaAdapters));
|
|
61
|
-
|
|
62
|
-
return fetcher.fetch(joinURL(withBase(server ? resolveServerUrl(server.url, server.variables) : '/', window.location.origin), resolveRequestData(route,
|
|
51
|
+
input._encoded ?? (input._encoded = encodeRequestData({ ...mapInputs(input), method, bodyMediaType: body?.mediaType }, mediaAdapters, parameters));
|
|
52
|
+
return fetcher.fetch(joinURL(withBase(server ? resolveServerUrl(server.url, server.variables) : '/', window.location.origin), resolveRequestData(route, input._encoded)), {
|
|
63
53
|
proxyUrl,
|
|
64
|
-
...
|
|
54
|
+
...input._encoded,
|
|
65
55
|
});
|
|
66
56
|
});
|
|
67
57
|
function initAuthValues(values, inputs) {
|
|
@@ -102,7 +92,13 @@ export default function Client({ route, method = 'GET', securities, parameters,
|
|
|
102
92
|
localStorage.setItem(AuthPrefix + item.original.id, JSON.stringify(value));
|
|
103
93
|
}
|
|
104
94
|
}
|
|
105
|
-
|
|
95
|
+
const data = {
|
|
96
|
+
...mapInputs(values),
|
|
97
|
+
method,
|
|
98
|
+
bodyMediaType: body?.mediaType,
|
|
99
|
+
};
|
|
100
|
+
values._encoded ?? (values._encoded = encodeRequestData(data, mediaAdapters, parameters));
|
|
101
|
+
updater.setData(data, values._encoded);
|
|
106
102
|
});
|
|
107
103
|
useEffect(() => {
|
|
108
104
|
let timer = null;
|
|
@@ -111,6 +107,8 @@ export default function Client({ route, method = 'GET', securities, parameters,
|
|
|
111
107
|
values: true,
|
|
112
108
|
},
|
|
113
109
|
callback({ values }) {
|
|
110
|
+
// remove cached encoded request data
|
|
111
|
+
delete values._encoded;
|
|
114
112
|
if (timer)
|
|
115
113
|
window.clearTimeout(timer);
|
|
116
114
|
timer = window.setTimeout(() => onUpdateDebounced(values), timer ? 400 : 0);
|
|
@@ -157,10 +155,13 @@ function FormBody({ parameters = [], fields = {}, body, }) {
|
|
|
157
155
|
const type = paramTypes[i];
|
|
158
156
|
return (_jsx(CollapsiblePanel, { title: name, children: param.map((field) => {
|
|
159
157
|
const fieldName = `${type}.${field.name}`;
|
|
158
|
+
const schema = (field.content
|
|
159
|
+
? field.content[Object.keys(field.content)[0]].schema
|
|
160
|
+
: field.schema);
|
|
160
161
|
if (fields?.parameter) {
|
|
161
|
-
return renderCustomField(fieldName,
|
|
162
|
+
return renderCustomField(fieldName, schema, fields.parameter, field.name);
|
|
162
163
|
}
|
|
163
|
-
return (_jsx(FieldSet, { name: field.name, fieldName: fieldName, field:
|
|
164
|
+
return (_jsx(FieldSet, { name: field.name, fieldName: fieldName, field: schema }, fieldName));
|
|
164
165
|
}) }, name));
|
|
165
166
|
}), body && (_jsx(CollapsiblePanel, { title: "Body", children: fields.body ? (renderCustomField('body', body.schema, fields.body)) : (_jsx(BodyInput, { field: body.schema })) }))] }));
|
|
166
167
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/playground/fetcher.ts"],"names":[],"mappings":"AAAA,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;;;;OAIG;IACH,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;CACrE;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GACrC,OAAO,
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/playground/fetcher.ts"],"names":[],"mappings":"AAAA,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;;;;OAIG;IACH,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;CACrE;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GACrC,OAAO,CAqFT"}
|
|
@@ -5,9 +5,13 @@ export function createBrowserFetcher(adapters) {
|
|
|
5
5
|
if (options.bodyMediaType)
|
|
6
6
|
headers.append('Content-Type', options.bodyMediaType);
|
|
7
7
|
for (const key in options.header) {
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
headers.append(key,
|
|
8
|
+
const param = options.header[key];
|
|
9
|
+
if (!Array.isArray(param.value)) {
|
|
10
|
+
headers.append(key, param.value);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
headers.append(key, param.value.join(','));
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
16
|
const proxyUrl = options.proxyUrl
|
|
13
17
|
? new URL(options.proxyUrl, document.baseURI)
|
|
@@ -25,30 +29,16 @@ export function createBrowserFetcher(adapters) {
|
|
|
25
29
|
type: 'text',
|
|
26
30
|
data: `[Fumadocs] No adapter for ${options.bodyMediaType}, you need to specify one from 'createOpenAPI()'.`,
|
|
27
31
|
};
|
|
28
|
-
body =
|
|
32
|
+
body = adapter.encode(options);
|
|
29
33
|
}
|
|
30
34
|
// cookies
|
|
31
35
|
for (const key in options.cookie) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
? `domain=${proxyUrl.host}`
|
|
39
|
-
: undefined,
|
|
40
|
-
path: '/',
|
|
41
|
-
'max-age': 30,
|
|
42
|
-
};
|
|
43
|
-
let str = '';
|
|
44
|
-
for (const [key, value] of Object.entries(cookie)) {
|
|
45
|
-
if (value) {
|
|
46
|
-
if (str.length > 0)
|
|
47
|
-
str += '; ';
|
|
48
|
-
str += `${key}=${value}`;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
document.cookie = str;
|
|
36
|
+
const param = options.cookie[key];
|
|
37
|
+
const segs = [`${key}=${param.value}`];
|
|
38
|
+
if (proxyUrl && proxyUrl.origin !== window.location.origin)
|
|
39
|
+
segs.push(`domain=${proxyUrl.host}`);
|
|
40
|
+
segs.push('path=/', 'max-age=30');
|
|
41
|
+
document.cookie = segs.join('; ');
|
|
52
42
|
}
|
|
53
43
|
return fetch(url, {
|
|
54
44
|
method: options.method,
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type { MethodInformation, RenderContext, SecuritySchemeObject } from '../types.js';
|
|
2
|
-
import { type ParsedSchema } from '../utils/schema.js';
|
|
1
|
+
import type { MethodInformation, ParameterObject, RenderContext, SecuritySchemeObject } from '../types.js';
|
|
2
|
+
import { type NoReference, type ParsedSchema } from '../utils/schema.js';
|
|
3
3
|
import { type ClientProps } from './client.js';
|
|
4
|
-
export type ParameterField = {
|
|
5
|
-
name: string;
|
|
6
|
-
description?: string;
|
|
4
|
+
export type ParameterField = NoReference<ParameterObject> & {
|
|
7
5
|
schema: ParsedSchema;
|
|
8
6
|
in: 'cookie' | 'header' | 'query' | 'path';
|
|
9
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/playground/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACrB,MAAM,SAAS,CAAC;AACjB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/playground/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,oBAAoB,EACrB,MAAM,SAAS,CAAC;AACjB,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,eAAe,CAAC,GAAG;IAC1D,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,MAAM,MAAM,aAAa,GAAG,oBAAoB,GAAG;IACjD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,wBAAsB,aAAa,CAAC,EAClC,IAAI,EACJ,MAAM,EACN,GAAG,EACH,MAAM,GACP,EAAE,kBAAkB,oDAwCpB"}
|
package/dist/playground/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { getPreferredType } from '../utils/schema.js';
|
|
2
|
+
import { getPreferredType, } from '../utils/schema.js';
|
|
3
3
|
import { ClientLazy } from '../ui/lazy.js';
|
|
4
4
|
export async function APIPlayground({ path, method, ctx, client, }) {
|
|
5
5
|
let currentId = 0;
|
|
@@ -17,10 +17,8 @@ export async function APIPlayground({ path, method, ctx, client, }) {
|
|
|
17
17
|
method: method.method,
|
|
18
18
|
route: path,
|
|
19
19
|
parameters: method.parameters?.map((v) => ({
|
|
20
|
-
|
|
21
|
-
in: v.in,
|
|
20
|
+
...v,
|
|
22
21
|
schema: writeReferences((v.schema ?? true), context),
|
|
23
|
-
description: v.description,
|
|
24
22
|
})),
|
|
25
23
|
body: bodyContent && mediaType
|
|
26
24
|
? {
|
|
@@ -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;AAGlC,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,OA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sB,OAAO,CAAC,KAAK,EAAE,YAAY,oDAkEhD;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,CA0BxB"}
|
package/dist/render/api-page.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Operation } from '../render/operation/index.js';
|
|
|
4
4
|
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
|
+
import { defaultAdapters } from '../media/adapter.js';
|
|
7
8
|
export async function APIPage(props) {
|
|
8
9
|
const { operations, hasHead = true, webhooks, disableCache = process.env.NODE_ENV === 'development', } = props;
|
|
9
10
|
const processed = await processDocument(props.document, disableCache);
|
|
@@ -48,14 +49,7 @@ export async function getContext(schema, options = {}) {
|
|
|
48
49
|
generateCodeSamples: options.generateCodeSamples,
|
|
49
50
|
servers,
|
|
50
51
|
mediaAdapters: {
|
|
51
|
-
...
|
|
52
|
-
'application/octet-stream': true,
|
|
53
|
-
'application/json': true,
|
|
54
|
-
'multipart/form-data': true,
|
|
55
|
-
'application/xml': true,
|
|
56
|
-
'application/x-ndjson': true,
|
|
57
|
-
'application/x-www-form-urlencoded': true,
|
|
58
|
-
},
|
|
52
|
+
...defaultAdapters,
|
|
59
53
|
...options.mediaAdapters,
|
|
60
54
|
},
|
|
61
55
|
slugger: new Slugger(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MethodInformation, RenderContext } from '../../types.js';
|
|
2
2
|
import { type ReactNode } from 'react';
|
|
3
3
|
import { type CodeSample } from '../../render/operation/index.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type RawRequestData, type RequestData } from '../../requests/_shared.js';
|
|
5
5
|
interface CustomProperty {
|
|
6
6
|
'x-codeSamples'?: CodeSample[];
|
|
7
7
|
'x-selectedCodeSample'?: string;
|
|
@@ -11,7 +11,8 @@ interface CodeExampleItem {
|
|
|
11
11
|
key: string;
|
|
12
12
|
name: string;
|
|
13
13
|
description?: string;
|
|
14
|
-
data:
|
|
14
|
+
data: RawRequestData;
|
|
15
|
+
encoded: RequestData;
|
|
15
16
|
}
|
|
16
17
|
export declare function APIExampleProvider({ examples, method, children, route, }: {
|
|
17
18
|
examples: CodeExampleItem[];
|
|
@@ -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;AAM3D,OAAO,KAAK,
|
|
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,EAEL,KAAK,cAAc,EACnB,KAAK,WAAW,EACjB,MAAM,oBAAoB,CAAC;AA6B5B,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,cAAc,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;CACtB;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,2CAYA;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,GAAG,EAAE,aAAa,GACjB,eAAe,EAAE,CA0CnB;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"}
|
|
@@ -5,6 +5,7 @@ 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';
|
|
8
|
+
import { encodeRequestData, } from '../../requests/_shared.js';
|
|
8
9
|
const defaultSamples = [
|
|
9
10
|
{
|
|
10
11
|
label: 'cURL',
|
|
@@ -33,10 +34,7 @@ const defaultSamples = [
|
|
|
33
34
|
];
|
|
34
35
|
export function APIExampleProvider({ examples, method, children, route, }) {
|
|
35
36
|
const exclusiveSampleKey = method['x-exclusiveCodeSample'];
|
|
36
|
-
return (_jsx(CodeExampleProvider, { initialKey: exclusiveSampleKey, route: route, examples: examples
|
|
37
|
-
key: example.key,
|
|
38
|
-
data: example.data,
|
|
39
|
-
})), children: children }));
|
|
37
|
+
return (_jsx(CodeExampleProvider, { initialKey: exclusiveSampleKey, route: route, examples: examples, children: children }));
|
|
40
38
|
}
|
|
41
39
|
export function getAPIExamples(path, method, ctx) {
|
|
42
40
|
const media = method.requestBody
|
|
@@ -46,22 +44,26 @@ export function getAPIExamples(path, method, ctx) {
|
|
|
46
44
|
if (bodyOfType?.examples) {
|
|
47
45
|
const result = [];
|
|
48
46
|
for (const [key, value] of Object.entries(bodyOfType.examples)) {
|
|
47
|
+
const data = getRequestData(path, method, key, ctx);
|
|
49
48
|
result.push({
|
|
50
49
|
key,
|
|
51
50
|
name: value.summary ?? key,
|
|
52
51
|
description: value.description,
|
|
53
|
-
data
|
|
52
|
+
data,
|
|
53
|
+
encoded: encodeRequestData(data, ctx.mediaAdapters, method.parameters ?? []),
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
if (result.length > 0)
|
|
57
57
|
return result;
|
|
58
58
|
}
|
|
59
|
+
const data = getRequestData(path, method, null, ctx);
|
|
59
60
|
return [
|
|
60
61
|
{
|
|
61
62
|
key: '_default',
|
|
62
63
|
name: 'Default',
|
|
63
64
|
description: bodyOfType?.schema?.description,
|
|
64
|
-
data
|
|
65
|
+
data,
|
|
66
|
+
encoded: encodeRequestData(data, ctx.mediaAdapters, method.parameters ?? []),
|
|
65
67
|
},
|
|
66
68
|
];
|
|
67
69
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { MethodInformation, RenderContext } from '../../types.js';
|
|
2
|
-
import type
|
|
3
|
-
export declare function getRequestData(path: string, method: MethodInformation, sampleKey: string | null, _ctx: RenderContext):
|
|
2
|
+
import { type RawRequestData } from '../../requests/_shared.js';
|
|
3
|
+
export declare function getRequestData(path: string, method: MethodInformation, sampleKey: string | null, _ctx: RenderContext): RawRequestData;
|
|
4
4
|
//# sourceMappingURL=get-request-data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-request-data.d.ts","sourceRoot":"","sources":["../../../src/render/operation/get-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIhE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"get-request-data.d.ts","sourceRoot":"","sources":["../../../src/render/operation/get-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIhE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,IAAI,EAAE,aAAa,GAClB,cAAc,CA8DhB"}
|
|
@@ -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;AAiBtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;
|
|
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;AAiBtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAStE,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,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AAa,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,CA0DxC"}
|
package/dist/render/renderer.js
CHANGED
|
@@ -4,6 +4,7 @@ import { AccordionContent, AccordionHeader, AccordionItem, Accordions, 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/lazy.js';
|
|
7
|
+
import { CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, } from 'fumadocs-ui/components/codeblock';
|
|
7
8
|
export function createRenders() {
|
|
8
9
|
return {
|
|
9
10
|
Root,
|
|
@@ -16,9 +17,9 @@ export function createRenders() {
|
|
|
16
17
|
ResponseType: (props) => (_jsxs(AccordionItem, { value: props.label, children: [_jsx(AccordionHeader, { children: _jsx(AccordionTrigger, { children: props.label }) }), _jsx(AccordionContent, { className: "prose-no-margin", children: props.children })] })),
|
|
17
18
|
Property,
|
|
18
19
|
ObjectCollapsible,
|
|
19
|
-
Requests: (
|
|
20
|
+
Requests: ({ items, children }) => (_jsxs(CodeBlockTabs, { groupId: "fumadocs_openapi_requests", defaultValue: items[0], children: [_jsx(CodeBlockTabsList, { children: items.map((item) => (_jsx(CodeBlockTabsTrigger, { value: item, children: item }, item))) }), children] })),
|
|
20
21
|
CodeExampleSelector,
|
|
21
|
-
Request: (props) => _jsx(
|
|
22
|
+
Request: (props) => (_jsx(CodeBlockTab, { value: props.name, children: props.children })),
|
|
22
23
|
APIPlayground,
|
|
23
24
|
};
|
|
24
25
|
}
|
package/dist/render/schema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { ResolvedSchema } from '../utils/schema.js';
|
|
3
3
|
import type { RenderContext } from '../types.js';
|
|
4
|
-
export declare function Schema({ name, schema, required, readOnly, writeOnly, as, ctx:
|
|
4
|
+
export declare function Schema({ name, schema, required, readOnly, writeOnly, as, ctx: renderContext, }: {
|
|
5
5
|
name: string;
|
|
6
6
|
required?: boolean;
|
|
7
7
|
schema: ResolvedSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/render/schema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAe7C,wBAAgB,MAAM,CAAC,EACrB,IAAI,EACJ,MAAM,EACN,QAAgB,EAChB,QAAgB,EAChB,SAAiB,EACjB,EAAe,EACf,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/render/schema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAe7C,wBAAgB,MAAM,CAAC,EACrB,IAAI,EACJ,MAAM,EACN,QAAgB,EAChB,QAAgB,EAChB,SAAiB,EACjB,EAAe,EACf,GAAG,EAAE,aAAa,GACnB,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,cAAc,CAAC;IACvB,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAEzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,EAAE,aAAa,CAAC;CACpB,GAAG,SAAS,CAoTZ"}
|
package/dist/render/schema.js
CHANGED
|
@@ -4,7 +4,8 @@ import { combineSchema } from '../utils/combine-schema.js';
|
|
|
4
4
|
import { Markdown } from './markdown.js';
|
|
5
5
|
import { schemaToString } from '../utils/schema-to-string.js';
|
|
6
6
|
import { Tabs, TabsContent, TabsList, TabsTrigger, } from 'fumadocs-ui/components/tabs';
|
|
7
|
-
export function Schema({ name, schema, required = false, readOnly = false, writeOnly = false, as = 'property', ctx:
|
|
7
|
+
export function Schema({ name, schema, required = false, readOnly = false, writeOnly = false, as = 'property', ctx: renderContext, }) {
|
|
8
|
+
const { renderer } = renderContext;
|
|
8
9
|
function propertyBody(schema, renderPrimitive, ctx) {
|
|
9
10
|
if (Array.isArray(schema.type)) {
|
|
10
11
|
const items = schema.type.flatMap((type) => {
|
|
@@ -20,7 +21,7 @@ export function Schema({ name, schema, required = false, readOnly = false, write
|
|
|
20
21
|
return;
|
|
21
22
|
if (items.length === 1)
|
|
22
23
|
return propertyBody(items[0], renderPrimitive, ctx);
|
|
23
|
-
return (_jsxs(Tabs, { defaultValue: items[0].type, children: [_jsx(TabsList, { children: items.map((item) => (_jsx(TabsTrigger, { value: item.type, children: schemaToString(item) }, item.type))) }), items.map((item) => (_jsxs(TabsContent, { value: item.type, children: [item.description && _jsx(Markdown, { text: item.description }), propertyInfo(item), renderPrimitive(item, ctx)] }, item.type)))] }));
|
|
24
|
+
return (_jsxs(Tabs, { defaultValue: items[0].type, children: [_jsx(TabsList, { children: items.map((item) => (_jsx(TabsTrigger, { value: item.type, children: schemaToString(item, renderContext.schema) }, item.type))) }), items.map((item) => (_jsxs(TabsContent, { value: item.type, children: [item.description && _jsx(Markdown, { text: item.description }), propertyInfo(item), renderPrimitive(item, ctx)] }, item.type)))] }));
|
|
24
25
|
}
|
|
25
26
|
if (schema.oneOf) {
|
|
26
27
|
const oneOf = schema.oneOf.filter((item) => isComplexType(item));
|
|
@@ -29,7 +30,7 @@ export function Schema({ name, schema, required = false, readOnly = false, write
|
|
|
29
30
|
if (oneOf.length === 1) {
|
|
30
31
|
return propertyBody(oneOf[0], renderPrimitive, ctx);
|
|
31
32
|
}
|
|
32
|
-
return (_jsxs(Tabs, { defaultValue: "0", children: [_jsx(TabsList, { children: oneOf.map((item, i) => (_jsx(TabsTrigger, { value: i.toString(), children: schemaToString(item) }, i))) }), oneOf.map((item, i) => (_jsxs(TabsContent, { value: i.toString(), children: [item.description && _jsx(Markdown, { text: item.description }), propertyInfo(item), propertyBody(item, (child, ctx) => primitiveBody(child, ctx, false, true), ctx)] }, i)))] }));
|
|
33
|
+
return (_jsxs(Tabs, { defaultValue: "0", children: [_jsx(TabsList, { children: oneOf.map((item, i) => (_jsx(TabsTrigger, { value: i.toString(), children: schemaToString(item, renderContext.schema) }, i))) }), oneOf.map((item, i) => (_jsxs(TabsContent, { value: i.toString(), children: [item.description && _jsx(Markdown, { text: item.description }), propertyInfo(item), propertyBody(item, (child, ctx) => primitiveBody(child, ctx, false, true), ctx)] }, i)))] }));
|
|
33
34
|
}
|
|
34
35
|
const of = schema.allOf ?? schema.anyOf;
|
|
35
36
|
if (of) {
|
|
@@ -122,12 +123,12 @@ export function Schema({ name, schema, required = false, readOnly = false, write
|
|
|
122
123
|
}
|
|
123
124
|
if (schema.type === 'array') {
|
|
124
125
|
const items = schema.items;
|
|
125
|
-
if (!items ||
|
|
126
|
+
if (!items || typeof items === 'boolean' || ctx.stack.has(items))
|
|
126
127
|
return;
|
|
127
|
-
return (_jsxs(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
return (_jsxs(renderer.ObjectCollapsible, { name: "Array Item", children: [_jsxs("div", { className: "text-sm border-t p-3 border-x prose-no-margin bg-fd-card last:rounded-b-xl first:rounded-tr-xl last:border-b empty:hidden", children: [_jsx(Markdown, { text: items.description ?? 'No Description' }), propertyInfo(items)] }), propertyBody(items, (child, ctx) => primitiveBody(child, ctx, false, true), {
|
|
129
|
+
...ctx,
|
|
130
|
+
stack: ctx.stack.next(schema),
|
|
131
|
+
})] }));
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
function property(key, schema, ctx, props) {
|
|
@@ -139,7 +140,7 @@ export function Schema({ name, schema, required = false, readOnly = false, write
|
|
|
139
140
|
}
|
|
140
141
|
if ((schema.readOnly && !readOnly) || (schema.writeOnly && !writeOnly))
|
|
141
142
|
return;
|
|
142
|
-
return (_jsxs(renderer.Property, { name: key, type: schemaToString(schema), deprecated: schema.deprecated, ...props, children: [schema.description && _jsx(Markdown, { text: schema.description }), propertyInfo(schema), propertyBody(schema, (child, ctx) => primitiveBody(child, ctx, true, true), ctx)] }));
|
|
143
|
+
return (_jsxs(renderer.Property, { name: key, type: schemaToString(schema, renderContext.schema), deprecated: schema.deprecated, ...props, children: [schema.description && _jsx(Markdown, { text: schema.description }), propertyInfo(schema), propertyBody(schema, (child, ctx) => primitiveBody(child, ctx, true, true), ctx)] }));
|
|
143
144
|
}
|
|
144
145
|
const context = {
|
|
145
146
|
stack: schemaStack(),
|
|
@@ -189,9 +190,7 @@ function isComplexType(schema) {
|
|
|
189
190
|
if (arr && arr.some(isComplexType))
|
|
190
191
|
return true;
|
|
191
192
|
return (schema.type === 'object' ||
|
|
192
|
-
(schema.type === 'array' &&
|
|
193
|
-
schema.items != null &&
|
|
194
|
-
isComplexType(schema.items)));
|
|
193
|
+
(schema.type === 'array' && schema.items != null));
|
|
195
194
|
}
|
|
196
195
|
function getRange(value, min, exclusiveMin, max, exclusiveMax) {
|
|
197
196
|
const out = [];
|