fumadocs-openapi 6.3.0 → 7.0.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/playground/client.d.ts +11 -11
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +124 -119
- package/dist/playground/fetcher.d.ts +6 -22
- package/dist/playground/fetcher.d.ts.map +1 -1
- package/dist/playground/fetcher.js +44 -85
- package/dist/playground/get-default-values.d.ts +2 -3
- package/dist/playground/get-default-values.d.ts.map +1 -1
- package/dist/playground/get-default-values.js +8 -4
- package/dist/playground/index.d.ts +3 -2
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +6 -11
- package/dist/playground/inputs.d.ts.map +1 -1
- package/dist/playground/inputs.js +46 -32
- package/dist/render/operation/api-example.d.ts +18 -4
- package/dist/render/operation/api-example.d.ts.map +1 -1
- package/dist/render/operation/api-example.js +68 -72
- package/dist/render/operation/get-request-data.d.ts +5 -0
- package/dist/render/operation/get-request-data.d.ts.map +1 -0
- package/dist/render/operation/get-request-data.js +71 -0
- package/dist/render/{operation.d.ts → operation/index.d.ts} +4 -4
- package/dist/render/operation/index.d.ts.map +1 -0
- package/dist/render/{operation.js → operation/index.js} +14 -15
- package/dist/render/renderer.d.ts +1 -9
- package/dist/render/renderer.d.ts.map +1 -1
- package/dist/render/renderer.js +3 -5
- package/dist/requests/_shared.d.ts +11 -0
- package/dist/requests/_shared.d.ts.map +1 -0
- package/dist/requests/_shared.js +4 -0
- package/dist/requests/curl.d.ts +2 -2
- package/dist/requests/curl.d.ts.map +1 -1
- package/dist/requests/curl.js +17 -18
- package/dist/requests/go.d.ts +2 -2
- package/dist/requests/go.d.ts.map +1 -1
- package/dist/requests/go.js +15 -14
- package/dist/requests/index.d.ts +3 -0
- package/dist/requests/index.d.ts.map +1 -0
- package/dist/requests/index.js +26 -0
- package/dist/requests/javascript.d.ts +2 -2
- package/dist/requests/javascript.d.ts.map +1 -1
- package/dist/requests/javascript.js +20 -27
- package/dist/requests/python.d.ts +2 -2
- package/dist/requests/python.d.ts.map +1 -1
- package/dist/requests/python.js +18 -22
- package/dist/scalar/client.js +1 -1
- package/dist/server/api-page.js +1 -1
- package/dist/types.d.ts +5 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/client.d.ts +1 -2
- package/dist/ui/client.d.ts.map +1 -1
- package/dist/ui/client.js +1 -3
- package/dist/ui/components/method-label.d.ts +1 -1
- package/dist/ui/contexts/api.d.ts +3 -5
- package/dist/ui/contexts/api.d.ts.map +1 -1
- package/dist/ui/contexts/api.js +2 -7
- package/dist/ui/contexts/code-example.d.ts +25 -0
- package/dist/ui/contexts/code-example.d.ts.map +1 -0
- package/dist/ui/contexts/code-example.js +104 -0
- package/dist/ui/contexts/code-example.lazy.d.ts +12 -0
- package/dist/ui/contexts/code-example.lazy.d.ts.map +1 -0
- package/dist/ui/contexts/code-example.lazy.js +5 -0
- package/dist/ui/server-select.d.ts +6 -1
- package/dist/ui/server-select.d.ts.map +1 -1
- package/dist/ui/server-select.js +6 -7
- package/dist/utils/generate-document.js +1 -1
- package/dist/utils/get-pathname-from-input.d.ts +2 -0
- package/dist/utils/get-pathname-from-input.d.ts.map +1 -0
- package/dist/utils/get-pathname-from-input.js +15 -0
- package/dist/utils/get-typescript-schema.d.ts +2 -3
- package/dist/utils/get-typescript-schema.d.ts.map +1 -1
- package/dist/utils/get-typescript-schema.js +13 -16
- package/package.json +9 -9
- package/dist/render/operation.d.ts.map +0 -1
- package/dist/ui/sample-select.d.ts +0 -4
- package/dist/ui/sample-select.d.ts.map +0 -1
- package/dist/ui/sample-select.js +0 -19
- package/dist/utils/generate-sample.d.ts +0 -40
- package/dist/utils/generate-sample.d.ts.map +0 -1
- package/dist/utils/generate-sample.js +0 -109
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
4
|
+
import { useApiContext, useServerSelectContext } from '../../ui/contexts/api.js';
|
|
5
|
+
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
|
6
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../../ui/components/select.js';
|
|
7
|
+
import { useEffectEvent } from 'fumadocs-core/utils/use-effect-event';
|
|
8
|
+
import { getUrl } from '../../utils/server-url.js';
|
|
9
|
+
import { defaultSamples } from '../../requests/index.js';
|
|
10
|
+
const CodeExampleContext = createContext(null);
|
|
11
|
+
export function CodeExampleProvider({ route, examples, initialKey, children, }) {
|
|
12
|
+
const [key, setKey] = useState(initialKey ?? examples[0].key);
|
|
13
|
+
const listeners = useRef([]);
|
|
14
|
+
const setData = useEffectEvent((newData) => {
|
|
15
|
+
for (const example of examples) {
|
|
16
|
+
if (example.key === key) {
|
|
17
|
+
// persistent changes
|
|
18
|
+
example.data = newData;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
for (const listener of listeners.current) {
|
|
22
|
+
listener(newData);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const updateKey = useEffectEvent((newKey) => {
|
|
26
|
+
const data = examples.find((example) => example.key === newKey)?.data;
|
|
27
|
+
if (!data)
|
|
28
|
+
return;
|
|
29
|
+
setKey(newKey);
|
|
30
|
+
for (const listener of listeners.current) {
|
|
31
|
+
listener(data);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const addListener = useEffectEvent((listener) => {
|
|
35
|
+
listeners.current.push(listener);
|
|
36
|
+
});
|
|
37
|
+
const removeListener = useEffectEvent((listener) => {
|
|
38
|
+
listeners.current = listeners.current.filter((item) => item !== listener);
|
|
39
|
+
});
|
|
40
|
+
return (_jsx(CodeExampleContext, { value: useMemo(() => ({
|
|
41
|
+
key,
|
|
42
|
+
route,
|
|
43
|
+
setKey: updateKey,
|
|
44
|
+
examples,
|
|
45
|
+
setData,
|
|
46
|
+
removeListener,
|
|
47
|
+
addListener,
|
|
48
|
+
}), [addListener, examples, key, removeListener, route, setData, updateKey]), children: children }));
|
|
49
|
+
}
|
|
50
|
+
export function CodeExample(props) {
|
|
51
|
+
const { shikiOptions } = useApiContext();
|
|
52
|
+
const { examples, key, route, addListener, removeListener } = useContext(CodeExampleContext);
|
|
53
|
+
const { server } = useServerSelectContext();
|
|
54
|
+
const [data, setData] = useState(() => {
|
|
55
|
+
return examples.find((example) => example.key === key).data;
|
|
56
|
+
});
|
|
57
|
+
const sample = useMemo(() => {
|
|
58
|
+
if (props.source)
|
|
59
|
+
return props;
|
|
60
|
+
return defaultSamples.find((item) => item.label === props.label);
|
|
61
|
+
}, [props]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const listener = setData;
|
|
64
|
+
addListener(listener);
|
|
65
|
+
return () => {
|
|
66
|
+
removeListener(listener);
|
|
67
|
+
};
|
|
68
|
+
}, [addListener, removeListener]);
|
|
69
|
+
const code = useMemo(() => {
|
|
70
|
+
if (!sample?.source)
|
|
71
|
+
return;
|
|
72
|
+
if (typeof sample.source === 'string')
|
|
73
|
+
return sample.source;
|
|
74
|
+
return sample.source(`${server ? getUrl(server.url, server.variables) : '/'}${route}`, data);
|
|
75
|
+
}, [sample, server, route, data]);
|
|
76
|
+
if (!code || !sample)
|
|
77
|
+
return null;
|
|
78
|
+
return (_jsx(DynamicCodeBlock, { lang: sample.lang, code: code, options: shikiOptions }));
|
|
79
|
+
}
|
|
80
|
+
export function CodeExampleSelector({ items }) {
|
|
81
|
+
const { key, setKey } = useContext(CodeExampleContext);
|
|
82
|
+
const item = items.find((item) => item.value === key);
|
|
83
|
+
return (_jsxs(Select, { value: key, onValueChange: setKey, children: [_jsx(SelectTrigger, { className: "not-prose mb-2", children: _jsx(SelectValue, { asChild: true, children: item ? _jsx(SelectDisplay, { item: item }) : null }) }), _jsx(SelectContent, { children: items.map((item) => (_jsx(SelectItem, { value: item.value, children: _jsx(SelectDisplay, { item: item }) }, item.value))) })] }));
|
|
84
|
+
}
|
|
85
|
+
function SelectDisplay({ item, ...props }) {
|
|
86
|
+
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 })] }));
|
|
87
|
+
}
|
|
88
|
+
export function useRequestData() {
|
|
89
|
+
const { examples, key, setData } = useContext(CodeExampleContext);
|
|
90
|
+
const data = useMemo(() => examples.find((example) => example.key === key).data, [examples, key]);
|
|
91
|
+
const saveData = useEffectEvent((data) => {
|
|
92
|
+
setData(data);
|
|
93
|
+
});
|
|
94
|
+
return useMemo(() => ({
|
|
95
|
+
/**
|
|
96
|
+
* initial request data
|
|
97
|
+
*/
|
|
98
|
+
data,
|
|
99
|
+
/**
|
|
100
|
+
* Save changes to request data, it won't trigger re-render on the component itself, which makes it safe to call in an effect with `data` as dep
|
|
101
|
+
*/
|
|
102
|
+
saveData,
|
|
103
|
+
}), [data, saveData]);
|
|
104
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const CodeExampleProvider: import("react").ComponentType<{
|
|
2
|
+
route: string;
|
|
3
|
+
examples: {
|
|
4
|
+
key: string;
|
|
5
|
+
data: import("../../requests/_shared.js").RequestData;
|
|
6
|
+
}[];
|
|
7
|
+
initialKey?: string;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const CodeExample: import("react").ComponentType<import("../../render/operation/index.js").CodeSample>;
|
|
11
|
+
export declare const CodeExampleSelector: import("react").ComponentType<import("../../render/renderer.js").SamplesProps>;
|
|
12
|
+
//# sourceMappingURL=code-example.lazy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-example.lazy.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.lazy.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB;;;;;;;cASi4B,MAAO,SAAS;EAPh7B,CAAC;AACF,eAAO,MAAM,WAAW,4EAEvB,CAAC;AACF,eAAO,MAAM,mBAAmB,6EAE/B,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import dynamic from 'next/dynamic';
|
|
3
|
+
export const CodeExampleProvider = dynamic(() => import('./code-example.js').then((mod) => mod.CodeExampleProvider));
|
|
4
|
+
export const CodeExample = dynamic(() => import('./code-example.js').then((mod) => mod.CodeExample));
|
|
5
|
+
export const CodeExampleSelector = dynamic(() => import('./code-example.js').then((mod) => mod.CodeExampleSelector));
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { type SelectedServer } from '../ui/contexts/api.js';
|
|
1
2
|
import type { HTMLAttributes } from 'react';
|
|
2
|
-
export default function ServerSelect(props: HTMLAttributes<HTMLDivElement>
|
|
3
|
+
export default function ServerSelect({ server, onServerChanged, onVariablesChanged, ...props }: HTMLAttributes<HTMLDivElement> & {
|
|
4
|
+
server: SelectedServer | null;
|
|
5
|
+
onServerChanged: (value: string) => void;
|
|
6
|
+
onVariablesChanged: (value: Record<string, string>) => void;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
3
8
|
//# sourceMappingURL=server-select.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-select.d.ts","sourceRoot":"","sources":["../../src/ui/server-select.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server-select.d.ts","sourceRoot":"","sources":["../../src/ui/server-select.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,mBAAmB,CAAC;AASvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,MAAM,EACN,eAAe,EACf,kBAAkB,EAClB,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,GAAG;IAClC,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC7D,kDA4EA"}
|
package/dist/ui/server-select.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useApiContext
|
|
3
|
+
import { useApiContext } from '../ui/contexts/api.js';
|
|
4
4
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/components/select.js';
|
|
5
5
|
import { Input, labelVariants } from '../ui/components/input.js';
|
|
6
6
|
import { cn } from 'fumadocs-ui/components/api';
|
|
7
|
-
export default function ServerSelect(props) {
|
|
7
|
+
export default function ServerSelect({ server, onServerChanged, onVariablesChanged, ...props }) {
|
|
8
8
|
const { servers } = useApiContext();
|
|
9
|
-
const { server, setServer, setServerVariables } = useServerSelectContext();
|
|
10
9
|
if (servers.length <= 1)
|
|
11
10
|
return null;
|
|
12
11
|
const schema = server
|
|
13
12
|
? servers.find((item) => item.url === server.url)
|
|
14
|
-
:
|
|
15
|
-
return (_jsxs("div", { ...props, className: cn('flex flex-col gap-4', props.className), children: [_jsxs(Select, { value: server?.url, onValueChange:
|
|
13
|
+
: null;
|
|
14
|
+
return (_jsxs("div", { ...props, className: cn('flex flex-col gap-4', props.className), children: [_jsxs(Select, { value: server?.url, onValueChange: onServerChanged, children: [_jsx(SelectTrigger, { className: "h-auto break-all", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: servers.map((item) => (_jsxs(SelectItem, { value: item.url, children: [item.url, _jsx("p", { className: "text-start text-fd-muted-foreground", children: item.description })] }, item.url))) })] }), Object.entries(schema?.variables ?? {}).map(([key, variable]) => {
|
|
16
15
|
if (!server)
|
|
17
16
|
return;
|
|
18
17
|
const id = `fd_server_select_${key}`;
|
|
19
|
-
return (_jsxs("fieldset", { className: "flex flex-col gap-1", children: [_jsx("label", { className: cn(labelVariants()), htmlFor: id, children: key }), _jsx("p", { className: "text-xs text-fd-muted-foreground empty:hidden", children: variable.description }), variable.enum ? (_jsxs(Select, { value: server.variables[key], onValueChange: (v) =>
|
|
18
|
+
return (_jsxs("fieldset", { className: "flex flex-col gap-1", children: [_jsx("label", { className: cn(labelVariants()), htmlFor: id, children: key }), _jsx("p", { className: "text-xs text-fd-muted-foreground empty:hidden", children: variable.description }), variable.enum ? (_jsxs(Select, { value: server.variables[key], onValueChange: (v) => onVariablesChanged({
|
|
20
19
|
...server?.variables,
|
|
21
20
|
[key]: v,
|
|
22
|
-
}), children: [_jsx(SelectTrigger, { id: id, children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: variable.enum.map((value) => (_jsx(SelectItem, { value: value, children: value }, value))) })] })) : (_jsx(Input, { id: id, value: server.variables[key], onChange: (e) =>
|
|
21
|
+
}), children: [_jsx(SelectTrigger, { id: id, children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: variable.enum.map((value) => (_jsx(SelectItem, { value: value, children: value }, value))) })] })) : (_jsx(Input, { id: id, value: server.variables[key], onChange: (e) => onVariablesChanged({
|
|
23
22
|
...server?.variables,
|
|
24
23
|
[key]: e.target.value,
|
|
25
24
|
}) }))] }, key));
|
|
@@ -28,7 +28,7 @@ export function generateDocument(options) {
|
|
|
28
28
|
if (banner.length > 0)
|
|
29
29
|
out.push(`---\n${banner}\n---`);
|
|
30
30
|
if (addGeneratedComment !== false) {
|
|
31
|
-
let commentContent = 'This file was generated by Fumadocs
|
|
31
|
+
let commentContent = 'This file was generated by Fumadocs. Do not edit this file directly. Any changes should be made by running the generation command again.';
|
|
32
32
|
if (typeof addGeneratedComment === 'string') {
|
|
33
33
|
commentContent = addGeneratedComment;
|
|
34
34
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-pathname-from-input.d.ts","sourceRoot":"","sources":["../../src/utils/get-pathname-from-input.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAkBR"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function getPathnameFromInput(url, path, query) {
|
|
2
|
+
let pathname = url;
|
|
3
|
+
for (const key in path) {
|
|
4
|
+
const paramValue = path[key];
|
|
5
|
+
if (typeof paramValue === 'string' && paramValue.length > 0)
|
|
6
|
+
pathname = pathname.replace(`{${key}}`, paramValue);
|
|
7
|
+
}
|
|
8
|
+
const searchParams = new URLSearchParams();
|
|
9
|
+
for (const key in query) {
|
|
10
|
+
const paramValue = query[key];
|
|
11
|
+
if (typeof paramValue === 'string' && paramValue.length > 0)
|
|
12
|
+
searchParams.append(key, paramValue);
|
|
13
|
+
}
|
|
14
|
+
return searchParams.size > 0 ? `${pathname}?${searchParams}` : pathname;
|
|
15
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare function getTypescriptSchema(endpoint: EndpointSample, code: string, dereferenceMap: DereferenceMap): Promise<string | undefined>;
|
|
1
|
+
import type { DereferenceMap } from '../types.js';
|
|
2
|
+
export declare function getTypescriptSchema(schema: object, dereferenceMap: DereferenceMap): Promise<string | undefined>;
|
|
4
3
|
//# sourceMappingURL=get-typescript-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-typescript-schema.d.ts","sourceRoot":"","sources":["../../src/utils/get-typescript-schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"get-typescript-schema.d.ts","sourceRoot":"","sources":["../../src/utils/get-typescript-schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgB7B"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { compile } from '@fumari/json-schema-to-typescript';
|
|
2
|
-
export async function getTypescriptSchema(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
enableConstEnums: false,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
2
|
+
export async function getTypescriptSchema(schema, dereferenceMap) {
|
|
3
|
+
return compile(
|
|
4
|
+
// re-running on the same schema results in error
|
|
5
|
+
// because it uses `defineProperty` to define internal references
|
|
6
|
+
// we clone the schema to fix this problem
|
|
7
|
+
schema, 'Response', {
|
|
8
|
+
$refOptions: false,
|
|
9
|
+
schemaToId: dereferenceMap,
|
|
10
|
+
bannerComment: '',
|
|
11
|
+
additionalProperties: false,
|
|
12
|
+
format: true,
|
|
13
|
+
enableConstEnums: false,
|
|
14
|
+
});
|
|
18
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"class-variance-authority": "^0.7.1",
|
|
53
53
|
"fast-glob": "^3.3.3",
|
|
54
54
|
"github-slugger": "^2.0.0",
|
|
55
|
-
"hast-util-to-jsx-runtime": "^2.3.
|
|
55
|
+
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
56
56
|
"js-yaml": "^4.1.0",
|
|
57
|
-
"lucide-react": "^0.
|
|
57
|
+
"lucide-react": "^0.479.0",
|
|
58
58
|
"next-themes": "^0.4.4",
|
|
59
59
|
"openapi-sampler": "^1.6.1",
|
|
60
60
|
"react-hook-form": "^7.54.2",
|
|
@@ -62,18 +62,18 @@
|
|
|
62
62
|
"remark-rehype": "^11.1.1",
|
|
63
63
|
"shiki": "^3.1.0",
|
|
64
64
|
"xml-js": "^1.6.11",
|
|
65
|
-
"fumadocs-core": "15.0.
|
|
66
|
-
"fumadocs-ui": "15.0.
|
|
65
|
+
"fumadocs-core": "15.0.16",
|
|
66
|
+
"fumadocs-ui": "15.0.16"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@scalar/api-client-react": "^1.1.
|
|
69
|
+
"@scalar/api-client-react": "^1.1.42",
|
|
70
70
|
"@types/js-yaml": "^4.0.9",
|
|
71
|
-
"@types/node": "22.13.
|
|
71
|
+
"@types/node": "22.13.10",
|
|
72
72
|
"@types/openapi-sampler": "^1.0.3",
|
|
73
73
|
"@types/react": "^19.0.10",
|
|
74
|
-
"next": "15.2.
|
|
74
|
+
"next": "15.2.1",
|
|
75
75
|
"openapi-types": "^12.1.3",
|
|
76
|
-
"tailwindcss": "^4.0.
|
|
76
|
+
"tailwindcss": "^4.0.12",
|
|
77
77
|
"tsc-alias": "^1.8.11",
|
|
78
78
|
"eslint-config-custom": "0.0.0",
|
|
79
79
|
"tsconfig": "0.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/render/operation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAYjB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EACF,MAAM,GACN,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GACtE,KAAK,CAAC;CACX;AASD,wBAAgB,SAAS,CAAC,EACxB,IAAkB,EAClB,IAAI,EACJ,MAAM,EACN,GAAG,EACH,OAAO,EACP,YAAgB,GACjB,EAAE;IACD,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;IAEnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,YAAY,CAkLf"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { SampleProps, SamplesProps } from '../render/renderer.js';
|
|
2
|
-
export declare function Samples({ items, defaultValue, children, }: SamplesProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
-
export declare function Sample({ value, children }: SampleProps): import("react").ReactNode;
|
|
4
|
-
//# sourceMappingURL=sample-select.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample-select.d.ts","sourceRoot":"","sources":["../../src/ui/sample-select.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAWnE,wBAAgB,OAAO,CAAC,EACtB,KAAK,EACL,YAA6B,EAC7B,QAAQ,GACT,EAAE,YAAY,2CA0Bd;AAWD,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,WAAW,6BAKtD"}
|
package/dist/ui/sample-select.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, use, useState } from 'react';
|
|
3
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/components/select.js';
|
|
4
|
-
const ActiveSampleContext = createContext('');
|
|
5
|
-
export function Samples({ items, defaultValue = items[0].value, children, }) {
|
|
6
|
-
const [value, setValue] = useState('');
|
|
7
|
-
const active = value === '' ? defaultValue : value;
|
|
8
|
-
const defaultItem = items.find((item) => item.value === defaultValue);
|
|
9
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Select, { value: value, onValueChange: setValue, children: [_jsx(SelectTrigger, { className: "not-prose mb-2", children: _jsx(SelectValue, { placeholder: defaultItem ? _jsx(SelectDisplay, { ...defaultItem }) : null }) }), _jsx(SelectContent, { children: items.map((item) => (_jsx(SelectItem, { value: item.value, children: _jsx(SelectDisplay, { ...item }) }, item.value))) })] }), _jsx(ActiveSampleContext, { value: active, children: children })] }));
|
|
10
|
-
}
|
|
11
|
-
function SelectDisplay(item) {
|
|
12
|
-
return (_jsxs(_Fragment, { children: [_jsx("span", { className: "font-medium text-sm", children: item.title }), _jsx("span", { className: "text-fd-muted-foreground", children: item.description })] }));
|
|
13
|
-
}
|
|
14
|
-
export function Sample({ value, children }) {
|
|
15
|
-
const active = use(ActiveSampleContext);
|
|
16
|
-
if (value !== active)
|
|
17
|
-
return;
|
|
18
|
-
return children;
|
|
19
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { MethodInformation, RenderContext } from '../types.js';
|
|
2
|
-
import { type ParsedSchema, type NoReference } from '../utils/schema.js';
|
|
3
|
-
import type { OpenAPIV3_1 } from 'openapi-types';
|
|
4
|
-
export type Samples = {
|
|
5
|
-
[key in '_default' | (string & {})]?: {
|
|
6
|
-
value?: unknown;
|
|
7
|
-
description?: string;
|
|
8
|
-
summary?: string;
|
|
9
|
-
externalValue?: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Sample info of endpoint
|
|
14
|
-
*/
|
|
15
|
-
export interface EndpointSample {
|
|
16
|
-
/**
|
|
17
|
-
* Request URL, including path and query parameters
|
|
18
|
-
*/
|
|
19
|
-
url: string;
|
|
20
|
-
method: string;
|
|
21
|
-
body?: {
|
|
22
|
-
schema: ParsedSchema;
|
|
23
|
-
mediaType: string;
|
|
24
|
-
samples: Samples;
|
|
25
|
-
};
|
|
26
|
-
responses: Record<string, ResponseSample>;
|
|
27
|
-
parameters: ParameterSample[];
|
|
28
|
-
}
|
|
29
|
-
interface ResponseSample {
|
|
30
|
-
mediaType: string;
|
|
31
|
-
samples: Samples;
|
|
32
|
-
schema: ParsedSchema;
|
|
33
|
-
}
|
|
34
|
-
interface ParameterSample extends NoReference<OpenAPIV3_1.ParameterObject> {
|
|
35
|
-
sample: unknown;
|
|
36
|
-
isAuthOnly: boolean;
|
|
37
|
-
}
|
|
38
|
-
export declare function generateSample(path: string, method: MethodInformation, { baseUrl, schema: { document } }: RenderContext): EndpointSample;
|
|
39
|
-
export {};
|
|
40
|
-
//# sourceMappingURL=generate-sample.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-sample.d.ts","sourceRoot":"","sources":["../../src/utils/generate-sample.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,MAAM,OAAO,GAAG;KACnB,GAAG,IAAI,UAAU,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE;QACpC,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,YAAY,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC1C,UAAU,EAAE,eAAe,EAAE,CAAC;CAC/B;AAED,UAAU,cAAc;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,UAAU,eAAgB,SAAQ,WAAW,CAAC,WAAW,CAAC,eAAe,CAAC;IACxE,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,aAAa,GAC/C,cAAc,CA0HhB"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { sample } from 'openapi-sampler';
|
|
2
|
-
import { getPreferredType, } from '../utils/schema.js';
|
|
3
|
-
import { getSecurities, getSecurityPrefix } from '../utils/get-security.js';
|
|
4
|
-
export function generateSample(path, method, { baseUrl, schema: { document } }) {
|
|
5
|
-
const params = [];
|
|
6
|
-
const responses = {};
|
|
7
|
-
for (const param of method.parameters ?? []) {
|
|
8
|
-
let schema = param.schema, value;
|
|
9
|
-
if (!schema && param.content) {
|
|
10
|
-
const key = getPreferredType(param.content);
|
|
11
|
-
const content = key ? param.content[key] : undefined;
|
|
12
|
-
if (!content)
|
|
13
|
-
throw new Error(`Cannot find parameter schema for ${param.name} in ${path} ${method.method}`);
|
|
14
|
-
schema = content.schema;
|
|
15
|
-
value = content.example ?? param.example ?? sample(schema);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
value = param.example ?? sample(schema);
|
|
19
|
-
}
|
|
20
|
-
if (schema?.type && param.schema?.type === value) {
|
|
21
|
-
// if no example is defined make sure its visible that there is still a placeholder, equal to auth <token>
|
|
22
|
-
value = `<${value}>`;
|
|
23
|
-
}
|
|
24
|
-
params.push({
|
|
25
|
-
...param,
|
|
26
|
-
sample: value,
|
|
27
|
-
isAuthOnly: false,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
const requirements = method.security ?? document.security;
|
|
31
|
-
if (requirements && requirements.length > 0) {
|
|
32
|
-
for (const security of getSecurities(requirements[0], document)) {
|
|
33
|
-
const prefix = getSecurityPrefix(security);
|
|
34
|
-
params.push({
|
|
35
|
-
name: security.type === 'apiKey' ? security.name : 'Authorization',
|
|
36
|
-
schema: {
|
|
37
|
-
type: 'string',
|
|
38
|
-
},
|
|
39
|
-
sample: prefix ? `${prefix} <token>` : '<token>',
|
|
40
|
-
in: 'header',
|
|
41
|
-
isAuthOnly: true,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
let bodyOutput;
|
|
46
|
-
if (method.requestBody) {
|
|
47
|
-
const body = method.requestBody.content;
|
|
48
|
-
const type = getPreferredType(body);
|
|
49
|
-
if (!type)
|
|
50
|
-
throw new Error(`Cannot find body schema for ${path} ${method.method}: missing media type`);
|
|
51
|
-
const schema = (type ? body[type].schema : undefined) ?? {};
|
|
52
|
-
bodyOutput = {
|
|
53
|
-
schema,
|
|
54
|
-
mediaType: type,
|
|
55
|
-
samples: body[type].examples
|
|
56
|
-
? body[type].examples
|
|
57
|
-
: {
|
|
58
|
-
_default: {
|
|
59
|
-
value: body[type].example ?? generateBody(method.method, schema),
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
for (const [code, response] of Object.entries(method.responses ?? {})) {
|
|
65
|
-
const content = response.content;
|
|
66
|
-
if (!content)
|
|
67
|
-
continue;
|
|
68
|
-
const mediaType = getPreferredType(content);
|
|
69
|
-
if (!mediaType)
|
|
70
|
-
continue;
|
|
71
|
-
const responseSchema = content[mediaType].schema;
|
|
72
|
-
if (!responseSchema)
|
|
73
|
-
continue;
|
|
74
|
-
const examples = content[mediaType].examples ?? content.examples;
|
|
75
|
-
const example = content[mediaType].example ?? content.example;
|
|
76
|
-
responses[code] = {
|
|
77
|
-
mediaType,
|
|
78
|
-
samples: examples
|
|
79
|
-
? examples
|
|
80
|
-
: {
|
|
81
|
-
_default: example ?? generateBody(method.method, responseSchema),
|
|
82
|
-
},
|
|
83
|
-
schema: responseSchema,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
let pathWithParameters = path;
|
|
87
|
-
const queryParams = new URLSearchParams();
|
|
88
|
-
for (const param of params) {
|
|
89
|
-
if (param.in === 'query')
|
|
90
|
-
queryParams.append(param.name, String(param.sample));
|
|
91
|
-
if (param.in === 'path')
|
|
92
|
-
pathWithParameters = pathWithParameters.replace(`{${param.name}}`, String(param.sample));
|
|
93
|
-
}
|
|
94
|
-
if (queryParams.size > 0)
|
|
95
|
-
pathWithParameters = `${pathWithParameters}?${queryParams.toString()}`;
|
|
96
|
-
return {
|
|
97
|
-
url: `${baseUrl}${pathWithParameters}`,
|
|
98
|
-
body: bodyOutput,
|
|
99
|
-
responses,
|
|
100
|
-
method: method.method,
|
|
101
|
-
parameters: params,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function generateBody(method, schema) {
|
|
105
|
-
return sample(schema, {
|
|
106
|
-
skipReadOnly: method !== 'GET',
|
|
107
|
-
skipWriteOnly: method === 'GET',
|
|
108
|
-
});
|
|
109
|
-
}
|