fumadocs-openapi 9.3.13 → 9.4.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/playground/client.d.ts +5 -1
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +4 -4
- package/dist/playground/fetcher.d.ts +1 -1
- package/dist/playground/fetcher.d.ts.map +1 -1
- package/dist/playground/fetcher.js +2 -2
- package/dist/server/source-api.d.ts +1 -1
- package/dist/server/source-api.d.ts.map +1 -1
- package/dist/ui/contexts/code-example.d.ts.map +1 -1
- package/dist/ui/contexts/code-example.js +42 -45
- package/package.json +8 -8
|
@@ -36,6 +36,10 @@ export interface ClientProps extends HTMLAttributes<HTMLFormElement> {
|
|
|
36
36
|
*/
|
|
37
37
|
references: Record<string, RequestSchema>;
|
|
38
38
|
proxyUrl?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Request timeout in seconds (default: 10s)
|
|
41
|
+
*/
|
|
42
|
+
requestTimeout?: number;
|
|
39
43
|
fields?: {
|
|
40
44
|
parameter?: CustomField<`${ParameterField['in']}.${string}`, ParameterField>;
|
|
41
45
|
auth?: CustomField<FieldPath<FormValues>, RequestSchema>;
|
|
@@ -47,6 +51,6 @@ export interface ClientProps extends HTMLAttributes<HTMLFormElement> {
|
|
|
47
51
|
}>;
|
|
48
52
|
}>;
|
|
49
53
|
}
|
|
50
|
-
export default function Client({ route, method, securities, parameters, body, fields, references, proxyUrl, components: { ResultDisplay }, ...rest }: ClientProps): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
export default function Client({ route, method, securities, parameters, body, fields, references, proxyUrl, components: { ResultDisplay }, requestTimeout, ...rest }: ClientProps): import("react/jsx-runtime").JSX.Element;
|
|
51
55
|
export {};
|
|
52
56
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/playground/client.tsx"],"names":[],"mappings":"AACA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ACP,SAAS,CAAC,EAAE,WAAW,CACrB,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,MAAM,EAAE,EACnC,cAAc,CACf,CAAC;QACF,IAAI,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,CAAC;QACzD,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;KAC3C,CAAC;IAEF,UAAU,CAAC,EAAE,OAAO,CAAC;QACnB,aAAa,EAAE,EAAE,CAAC;YAAE,IAAI,EAAE,WAAW,CAAA;SAAE,CAAC,CAAC;KAC1C,CAAC,CAAC;CACJ;AAgBD,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAC7B,KAAK,EACL,MAAc,EACd,UAAU,EACV,UAAe,EACf,IAAI,EACJ,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EAAE,EAAE,aAAoC,EAAO,EACzD,cAAmB,EACnB,GAAG,IAAI,EACR,EAAE,WAAW,2CAyLb"}
|
|
@@ -28,7 +28,7 @@ const OauthDialog = lazy(() => import('./auth/oauth-dialog.js').then((mod) => ({
|
|
|
28
28
|
const OauthDialogTrigger = lazy(() => import('./auth/oauth-dialog.js').then((mod) => ({
|
|
29
29
|
default: mod.OauthDialogTrigger,
|
|
30
30
|
})));
|
|
31
|
-
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 } = {}, requestTimeout = 10, ...rest }) {
|
|
32
32
|
const { server } = useServerSelectContext();
|
|
33
33
|
const requestData = useRequestInitialData();
|
|
34
34
|
const updater = useRequestDataUpdater();
|
|
@@ -47,7 +47,7 @@ export default function Client({ route, method = 'GET', securities, parameters =
|
|
|
47
47
|
defaultValues,
|
|
48
48
|
});
|
|
49
49
|
const testQuery = useQuery(async (input) => {
|
|
50
|
-
const fetcher = await import('./fetcher.js').then((mod) => mod.createBrowserFetcher(mediaAdapters));
|
|
50
|
+
const fetcher = await import('./fetcher.js').then((mod) => mod.createBrowserFetcher(mediaAdapters, requestTimeout));
|
|
51
51
|
input._encoded ?? (input._encoded = encodeRequestData({ ...mapInputs(input), method, bodyMediaType: body?.mediaType }, mediaAdapters, parameters));
|
|
52
52
|
return fetcher.fetch(joinURL(withBase(server ? resolveServerUrl(server.url, server.variables) : '/', window.location.origin), resolveRequestData(route, input._encoded)), {
|
|
53
53
|
proxyUrl,
|
|
@@ -299,14 +299,14 @@ function useAuthInputs(securities) {
|
|
|
299
299
|
}
|
|
300
300
|
return result;
|
|
301
301
|
}, [securities]);
|
|
302
|
-
const mapInputs =
|
|
302
|
+
const mapInputs = (values) => {
|
|
303
303
|
for (const item of inputs) {
|
|
304
304
|
if (!item.mapOutput)
|
|
305
305
|
continue;
|
|
306
306
|
values = manipulateValues(values, item.fieldName, item.mapOutput, true);
|
|
307
307
|
}
|
|
308
308
|
return values;
|
|
309
|
-
}
|
|
309
|
+
};
|
|
310
310
|
return { inputs, mapInputs };
|
|
311
311
|
}
|
|
312
312
|
function renderCustomField(fieldName, info, field, key) {
|
|
@@ -16,5 +16,5 @@ export interface Fetcher {
|
|
|
16
16
|
*/
|
|
17
17
|
fetch: (url: string, options: FetchOptions) => Promise<FetchResult>;
|
|
18
18
|
}
|
|
19
|
-
export declare function createBrowserFetcher(adapters: Record<string, MediaAdapter
|
|
19
|
+
export declare function createBrowserFetcher(adapters: Record<string, MediaAdapter>, requestTimeout: number): Fetcher;
|
|
20
20
|
//# sourceMappingURL=fetcher.d.ts.map
|
|
@@ -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,
|
|
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,EACtC,cAAc,EAAE,MAAM,GACrB,OAAO,CAwFT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function createBrowserFetcher(adapters) {
|
|
1
|
+
export function createBrowserFetcher(adapters, requestTimeout) {
|
|
2
2
|
return {
|
|
3
3
|
async fetch(url, options) {
|
|
4
4
|
const headers = new Headers();
|
|
@@ -46,7 +46,7 @@ export function createBrowserFetcher(adapters) {
|
|
|
46
46
|
cache: 'no-cache',
|
|
47
47
|
headers,
|
|
48
48
|
body,
|
|
49
|
-
signal: AbortSignal.timeout(
|
|
49
|
+
signal: AbortSignal.timeout(requestTimeout * 1000),
|
|
50
50
|
})
|
|
51
51
|
.then(async (res) => {
|
|
52
52
|
const contentType = res.headers.get('Content-Type') ?? '';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type * as PageTree from 'fumadocs-core/page-tree';
|
|
2
2
|
import type { LoaderPlugin, PageFile, PageTreeTransformer } from 'fumadocs-core/source';
|
|
3
3
|
/**
|
|
4
4
|
* Fumadocs Source API integration, pass this to `plugins` array in `loader()`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,wBAAgB,aAAa,IAAI,YAAY,CAkC5C;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,GACrB,MAAM,QAAQ,CAAC,IAAI,EACnB,MAAM,QAAQ,GAAG,SAAS,KACzB,QAAQ,CAAC,IA4BX,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,mBAAmB,CAExD"}
|
|
@@ -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;AActD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAmBtE,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,MAAM,EAAE,UAAU,kDA2C7C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,2CAoB1D;AAgBD,wBAAgB,qBAAqB,mBAIpC;AAED,wBAAgB,qBAAqB;oBA1KnB,cAAc,WAAW,WAAW,KAAK,IAAI;EA6K9D"}
|
|
@@ -4,61 +4,58 @@ import { createContext, useContext, useEffect, useMemo, useRef, useState, } from
|
|
|
4
4
|
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
|
-
import { useEffectEvent } from 'fumadocs-core/utils/use-effect-event';
|
|
8
7
|
import { joinURL, resolveRequestData, resolveServerUrl, withBase, } from '../../utils/url.js';
|
|
9
8
|
const CodeExampleContext = createContext(null);
|
|
10
9
|
export function CodeExampleProvider({ route, examples, initialKey, children, }) {
|
|
11
10
|
const [key, setKey] = useState(initialKey ?? examples[0].key);
|
|
12
11
|
const listeners = useRef([]);
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
if (example.key === key) {
|
|
16
|
-
// persistent changes
|
|
17
|
-
example.data = data;
|
|
18
|
-
example.encoded = encoded;
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
for (const listener of listeners.current) {
|
|
23
|
-
listener(data, encoded);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
const updateKey = useEffectEvent((newKey) => {
|
|
27
|
-
const example = examples.find((example) => example.key === newKey);
|
|
28
|
-
if (!example)
|
|
29
|
-
return;
|
|
30
|
-
setKey(newKey);
|
|
31
|
-
for (const listener of listeners.current) {
|
|
32
|
-
listener(example.data, example.encoded);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
const addListener = useEffectEvent((listener) => {
|
|
36
|
-
// initial call to listeners to ensure their data is the latest
|
|
37
|
-
// this is necessary to avoid race conditions between `useEffect()`
|
|
38
|
-
const example = examples.find((example) => example.key === key);
|
|
39
|
-
listener(example.data, example.encoded);
|
|
40
|
-
listeners.current.push(listener);
|
|
41
|
-
});
|
|
42
|
-
const removeListener = useEffectEvent((listener) => {
|
|
43
|
-
listeners.current = listeners.current.filter((item) => item !== listener);
|
|
44
|
-
});
|
|
12
|
+
const examplesRef = useRef(examples);
|
|
13
|
+
examplesRef.current = examples;
|
|
45
14
|
return (_jsx(CodeExampleContext, { value: useMemo(() => ({
|
|
46
15
|
key,
|
|
47
16
|
route,
|
|
48
|
-
setKey:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
17
|
+
setKey: (newKey) => {
|
|
18
|
+
const example = examplesRef.current.find((example) => example.key === newKey);
|
|
19
|
+
if (!example)
|
|
20
|
+
return;
|
|
21
|
+
setKey(newKey);
|
|
22
|
+
for (const listener of listeners.current) {
|
|
23
|
+
listener(example.data, example.encoded);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
getExample: (key) => {
|
|
27
|
+
return examplesRef.current.find((example) => example.key === key);
|
|
28
|
+
},
|
|
29
|
+
setData: (data, encoded) => {
|
|
30
|
+
for (const example of examplesRef.current) {
|
|
31
|
+
if (example.key === key) {
|
|
32
|
+
// persistent changes
|
|
33
|
+
example.data = data;
|
|
34
|
+
example.encoded = encoded;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const listener of listeners.current) {
|
|
39
|
+
listener(data, encoded);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
removeListener: (listener) => {
|
|
43
|
+
listeners.current = listeners.current.filter((item) => item !== listener);
|
|
44
|
+
},
|
|
45
|
+
addListener: (listener) => {
|
|
46
|
+
// initial call to listeners to ensure their data is the latest
|
|
47
|
+
// this is necessary to avoid race conditions between `useEffect()`
|
|
48
|
+
const example = examplesRef.current.find((example) => example.key === key);
|
|
49
|
+
listener(example.data, example.encoded);
|
|
50
|
+
listeners.current.push(listener);
|
|
51
|
+
},
|
|
52
|
+
}), [key, route]), children: children }));
|
|
54
53
|
}
|
|
55
54
|
export function CodeExample(sample) {
|
|
56
55
|
const { shikiOptions, mediaAdapters } = useApiContext();
|
|
57
|
-
const {
|
|
56
|
+
const { getExample, key, route, addListener, removeListener } = useContext(CodeExampleContext);
|
|
58
57
|
const { server } = useServerSelectContext();
|
|
59
|
-
const [data, setData] = useState(() =>
|
|
60
|
-
return examples.find((example) => example.key === key).encoded;
|
|
61
|
-
});
|
|
58
|
+
const [data, setData] = useState(() => getExample(key).encoded);
|
|
62
59
|
useEffect(() => {
|
|
63
60
|
const listener = (_, encoded) => setData(encoded);
|
|
64
61
|
addListener(listener);
|
|
@@ -91,8 +88,8 @@ function SelectDisplay({ item, ...props }) {
|
|
|
91
88
|
return (_jsxs("div", { ...props, children: [_jsx("span", { className: "font-medium text-sm", children: item.title }), _jsx("span", { className: "text-fd-muted-foreground", children: item.description })] }));
|
|
92
89
|
}
|
|
93
90
|
export function useRequestInitialData() {
|
|
94
|
-
const {
|
|
95
|
-
return
|
|
91
|
+
const { getExample, key } = useContext(CodeExampleContext);
|
|
92
|
+
return getExample(key).data;
|
|
96
93
|
}
|
|
97
94
|
export function useRequestDataUpdater() {
|
|
98
95
|
const { setData } = useContext(CodeExampleContext);
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.1",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
7
7
|
"Docs"
|
|
8
8
|
],
|
|
9
|
-
"homepage": "https://fumadocs.
|
|
9
|
+
"homepage": "https://fumadocs.dev",
|
|
10
10
|
"repository": "github:fuma-nama/fumadocs",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"author": "Fuma Nama",
|
|
@@ -65,18 +65,18 @@
|
|
|
65
65
|
"remark-rehype": "^11.1.2",
|
|
66
66
|
"tinyglobby": "^0.2.15",
|
|
67
67
|
"xml-js": "^1.6.11",
|
|
68
|
-
"fumadocs-core": "15.8.
|
|
69
|
-
"fumadocs-ui": "15.8.
|
|
68
|
+
"fumadocs-core": "15.8.3",
|
|
69
|
+
"fumadocs-ui": "15.8.3"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@scalar/api-client-react": "^1.3.
|
|
72
|
+
"@scalar/api-client-react": "^1.3.42",
|
|
73
73
|
"@types/js-yaml": "^4.0.9",
|
|
74
|
-
"@types/node": "24.
|
|
74
|
+
"@types/node": "24.6.2",
|
|
75
75
|
"@types/openapi-sampler": "^1.0.3",
|
|
76
|
-
"@types/react": "^19.
|
|
76
|
+
"@types/react": "^19.2.0",
|
|
77
77
|
"json-schema-typed": "^8.0.1",
|
|
78
78
|
"openapi-types": "^12.1.3",
|
|
79
|
-
"tailwindcss": "^4.1.
|
|
79
|
+
"tailwindcss": "^4.1.14",
|
|
80
80
|
"tsc-alias": "^1.8.16",
|
|
81
81
|
"eslint-config-custom": "0.0.0",
|
|
82
82
|
"tsconfig": "0.0.0"
|