fumadocs-openapi 9.0.18 → 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/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/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"],"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H,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,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,O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C1C,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,CAA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B,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,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,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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,15 +1,31 @@
|
|
|
1
1
|
import type { MediaAdapter } from '../media/adapter.js';
|
|
2
|
+
import type { NoReference } from '../utils/schema.js';
|
|
3
|
+
import type { ParameterObject } from '../types.js';
|
|
2
4
|
export type SampleGenerator = (url: string, data: RequestData, context: {
|
|
3
5
|
mediaAdapters: Record<string, MediaAdapter>;
|
|
4
6
|
}) => string;
|
|
7
|
+
export interface RawRequestData {
|
|
8
|
+
method: string;
|
|
9
|
+
path: Record<string, unknown>;
|
|
10
|
+
query: Record<string, unknown>;
|
|
11
|
+
header: Record<string, unknown>;
|
|
12
|
+
cookie: Record<string, unknown>;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
bodyMediaType?: string;
|
|
15
|
+
}
|
|
16
|
+
interface EncodedParameter {
|
|
17
|
+
readonly value: string | string[];
|
|
18
|
+
}
|
|
5
19
|
export interface RequestData {
|
|
6
20
|
method: string;
|
|
7
|
-
path: Record<string,
|
|
8
|
-
query: Record<string,
|
|
9
|
-
header: Record<string,
|
|
10
|
-
cookie: Record<string,
|
|
21
|
+
path: Record<string, EncodedParameter>;
|
|
22
|
+
query: Record<string, EncodedParameter>;
|
|
23
|
+
header: Record<string, EncodedParameter>;
|
|
24
|
+
cookie: Record<string, EncodedParameter>;
|
|
11
25
|
body?: unknown;
|
|
12
26
|
bodyMediaType?: string;
|
|
13
27
|
}
|
|
14
28
|
export declare function ident(code: string, tab?: number): string;
|
|
29
|
+
export declare function encodeRequestData(from: RawRequestData, adapters: Record<string, MediaAdapter>, parameters: NoReference<ParameterObject>[]): RequestData;
|
|
30
|
+
export {};
|
|
15
31
|
//# sourceMappingURL=_shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../src/requests/_shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"_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,MAAM,CAAC;CACxB;AAYD,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAU,UAKlD;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EACtC,UAAU,EAAE,WAAW,CAAC,eAAe,CAAC,EAAE,GACzC,WAAW,CAsIb"}
|
package/dist/requests/_shared.js
CHANGED
|
@@ -1,6 +1,119 @@
|
|
|
1
|
+
const FormDelimiter = {
|
|
2
|
+
spaceDelimited: ' ',
|
|
3
|
+
pipeDelimited: '|',
|
|
4
|
+
};
|
|
5
|
+
const PathPrefix = {
|
|
6
|
+
label: '.',
|
|
7
|
+
matrix: ';',
|
|
8
|
+
};
|
|
1
9
|
export function ident(code, tab = 1) {
|
|
2
10
|
return code
|
|
3
11
|
.split('\n')
|
|
4
12
|
.map((v) => ' '.repeat(tab) + v)
|
|
5
13
|
.join('\n');
|
|
6
14
|
}
|
|
15
|
+
export function encodeRequestData(from, adapters, parameters) {
|
|
16
|
+
function getMediaEncoder(field) {
|
|
17
|
+
if (!field.content)
|
|
18
|
+
return;
|
|
19
|
+
for (const k in field.content) {
|
|
20
|
+
if (k in adapters) {
|
|
21
|
+
return (v) => String(adapters[k].encode({ body: v }));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function writeObject(parentKey, value, deep, output) {
|
|
26
|
+
for (const k in value) {
|
|
27
|
+
const prop = value[k];
|
|
28
|
+
if (prop == null)
|
|
29
|
+
continue;
|
|
30
|
+
const key = deep ? `${parentKey}[${k}]` : k;
|
|
31
|
+
if (!deep || typeof prop !== 'object') {
|
|
32
|
+
output[key] = {
|
|
33
|
+
value: String(prop),
|
|
34
|
+
};
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
writeObject(key, value, deep, output);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function write(key, value, field, output = {}) {
|
|
41
|
+
const encoder = getMediaEncoder(field);
|
|
42
|
+
if (encoder) {
|
|
43
|
+
output[key] = { value: encoder(value) };
|
|
44
|
+
return output;
|
|
45
|
+
}
|
|
46
|
+
const explode = field.explode ?? true;
|
|
47
|
+
let prefix = '';
|
|
48
|
+
let sep = ',';
|
|
49
|
+
if (field.in === 'path') {
|
|
50
|
+
const style = field.style ?? 'simple';
|
|
51
|
+
if (style in PathPrefix) {
|
|
52
|
+
prefix = PathPrefix[style];
|
|
53
|
+
if (explode)
|
|
54
|
+
sep = prefix;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
// header & cookie doesn't support explode for array values
|
|
59
|
+
if (explode && field.in !== 'header' && field.in !== 'cookie') {
|
|
60
|
+
output[key] = {
|
|
61
|
+
value: prefix + value.map(String),
|
|
62
|
+
};
|
|
63
|
+
return output;
|
|
64
|
+
}
|
|
65
|
+
if (field.in === 'query') {
|
|
66
|
+
const style = field.style ?? 'form';
|
|
67
|
+
if (style in FormDelimiter)
|
|
68
|
+
sep = FormDelimiter[style];
|
|
69
|
+
}
|
|
70
|
+
output[key] = {
|
|
71
|
+
value: prefix + value.map(String).join(sep),
|
|
72
|
+
};
|
|
73
|
+
return output;
|
|
74
|
+
}
|
|
75
|
+
if (typeof value === 'object' && value) {
|
|
76
|
+
// header & path creates key-value pairs
|
|
77
|
+
if (explode && (field.in === 'header' || field.in === 'path')) {
|
|
78
|
+
output[key] = {
|
|
79
|
+
value: prefix +
|
|
80
|
+
Object.entries(value)
|
|
81
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
82
|
+
.join(sep),
|
|
83
|
+
};
|
|
84
|
+
return output;
|
|
85
|
+
}
|
|
86
|
+
if (explode || field.style === 'deepObject') {
|
|
87
|
+
writeObject(key, value, field.style === 'deepObject', output);
|
|
88
|
+
return output;
|
|
89
|
+
}
|
|
90
|
+
output[key] = {
|
|
91
|
+
value: prefix + Object.entries(value).flat().join(sep),
|
|
92
|
+
};
|
|
93
|
+
return output;
|
|
94
|
+
}
|
|
95
|
+
output[key] = {
|
|
96
|
+
value: prefix + String(value),
|
|
97
|
+
};
|
|
98
|
+
return output;
|
|
99
|
+
}
|
|
100
|
+
const result = {
|
|
101
|
+
method: from.method,
|
|
102
|
+
body: from.body,
|
|
103
|
+
bodyMediaType: from.bodyMediaType,
|
|
104
|
+
};
|
|
105
|
+
for (const type of ['cookie', 'query', 'header', 'path']) {
|
|
106
|
+
const out = {};
|
|
107
|
+
for (const k in from[type]) {
|
|
108
|
+
const value = from[type][k];
|
|
109
|
+
if (value == null)
|
|
110
|
+
continue;
|
|
111
|
+
const field = parameters.find((p) => p.name === k && p.in === type);
|
|
112
|
+
if (!field)
|
|
113
|
+
continue;
|
|
114
|
+
write(k, value, field, out);
|
|
115
|
+
}
|
|
116
|
+
result[type] = out;
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csharp.d.ts","sourceRoot":"","sources":["../../src/requests/csharp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"csharp.d.ts","sourceRoot":"","sources":["../../src/requests/csharp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,eAAO,MAAM,SAAS,EAAE,eAkEvB,CAAC"}
|
package/dist/requests/csharp.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { resolveRequestData } from '../utils/url.js';
|
|
3
2
|
export const generator = (url, data, { mediaAdapters }) => {
|
|
4
3
|
const s = [];
|
|
5
4
|
const imports = new Set(['System', 'System.Net.Http', 'System.Text']);
|
|
@@ -22,23 +21,28 @@ export const generator = (url, data, { mediaAdapters }) => {
|
|
|
22
21
|
s.push(body, '');
|
|
23
22
|
}
|
|
24
23
|
s.push('var client = new HttpClient();');
|
|
24
|
+
const headerLines = [];
|
|
25
|
+
function addHeader(key, value) {
|
|
26
|
+
headerLines.push(`client.DefaultRequestHeaders.Add("${key}", ${JSON.stringify(value)});`);
|
|
27
|
+
}
|
|
28
|
+
for (const k in headers) {
|
|
29
|
+
addHeader(k, headers[k].value);
|
|
30
|
+
}
|
|
25
31
|
// Add cookie header if cookies are present
|
|
26
32
|
if (Object.keys(data.cookie).length > 0) {
|
|
27
|
-
|
|
28
|
-
.map(([key,
|
|
33
|
+
const cookie = Object.entries(data.cookie)
|
|
34
|
+
.map(([key, param]) => `${key}=${param.value}`)
|
|
29
35
|
.join('; ');
|
|
36
|
+
addHeader('cookie', cookie);
|
|
30
37
|
}
|
|
31
|
-
// Add headers
|
|
32
|
-
const headerLines = Object.entries(headers).map(([key, value]) => `client.DefaultRequestHeaders.Add("${key}", ${JSON.stringify(value)});`);
|
|
33
38
|
s.push(...headerLines);
|
|
34
39
|
// Build the request
|
|
35
|
-
const resolvedUrl = resolveRequestData(url, data);
|
|
36
40
|
const method = data.method[0].toUpperCase() + data.method.slice(1).toLowerCase() + 'Async';
|
|
37
41
|
if (body) {
|
|
38
|
-
s.push(`var response = await client.${method}("${
|
|
42
|
+
s.push(`var response = await client.${method}("${url}", body);`);
|
|
39
43
|
}
|
|
40
44
|
else {
|
|
41
|
-
s.push(`var response = await client.${method}("${
|
|
45
|
+
s.push(`var response = await client.${method}("${url}");`);
|
|
42
46
|
}
|
|
43
47
|
// Add response handling
|
|
44
48
|
s.push('var responseBody = await response.Content.ReadAsStringAsync();');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEjE,eAAO,MAAM,SAAS,EAAE,eAsCvB,CAAC"}
|
package/dist/requests/curl.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { escapeString, inputToString } from '../utils/input-to-string.js';
|
|
3
3
|
import { ident } from '../requests/_shared.js';
|
|
4
|
-
import { resolveRequestData } from '../utils/url.js';
|
|
5
4
|
export const generator = (url, data) => {
|
|
6
5
|
const s = [];
|
|
7
|
-
s.push(`curl -X ${data.method} "${
|
|
6
|
+
s.push(`curl -X ${data.method} "${url}"`);
|
|
8
7
|
for (const header in data.header) {
|
|
9
|
-
const value = `${header}: ${data.header[header]}`;
|
|
8
|
+
const value = `${header}: ${data.header[header].value}`;
|
|
10
9
|
s.push(`-H "${value}"`);
|
|
11
10
|
}
|
|
12
|
-
for (const
|
|
13
|
-
const
|
|
14
|
-
s.push(`--cookie ${value}`);
|
|
11
|
+
for (const k in data.cookie) {
|
|
12
|
+
const param = data.cookie[k];
|
|
13
|
+
s.push(`--cookie ${JSON.stringify(`${k}=${param.value}`)}`);
|
|
15
14
|
}
|
|
16
15
|
if (data.body && data.bodyMediaType === 'multipart/form-data') {
|
|
17
16
|
if (typeof data.body !== 'object')
|
package/dist/requests/go.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/requests/go.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/requests/go.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEjE,eAAO,MAAM,SAAS,EAAE,eA2DvB,CAAC"}
|
package/dist/requests/go.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { ident } from '../requests/_shared.js';
|
|
3
|
-
import { resolveRequestData } from '../utils/url.js';
|
|
4
3
|
export const generator = (url, data, { mediaAdapters }) => {
|
|
5
4
|
const imports = ['fmt', 'net/http', 'io/ioutil'];
|
|
6
5
|
const headers = new Map();
|
|
7
6
|
const variables = new Map();
|
|
8
|
-
variables.set('url', JSON.stringify(
|
|
7
|
+
variables.set('url', JSON.stringify(url));
|
|
9
8
|
for (const header in data.header) {
|
|
10
|
-
headers.set(header, JSON.stringify(data.header[header]));
|
|
9
|
+
headers.set(header, JSON.stringify(data.header[header].value));
|
|
10
|
+
}
|
|
11
|
+
const cookies = Object.entries(data.cookie);
|
|
12
|
+
if (cookies.length > 0) {
|
|
13
|
+
headers.set('Cookie', JSON.stringify(cookies.map(([k, param]) => `${k}=${param.value}`).join('; ')));
|
|
11
14
|
}
|
|
12
|
-
const cookies = Object.keys(data.cookie);
|
|
13
|
-
if (cookies.length > 0)
|
|
14
|
-
headers.set('Cookie', JSON.stringify(cookies.map((p) => `${p}=${data.cookie[p]}`).join('; ')));
|
|
15
15
|
let body;
|
|
16
16
|
if (data.body && data.bodyMediaType && data.bodyMediaType in mediaAdapters) {
|
|
17
17
|
headers.set('Content-Type', `"${data.bodyMediaType}"`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"java.d.ts","sourceRoot":"","sources":["../../src/requests/java.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"java.d.ts","sourceRoot":"","sources":["../../src/requests/java.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEjE,eAAO,MAAM,SAAS,EAAE,eAqFvB,CAAC"}
|
package/dist/requests/java.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { ident } from '../requests/_shared.js';
|
|
3
|
-
import { resolveRequestData } from '../utils/url.js';
|
|
4
3
|
export const generator = (url, data, { mediaAdapters }) => {
|
|
5
4
|
const s = [];
|
|
6
5
|
const headers = { ...data.header };
|
|
@@ -37,19 +36,20 @@ export const generator = (url, data, { mediaAdapters }) => {
|
|
|
37
36
|
s.push('');
|
|
38
37
|
// Build request
|
|
39
38
|
s.push('HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()');
|
|
40
|
-
s.push(ident(`.uri(URI.create(${JSON.stringify(
|
|
39
|
+
s.push(ident(`.uri(URI.create(${JSON.stringify(url)}))`));
|
|
41
40
|
// Add headers
|
|
42
|
-
for (const [key,
|
|
43
|
-
s.push(ident(`.header(${JSON.stringify(key)}, ${JSON.stringify(value)})`));
|
|
41
|
+
for (const [key, param] of Object.entries(headers)) {
|
|
42
|
+
s.push(ident(`.header(${JSON.stringify(key)}, ${JSON.stringify(param.value)})`));
|
|
44
43
|
}
|
|
45
44
|
if (data.bodyMediaType) {
|
|
46
45
|
s.push(ident(`.header("Content-Type", "${data.bodyMediaType}")`));
|
|
47
46
|
}
|
|
48
47
|
// Add cookies if present
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
const cookies = Object.entries(data.cookie);
|
|
49
|
+
if (cookies.length > 0) {
|
|
50
|
+
const cookieString = cookies
|
|
51
|
+
.map(([key, param]) => `${key}=${param.value}`)
|
|
52
|
+
.join('; ');
|
|
53
53
|
s.push(ident(`.header("Cookie", ${JSON.stringify(cookieString)})`));
|
|
54
54
|
}
|
|
55
55
|
const arg = body ? 'body' : '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/requests/javascript.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/requests/javascript.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEjE,eAAO,MAAM,SAAS,EAAE,eAkDvB,CAAC"}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { ident } from '../requests/_shared.js';
|
|
3
|
-
import { resolveRequestData } from '../utils/url.js';
|
|
4
3
|
export const generator = (url, data, { mediaAdapters }) => {
|
|
5
4
|
const s = [];
|
|
6
5
|
const options = new Map();
|
|
7
|
-
const headers = {
|
|
8
|
-
|
|
9
|
-
headers[
|
|
10
|
-
|
|
6
|
+
const headers = {};
|
|
7
|
+
for (const [k, v] of Object.entries(data.header)) {
|
|
8
|
+
headers[k] = v.value;
|
|
9
|
+
}
|
|
10
|
+
const cookies = Object.entries(data.cookie);
|
|
11
|
+
if (cookies.length > 0) {
|
|
12
|
+
headers['cookie'] = cookies
|
|
13
|
+
.map(([key, param]) => `${key}=${param.value}`)
|
|
11
14
|
.join('; ');
|
|
12
15
|
}
|
|
13
16
|
if (Object.keys(headers).length > 0) {
|
|
@@ -26,7 +29,7 @@ export const generator = (url, data, { mediaAdapters }) => {
|
|
|
26
29
|
s.push(body);
|
|
27
30
|
options.set('body', 'body');
|
|
28
31
|
}
|
|
29
|
-
const params = [JSON.stringify(
|
|
32
|
+
const params = [JSON.stringify(url)];
|
|
30
33
|
if (options.size > 0) {
|
|
31
34
|
const str = Array.from(options.entries())
|
|
32
35
|
.map(([k, v]) => ident(k === v ? k : `${k}: ${v}`))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/requests/python.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/requests/python.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,eAAO,MAAM,SAAS,EAAE,eAgDvB,CAAC"}
|
package/dist/requests/python.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { resolveRequestData } from '../utils/url.js';
|
|
3
2
|
export const generator = (url, data, { mediaAdapters }) => {
|
|
4
|
-
const headers = {
|
|
3
|
+
const headers = {};
|
|
5
4
|
const params = [`"${data.method}"`, 'url'];
|
|
6
5
|
let body;
|
|
7
6
|
if (data.body && data.bodyMediaType && data.bodyMediaType in mediaAdapters) {
|
|
@@ -16,15 +15,23 @@ export const generator = (url, data, { mediaAdapters }) => {
|
|
|
16
15
|
params.push('data = body');
|
|
17
16
|
}
|
|
18
17
|
}
|
|
18
|
+
for (const [k, v] of Object.entries(data.header)) {
|
|
19
|
+
headers[k] = v.value;
|
|
20
|
+
}
|
|
19
21
|
if (Object.keys(headers).length > 0) {
|
|
20
22
|
params.push(`headers = ${JSON.stringify(headers, null, 2)}`);
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
const inputCookies = Object.entries(data.cookie);
|
|
25
|
+
if (inputCookies.length > 0) {
|
|
26
|
+
const cookies = {};
|
|
27
|
+
for (const [k, v] of inputCookies) {
|
|
28
|
+
cookies[k] = v.value;
|
|
29
|
+
}
|
|
30
|
+
params.push(`cookies = ${JSON.stringify(cookies, null, 2)}`);
|
|
24
31
|
}
|
|
25
32
|
return `import requests
|
|
26
33
|
|
|
27
|
-
url = ${JSON.stringify(
|
|
34
|
+
url = ${JSON.stringify(url)}
|
|
28
35
|
${body ?? ''}
|
|
29
36
|
response = requests.request(${params.join(', ')})
|
|
30
37
|
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,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OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,iBAAiB,CAAC;IAE1B;;;;;;;OAOG;IACH,wBAAwB,CAAC,EACrB,CAAC,CACC,MAAM,EAAE,WAAW,CAAC,iBAAiB,CAAC,EACtC,UAAU,EAAE,MAAM,KACf,SAAS,CAAC,MAAM,CAAC,CAAC,GACvB,KAAK,CAAC;IAEV;;OAEG;IACH,mBAAmB,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC;IAE7E,YAAY,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC,GAClD,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAElC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC7C"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { RenderContext, ServerObject } from '../../types.js';
|
|
3
3
|
import { type MediaAdapter } from '../../media/adapter.js';
|
|
4
|
-
export interface ApiProviderProps extends ApiContextType {
|
|
4
|
+
export interface ApiProviderProps extends Omit<ApiContextType, 'mediaAdapters'> {
|
|
5
5
|
/**
|
|
6
6
|
* Base URL for API requests
|
|
7
7
|
*/
|
|
8
8
|
defaultBaseUrl?: string;
|
|
9
9
|
children?: ReactNode;
|
|
10
|
+
mediaAdapters?: Record<string, MediaAdapter>;
|
|
10
11
|
}
|
|
11
12
|
export interface SelectedServer {
|
|
12
13
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/api.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3D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,YAAY,GACb,EAAE,gBAAgB,2CA2ElB"}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { CodeSample } from '../../render/operation/index.js';
|
|
3
3
|
import type { SamplesProps } from '../../render/renderer.js';
|
|
4
|
-
import type { RequestData } from '../../requests/_shared.js';
|
|
4
|
+
import type { RawRequestData, RequestData } from '../../requests/_shared.js';
|
|
5
5
|
export declare function CodeExampleProvider({ route, examples, initialKey, children, }: {
|
|
6
6
|
route: string;
|
|
7
7
|
examples: {
|
|
8
8
|
key: string;
|
|
9
|
-
data:
|
|
9
|
+
data: RawRequestData;
|
|
10
|
+
encoded: RequestData;
|
|
10
11
|
}[];
|
|
11
12
|
initialKey?: string;
|
|
12
13
|
children: ReactNode;
|
|
13
14
|
}): import("react/jsx-runtime").JSX.Element;
|
|
14
15
|
export declare function CodeExample(props: CodeSample): import("react/jsx-runtime").JSX.Element | null;
|
|
15
16
|
export declare function CodeExampleSelector({ items }: SamplesProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
-
export declare function useRequestInitialData():
|
|
17
|
+
export declare function useRequestInitialData(): RawRequestData;
|
|
17
18
|
export declare function useRequestDataUpdater(): {
|
|
18
|
-
setData: (data: RequestData) => void;
|
|
19
|
+
setData: (data: RawRequestData, encoded: RequestData) => void;
|
|
19
20
|
};
|
|
20
21
|
//# sourceMappingURL=code-example.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-example.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"code-example.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAetD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAsBtE,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,cAAc,CAAC;QACrB,OAAO,EAAE,WAAW,CAAC;KACtB,EAAE,CAAC;IACJ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;CACrB,2CA6DA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,kDAgD5C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,2CAoB1D;AAgBD,wBAAgB,qBAAqB,mBAOpC;AAED,wBAAgB,qBAAqB;oBAlLnB,cAAc,WAAW,WAAW,KAAK,IAAI;EAqL9D"}
|
|
@@ -5,36 +5,39 @@ import { useApiContext, useServerSelectContext } from '../../ui/contexts/api.js'
|
|
|
5
5
|
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
|
6
6
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../../ui/components/select.js';
|
|
7
7
|
import { useEffectEvent } from 'fumadocs-core/utils/use-effect-event';
|
|
8
|
-
import { joinURL, resolveServerUrl, withBase } from '../../utils/url.js';
|
|
8
|
+
import { joinURL, resolveRequestData, resolveServerUrl, withBase, } from '../../utils/url.js';
|
|
9
9
|
import { defaultSamples } from '../../requests/index.js';
|
|
10
10
|
const CodeExampleContext = createContext(null);
|
|
11
11
|
export function CodeExampleProvider({ route, examples, initialKey, children, }) {
|
|
12
12
|
const [key, setKey] = useState(initialKey ?? examples[0].key);
|
|
13
13
|
const listeners = useRef([]);
|
|
14
|
-
const setData = useEffectEvent((
|
|
14
|
+
const setData = useEffectEvent((data, encoded) => {
|
|
15
15
|
for (const example of examples) {
|
|
16
16
|
if (example.key === key) {
|
|
17
17
|
// persistent changes
|
|
18
|
-
example.data =
|
|
18
|
+
example.data = data;
|
|
19
|
+
example.encoded = encoded;
|
|
20
|
+
break;
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
for (const listener of listeners.current) {
|
|
22
|
-
listener(
|
|
24
|
+
listener(data, encoded);
|
|
23
25
|
}
|
|
24
26
|
});
|
|
25
27
|
const updateKey = useEffectEvent((newKey) => {
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
+
const example = examples.find((example) => example.key === newKey);
|
|
29
|
+
if (!example)
|
|
28
30
|
return;
|
|
29
31
|
setKey(newKey);
|
|
30
32
|
for (const listener of listeners.current) {
|
|
31
|
-
listener(data);
|
|
33
|
+
listener(example.data, example.encoded);
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
36
|
const addListener = useEffectEvent((listener) => {
|
|
35
37
|
// initial call to listeners to ensure their data is the latest
|
|
36
38
|
// this is necessary to avoid race conditions between `useEffect()`
|
|
37
|
-
|
|
39
|
+
const example = examples.find((example) => example.key === key);
|
|
40
|
+
listener(example.data, example.encoded);
|
|
38
41
|
listeners.current.push(listener);
|
|
39
42
|
});
|
|
40
43
|
const removeListener = useEffectEvent((listener) => {
|
|
@@ -55,13 +58,13 @@ export function CodeExample(props) {
|
|
|
55
58
|
const { examples, key, route, addListener, removeListener } = useContext(CodeExampleContext);
|
|
56
59
|
const { server } = useServerSelectContext();
|
|
57
60
|
const [data, setData] = useState(() => {
|
|
58
|
-
return examples.find((example) => example.key === key).
|
|
61
|
+
return examples.find((example) => example.key === key).encoded;
|
|
59
62
|
});
|
|
60
63
|
const sample = props.source
|
|
61
64
|
? props
|
|
62
65
|
: defaultSamples.find((item) => item.label === props.label);
|
|
63
66
|
useEffect(() => {
|
|
64
|
-
const listener = setData;
|
|
67
|
+
const listener = (_, encoded) => setData(encoded);
|
|
65
68
|
addListener(listener);
|
|
66
69
|
return () => {
|
|
67
70
|
removeListener(listener);
|
|
@@ -74,7 +77,7 @@ export function CodeExample(props) {
|
|
|
74
77
|
return sample.source;
|
|
75
78
|
return sample.source(joinURL(withBase(server ? resolveServerUrl(server.url, server.variables) : '/', typeof window !== 'undefined'
|
|
76
79
|
? window.location.origin
|
|
77
|
-
: 'https://loading'), route), data, {
|
|
80
|
+
: 'https://loading'), resolveRequestData(route, data)), data, {
|
|
78
81
|
mediaAdapters,
|
|
79
82
|
});
|
|
80
83
|
}, [mediaAdapters, sample, server, route, data]);
|
package/dist/ui/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAYlE,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,SAAS,EACT,GAAG,EACH,GAAG,KAAK,EACT,EAAE,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAYlE,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,SAAS,EACT,GAAG,EACH,GAAG,KAAK,EACT,EAAE,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC,2CAmB5C;AAED,wBAAgB,OAAO,CAAC,EACtB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,2CAMhC;AAED,wBAAgB,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,CAAC,cAAc,CAAC,2CAmBzE;AAED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,MAAM,EACN,GAAG,KAAK,EACT,EAAE,aAAa,2CA+Bf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,2CAY/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAiBA;AAED,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/ui/index.js
CHANGED
|
@@ -6,7 +6,13 @@ import { ApiProvider } from '../ui/lazy.js';
|
|
|
6
6
|
import { cn } from 'fumadocs-ui/utils/cn';
|
|
7
7
|
import { buttonVariants } from 'fumadocs-ui/components/ui/button';
|
|
8
8
|
export function Root({ children, className, ctx, ...props }) {
|
|
9
|
-
|
|
9
|
+
const mediaAdapters = {};
|
|
10
|
+
for (const k in ctx.mediaAdapters) {
|
|
11
|
+
const adapter = ctx.mediaAdapters[k];
|
|
12
|
+
if (adapter.client)
|
|
13
|
+
mediaAdapters[k] = adapter.client;
|
|
14
|
+
}
|
|
15
|
+
return (_jsx("div", { className: cn('flex flex-col gap-24 text-sm', className), ...props, children: _jsx(ApiProvider, { mediaAdapters: mediaAdapters, servers: ctx.servers, shikiOptions: ctx.shikiOptions, children: children }) }));
|
|
10
16
|
}
|
|
11
17
|
export function APIInfo({ className, ...props }) {
|
|
12
18
|
return (_jsx("div", { className: cn('min-w-0 flex-1', className), ...props, children: props.children }));
|
|
@@ -26,6 +32,6 @@ export function APIExample(props) {
|
|
|
26
32
|
return (_jsx("div", { ...props, className: cn('prose-no-margin md:sticky md:top-(--fd-api-info-top) xl:w-[400px]', props.className), children: props.children }));
|
|
27
33
|
}
|
|
28
34
|
export function ObjectCollapsible(props) {
|
|
29
|
-
return (_jsxs(Collapsible, { ...props, children: [_jsxs(CollapsibleTrigger, { className: cn(buttonVariants({ color: 'secondary', size: 'sm' }), 'group px-3 py-2 data-[state=open]:rounded-b-none'), children: [props.name, _jsx(ChevronDown, { className: "size-4 text-fd-muted-foreground group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { className: "-mt-px *:bg-fd-card", children: props.children })] }));
|
|
35
|
+
return (_jsxs(Collapsible, { className: "my-2", ...props, children: [_jsxs(CollapsibleTrigger, { className: cn(buttonVariants({ color: 'secondary', size: 'sm' }), 'group px-3 py-2 data-[state=open]:rounded-b-none'), children: [props.name, _jsx(ChevronDown, { className: "size-4 text-fd-muted-foreground group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { className: "-mt-px *:bg-fd-card", children: props.children })] }));
|
|
30
36
|
}
|
|
31
37
|
export { APIPage } from '../render/api-page.js';
|
package/dist/ui/lazy.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export declare const CodeExampleProvider: import("react").ComponentType<{
|
|
|
2
2
|
route: string;
|
|
3
3
|
examples: {
|
|
4
4
|
key: string;
|
|
5
|
-
data: import("../requests/_shared.js").
|
|
5
|
+
data: import("../requests/_shared.js").RawRequestData;
|
|
6
|
+
encoded: import("../requests/_shared.js").RequestData;
|
|
6
7
|
}[];
|
|
7
8
|
initialKey?: string;
|
|
8
9
|
children: import("react").ReactNode;
|
package/dist/ui/lazy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../src/ui/lazy.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB
|
|
1
|
+
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../src/ui/lazy.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB;;;;;;;;;EAE/B,CAAC;AACF,eAAO,MAAM,WAAW,yEAEvB,CAAC;AACF,eAAO,MAAM,mBAAmB,0EAE/B,CAAC;AAEF,eAAO,MAAM,UAAU,0EAA+C,CAAC;AAEvE,eAAO,MAAM,WAAW,0EAEvB,CAAC"}
|
package/dist/utils/url.js
CHANGED
|
@@ -26,26 +26,24 @@ export function resolveServerUrl(template, variables) {
|
|
|
26
26
|
}
|
|
27
27
|
export function resolveRequestData(pathname, { path, query }) {
|
|
28
28
|
for (const key in path) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
pathname = pathname.replace(`{${key}}`, path[key].join('/'));
|
|
29
|
+
const param = path[key];
|
|
30
|
+
if (Array.isArray(param.value)) {
|
|
31
|
+
pathname = pathname.replace(`{${key}}`, param.value.join('/'));
|
|
33
32
|
}
|
|
34
33
|
else {
|
|
35
|
-
pathname = pathname.replace(`{${key}}`,
|
|
34
|
+
pathname = pathname.replace(`{${key}}`, param.value);
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
const searchParams = new URLSearchParams();
|
|
39
38
|
for (const key in query) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
searchParams.append(key, String(value));
|
|
39
|
+
const param = query[key];
|
|
40
|
+
if (Array.isArray(param.value)) {
|
|
41
|
+
for (const item of param.value) {
|
|
42
|
+
searchParams.append(key, item);
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
|
-
else
|
|
48
|
-
searchParams.
|
|
45
|
+
else {
|
|
46
|
+
searchParams.append(key, param.value);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
return searchParams.size > 0 ? `${pathname}?${searchParams}` : pathname;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"shiki": "^3.7.0",
|
|
65
65
|
"tinyglobby": "^0.2.14",
|
|
66
66
|
"xml-js": "^1.6.11",
|
|
67
|
-
"fumadocs-core": "15.6.
|
|
68
|
-
"fumadocs-ui": "15.6.
|
|
67
|
+
"fumadocs-core": "15.6.2",
|
|
68
|
+
"fumadocs-ui": "15.6.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@scalar/api-client-react": "^1.3.18",
|