fumadocs-openapi 9.0.18 → 9.1.1
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 +46 -40
- 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 -7
- package/dist/playground/inputs.d.ts.map +1 -1
- package/dist/playground/inputs.js +5 -4
- package/dist/playground/schema.d.ts +5 -0
- package/dist/playground/schema.d.ts.map +1 -1
- package/dist/playground/schema.js +61 -32
- 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/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/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/schema-to-string.d.ts.map +1 -1
- package/dist/utils/schema-to-string.js +30 -35
- package/dist/utils/url.js +10 -12
- package/package.json +3 -3
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,sBAAsB,CAAC;AAExD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACd,MAAM,oBAAoB,CAAC;AAiB5B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAwBzE,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC,MA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zD,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);
|
|
@@ -144,40 +142,48 @@ function SecurityTabs({ securities, setSecurityId, securityId, children, }) {
|
|
|
144
142
|
}
|
|
145
143
|
return result;
|
|
146
144
|
}
|
|
147
|
-
const
|
|
148
|
-
const paramTypes = ['header', 'cookie', 'query', 'path'];
|
|
145
|
+
const ParamTypes = ['path', 'header', 'cookie', 'query'];
|
|
149
146
|
function FormBody({ parameters = [], fields = {}, body, }) {
|
|
150
|
-
const
|
|
151
|
-
return
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
147
|
+
const panels = useMemo(() => {
|
|
148
|
+
return ParamTypes.map((type) => {
|
|
149
|
+
const items = parameters.filter((v) => v.in === type);
|
|
150
|
+
if (items.length === 0)
|
|
151
|
+
return;
|
|
152
|
+
return (_jsx(CollapsiblePanel, { title: {
|
|
153
|
+
header: 'Header',
|
|
154
|
+
cookie: 'Cookies',
|
|
155
|
+
query: 'Query',
|
|
156
|
+
path: 'Path',
|
|
157
|
+
}[type], children: items.map((field) => {
|
|
158
|
+
const fieldName = `${type}.${field.name}`;
|
|
159
|
+
const schema = (field.content
|
|
160
|
+
? field.content[Object.keys(field.content)[0]].schema
|
|
161
|
+
: field.schema);
|
|
162
|
+
if (fields?.parameter) {
|
|
163
|
+
return renderCustomField(fieldName, schema, fields.parameter, field.name);
|
|
164
|
+
}
|
|
165
|
+
return (_jsx(FieldSet, { name: field.name, fieldName: fieldName, field: schema }, fieldName));
|
|
166
|
+
}) }, type));
|
|
167
|
+
});
|
|
168
|
+
}, [fields.parameter, parameters]);
|
|
169
|
+
return (_jsxs(_Fragment, { children: [panels, body && (_jsx(CollapsiblePanel, { title: "Body", children: fields.body ? (renderCustomField('body', body.schema, fields.body)) : (_jsx(BodyInput, { field: body.schema })) }))] }));
|
|
166
170
|
}
|
|
167
171
|
function BodyInput({ field: _field }) {
|
|
168
172
|
const field = useResolvedSchema(_field);
|
|
169
173
|
const [isJson, setIsJson] = useState(false);
|
|
170
174
|
if (field.format === 'binary')
|
|
171
175
|
return _jsx(FieldSet, { field: field, fieldName: "body" });
|
|
172
|
-
|
|
176
|
+
if (isJson)
|
|
177
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { className: cn(buttonVariants({
|
|
173
178
|
color: 'secondary',
|
|
174
179
|
size: 'sm',
|
|
175
180
|
className: 'w-fit font-mono p-2',
|
|
176
|
-
})), onClick: () => setIsJson(false), type: "button", children: "Close JSON Editor" }), _jsx(JsonInput, { fieldName: "body" })] }))
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
})), onClick: () => setIsJson(false), type: "button", children: "Close JSON Editor" }), _jsx(JsonInput, { fieldName: "body" })] }));
|
|
182
|
+
return (_jsx(FieldSet, { field: field, fieldName: "body", collapsible: false, name: _jsx("button", { type: "button", className: cn(buttonVariants({
|
|
183
|
+
color: 'secondary',
|
|
184
|
+
size: 'sm',
|
|
185
|
+
className: 'p-2',
|
|
186
|
+
})), onClick: () => setIsJson(true), children: "Open JSON Editor" }) }));
|
|
181
187
|
}
|
|
182
188
|
/**
|
|
183
189
|
* manipulate values without mutating the original object
|
|
@@ -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,oDAkCpB"}
|
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;
|
|
@@ -16,12 +16,7 @@ export async function APIPlayground({ path, method, ctx, client, }) {
|
|
|
16
16
|
securities: parseSecurities(method, ctx),
|
|
17
17
|
method: method.method,
|
|
18
18
|
route: path,
|
|
19
|
-
parameters: method.parameters
|
|
20
|
-
name: v.name,
|
|
21
|
-
in: v.in,
|
|
22
|
-
schema: writeReferences((v.schema ?? true), context),
|
|
23
|
-
description: v.description,
|
|
24
|
-
})),
|
|
19
|
+
parameters: method.parameters,
|
|
25
20
|
body: bodyContent && mediaType
|
|
26
21
|
? {
|
|
27
22
|
schema: writeReferences(bodyContent[mediaType].schema, context),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EAGf,MAAM,OAAO,CAAC;AAef,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAkDxD,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,KAAK,CAAC,uDAwCxB;AAED,wBAAgB,SAAS,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,2CA8B7D;AA6FD,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,uDA6FA;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,KAAS,EACT,QAAQ,EACR,WAAkB,EAClB,GAAG,KAAK,EACT,EAA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S,EACT,QAAQ,EACR,WAAkB,EAClB,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;IAEf,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,kDA4KA"}
|
|
@@ -119,13 +119,14 @@ export function FieldSet({ field: _field, fieldName, toolbar, name, isRequired,
|
|
|
119
119
|
const { info, updateInfo } = useFieldInfo(fieldName, field, depth);
|
|
120
120
|
if (_field === false)
|
|
121
121
|
return null;
|
|
122
|
-
if (
|
|
123
|
-
const
|
|
124
|
-
|
|
122
|
+
if (info.unionField) {
|
|
123
|
+
const union = field[info.unionField];
|
|
124
|
+
const showSelect = union.length > 1;
|
|
125
|
+
return (_jsx(FieldSet, { ...props, name: name, fieldName: fieldName, isRequired: isRequired, field: union[info.oneOf], depth: depth + 1, slotType: showSelect ? false : slotType, toolbar: _jsxs(_Fragment, { children: [showSelect && (_jsx("select", { className: "text-xs font-mono", value: info.oneOf, onChange: (e) => {
|
|
125
126
|
updateInfo({
|
|
126
127
|
oneOf: Number(e.target.value),
|
|
127
128
|
});
|
|
128
|
-
}, children:
|
|
129
|
+
}, children: union.map((item, i) => (_jsx("option", { value: i, children: schemaToString(item) }, i))) })), toolbar] }) }));
|
|
129
130
|
}
|
|
130
131
|
if (Array.isArray(field.type)) {
|
|
131
132
|
const showSelect = field.type.length > 1;
|
|
@@ -6,9 +6,14 @@ interface SchemaContextType {
|
|
|
6
6
|
fieldInfoMap: Map<string, FieldInfo>;
|
|
7
7
|
ajv: Ajv2020;
|
|
8
8
|
}
|
|
9
|
+
type UnionField = 'anyOf' | 'allOf' | 'oneOf';
|
|
9
10
|
export interface FieldInfo {
|
|
10
11
|
selectedType?: string;
|
|
11
12
|
oneOf: number;
|
|
13
|
+
/**
|
|
14
|
+
* The actual field that represents union members.
|
|
15
|
+
*/
|
|
16
|
+
unionField?: UnionField;
|
|
12
17
|
}
|
|
13
18
|
export declare const anyFields: {
|
|
14
19
|
type: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/playground/schema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAiB,SAAS,EAAiC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/playground/schema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAiB,SAAS,EAAiC,MAAM,OAAO,CAAC;AAMhF,UAAU,iBAAiB;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC1C,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrC,GAAG,EAAE,OAAO,CAAC;CACd;AAED,KAAK,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAE9C,MAAM,WAAW,SAAS;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAGD,eAAO,MAAM,SAAS;;;;CAIG,CAAC;AAE1B,wBAAgB,cAAc,CAAC,EAC7B,UAAU,EACV,YAAY,EACZ,QAAQ,GACT,EAAE,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,GAAG;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAsB1D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,EACvC,KAAK,EAAE,MAAM,GACZ;IACD,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;CACjD,CA8FA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAQjC;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAEjC"}
|
|
@@ -28,50 +28,79 @@ export function SchemaProvider({ references, fieldInfoMap, children, }) {
|
|
|
28
28
|
*/
|
|
29
29
|
export function useFieldInfo(fieldName, schema, depth) {
|
|
30
30
|
const { fieldInfoMap, ajv } = useContext(SchemaContext);
|
|
31
|
-
const [_, trigger] = useState(0);
|
|
32
31
|
const form = useFormContext();
|
|
33
32
|
const keyName = `${fieldName}:${depth}`;
|
|
34
33
|
const value = form.getValues(fieldName);
|
|
35
|
-
const info =
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return ajv.validate(item, value);
|
|
34
|
+
const [info, setInfo] = useState(() => {
|
|
35
|
+
return fieldInfoMap.get(keyName) ?? init();
|
|
36
|
+
});
|
|
37
|
+
fieldInfoMap.set(keyName, info);
|
|
38
|
+
/**
|
|
39
|
+
* We automatically merge `allOf` | `anyOf` if all members are objects, but it's also possible for them to behave same as a union (`oneOf`).
|
|
40
|
+
*/
|
|
41
|
+
function isUnion(anyOrAllOf) {
|
|
42
|
+
return anyOrAllOf.every((item) => {
|
|
43
|
+
if (typeof item === 'boolean')
|
|
44
|
+
return true;
|
|
45
|
+
const u = item.anyOf || item.allOf;
|
|
46
|
+
return item.type !== 'object' && (!u || isUnion(u));
|
|
49
47
|
});
|
|
50
|
-
if (info.oneOf === -1)
|
|
51
|
-
info.oneOf = 0;
|
|
52
48
|
}
|
|
53
|
-
|
|
49
|
+
function getUnion() {
|
|
50
|
+
if (schema.anyOf && isUnion(schema.anyOf)) {
|
|
51
|
+
return [schema.anyOf, 'anyOf'];
|
|
52
|
+
}
|
|
53
|
+
if (schema.allOf && isUnion(schema.allOf)) {
|
|
54
|
+
return [schema.allOf, 'allOf'];
|
|
55
|
+
}
|
|
56
|
+
if (schema.oneOf)
|
|
57
|
+
return [schema.oneOf, 'oneOf'];
|
|
58
|
+
}
|
|
59
|
+
function init() {
|
|
60
|
+
const union = getUnion();
|
|
61
|
+
if (union) {
|
|
62
|
+
const [members, field] = union;
|
|
63
|
+
let oneOf = members.findIndex((item) => ajv.validate(item, value));
|
|
64
|
+
if (oneOf === -1)
|
|
65
|
+
oneOf = 0;
|
|
66
|
+
return {
|
|
67
|
+
oneOf,
|
|
68
|
+
unionField: field,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (Array.isArray(schema.type)) {
|
|
72
|
+
const types = schema.type;
|
|
73
|
+
return {
|
|
74
|
+
selectedType: types.find((type) => {
|
|
75
|
+
schema.type = type;
|
|
76
|
+
const match = ajv.validate(schema, value);
|
|
77
|
+
schema.type = types;
|
|
78
|
+
return match;
|
|
79
|
+
}) ?? types[0],
|
|
80
|
+
oneOf: -1,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return { oneOf: -1 };
|
|
84
|
+
}
|
|
54
85
|
return {
|
|
55
86
|
info,
|
|
56
87
|
updateInfo: useEffectEvent((value) => {
|
|
57
|
-
const prev = fieldInfoMap.get(keyName);
|
|
58
|
-
if (!prev)
|
|
59
|
-
return;
|
|
60
88
|
const updated = {
|
|
61
|
-
...
|
|
89
|
+
...info,
|
|
62
90
|
...value,
|
|
63
91
|
};
|
|
64
|
-
if (updated.oneOf ===
|
|
65
|
-
updated.selectedType ===
|
|
92
|
+
if (updated.oneOf === info.oneOf &&
|
|
93
|
+
updated.selectedType === info.selectedType)
|
|
66
94
|
return;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
95
|
+
setInfo(updated);
|
|
96
|
+
let valueSchema = schema;
|
|
97
|
+
if (updated.unionField) {
|
|
98
|
+
valueSchema = schema[updated.unionField][updated.oneOf];
|
|
99
|
+
}
|
|
100
|
+
else if (updated.selectedType) {
|
|
101
|
+
valueSchema = { ...schema, type: updated.selectedType };
|
|
102
|
+
}
|
|
103
|
+
form.setValue(fieldName, getDefaultValue(valueSchema));
|
|
75
104
|
}),
|
|
76
105
|
};
|
|
77
106
|
}
|
|
@@ -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,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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,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[];
|