fumadocs-openapi 5.11.3 → 5.11.5
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/index.d.ts +6 -1
- package/dist/server/index.d.ts +5 -1
- package/dist/server/index.js +60 -44
- package/dist/ui/client-client-B0hpK9b7.js +359 -0
- package/dist/ui/{fetcher-DLRl_kVF.js → fetcher-CsyGTBlt.js} +1 -1
- package/dist/ui/{index-client-cz-xNo9A.js → index-client-D_ZwIB_V.js} +97 -3
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +2 -2
- package/dist/ui/server-select-client-prQnF0hV.js +101 -0
- package/package.json +9 -9
- package/dist/ui/client-client-Co3JBILS.js +0 -538
package/dist/index.d.ts
CHANGED
|
@@ -179,6 +179,7 @@ type ReferenceObject = OpenAPIV3_1.ReferenceObject;
|
|
|
179
179
|
type PathItemObject = OpenAPIV3_1.PathItemObject;
|
|
180
180
|
type TagObject = OpenAPIV3_1.TagObject;
|
|
181
181
|
type ServerObject = NoReference<OpenAPIV3_1.ServerObject>;
|
|
182
|
+
type CallbackObject = NoReference<OpenAPIV3_1.CallbackObject>;
|
|
182
183
|
type MethodInformation = NoReference<OperationObject> & {
|
|
183
184
|
method: string;
|
|
184
185
|
};
|
|
@@ -215,6 +216,10 @@ interface RenderContext {
|
|
|
215
216
|
*/
|
|
216
217
|
generateCodeSamples?: (endpoint: EndpointSample) => Awaitable<CodeSample[]>;
|
|
217
218
|
shikiOptions?: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BuiltinTheme>;
|
|
219
|
+
/**
|
|
220
|
+
* Show full response schema instead of only example response & Typescript definitions
|
|
221
|
+
*/
|
|
222
|
+
showResponseSchema?: boolean;
|
|
218
223
|
}
|
|
219
224
|
|
|
220
225
|
type DocumentInput = string | OpenAPIV3_1.Document | OpenAPIV3.Document;
|
|
@@ -317,4 +322,4 @@ interface Config extends GenerateOptions {
|
|
|
317
322
|
}
|
|
318
323
|
declare function generateFiles(options: Config): Promise<void>;
|
|
319
324
|
|
|
320
|
-
export { type Config, type DereferenceMap, type Document, type GenerateOptions, type GeneratePageOutput, type GenerateTagOutput, type MethodInformation, type OperationObject, type ParameterObject, type PathItemObject, type ReferenceObject, type RenderContext, type SecurityRequirementObject, type SecuritySchemeObject, type ServerObject, type TagObject, generateAll, generateFiles, generatePages, generateTags };
|
|
325
|
+
export { type CallbackObject, type Config, type DereferenceMap, type Document, type GenerateOptions, type GeneratePageOutput, type GenerateTagOutput, type MethodInformation, type OperationObject, type ParameterObject, type PathItemObject, type ReferenceObject, type RenderContext, type SecurityRequirementObject, type SecuritySchemeObject, type ServerObject, type TagObject, generateAll, generateFiles, generatePages, generateTags };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -208,11 +208,15 @@ interface RenderContext {
|
|
|
208
208
|
*/
|
|
209
209
|
generateCodeSamples?: (endpoint: EndpointSample) => Awaitable<CodeSample[]>;
|
|
210
210
|
shikiOptions?: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BuiltinTheme>;
|
|
211
|
+
/**
|
|
212
|
+
* Show full response schema instead of only example response & Typescript definitions
|
|
213
|
+
*/
|
|
214
|
+
showResponseSchema?: boolean;
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
type DocumentInput = string | OpenAPIV3_1.Document | OpenAPIV3.Document;
|
|
214
218
|
|
|
215
|
-
type ApiPageContextProps = Pick<Partial<RenderContext>, 'shikiOptions' | 'generateTypeScriptSchema' | 'generateCodeSamples' | 'proxyUrl'>;
|
|
219
|
+
type ApiPageContextProps = Pick<Partial<RenderContext>, 'shikiOptions' | 'generateTypeScriptSchema' | 'generateCodeSamples' | 'proxyUrl' | 'showResponseSchema'>;
|
|
216
220
|
interface ApiPageProps extends ApiPageContextProps {
|
|
217
221
|
document: DocumentInput;
|
|
218
222
|
hasHead: boolean;
|
package/dist/server/index.js
CHANGED
|
@@ -796,6 +796,7 @@ function Operation({ type = 'operation', path, method, ctx, hasHead, headingLeve
|
|
|
796
796
|
const security = method.security ?? ctx.document.security;
|
|
797
797
|
let headNode = null;
|
|
798
798
|
let bodyNode = null;
|
|
799
|
+
let responseNode = null;
|
|
799
800
|
let callbacksNode = null;
|
|
800
801
|
if (hasHead) {
|
|
801
802
|
const title = method.summary ?? (method.operationId ? idToTitle(method.operationId) : path);
|
|
@@ -843,6 +844,38 @@ function Operation({ type = 'operation', path, method, ctx, hasHead, headingLeve
|
|
|
843
844
|
]
|
|
844
845
|
});
|
|
845
846
|
}
|
|
847
|
+
if (method.responses && ctx.showResponseSchema) {
|
|
848
|
+
responseNode = /*#__PURE__*/ jsxs(Fragment, {
|
|
849
|
+
children: [
|
|
850
|
+
heading(headingLevel, 'Response Body', ctx),
|
|
851
|
+
Object.entries(method.responses).map(([status, response])=>{
|
|
852
|
+
if (!response.content) return;
|
|
853
|
+
const mediaType = getPreferredType(response.content);
|
|
854
|
+
if (!mediaType) return null;
|
|
855
|
+
const content = response.content[mediaType];
|
|
856
|
+
if (!content.schema) return null;
|
|
857
|
+
return /*#__PURE__*/ jsxs(Fragment$1, {
|
|
858
|
+
children: [
|
|
859
|
+
heading(headingLevel + 1, status, ctx),
|
|
860
|
+
/*#__PURE__*/ jsx(Markdown, {
|
|
861
|
+
text: response.description
|
|
862
|
+
}),
|
|
863
|
+
/*#__PURE__*/ jsx(Schema, {
|
|
864
|
+
name: "response",
|
|
865
|
+
schema: content.schema,
|
|
866
|
+
ctx: {
|
|
867
|
+
render: ctx,
|
|
868
|
+
writeOnly: false,
|
|
869
|
+
readOnly: true,
|
|
870
|
+
required: true
|
|
871
|
+
}
|
|
872
|
+
})
|
|
873
|
+
]
|
|
874
|
+
}, status);
|
|
875
|
+
})
|
|
876
|
+
]
|
|
877
|
+
});
|
|
878
|
+
}
|
|
846
879
|
const parameterGroups = new Map();
|
|
847
880
|
const endpoint = generateSample(path, method, ctx);
|
|
848
881
|
for (const param of method.parameters ?? []){
|
|
@@ -877,28 +910,11 @@ function Operation({ type = 'operation', path, method, ctx, hasHead, headingLeve
|
|
|
877
910
|
callbacksNode = /*#__PURE__*/ jsxs(Fragment, {
|
|
878
911
|
children: [
|
|
879
912
|
heading(headingLevel, 'Webhooks', ctx),
|
|
880
|
-
Object.entries(method.callbacks).map(([name, callback])
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
return /*#__PURE__*/ jsx(Operation, {
|
|
886
|
-
type: "webhook",
|
|
887
|
-
hasHead: true,
|
|
888
|
-
path: path,
|
|
889
|
-
headingLevel: headingLevel + 1,
|
|
890
|
-
method: createMethod(method, pathItem, operation),
|
|
891
|
-
ctx: ctx
|
|
892
|
-
}, method);
|
|
893
|
-
});
|
|
894
|
-
return /*#__PURE__*/ jsx(Fragment$1, {
|
|
895
|
-
children: pathNodes
|
|
896
|
-
}, path);
|
|
897
|
-
});
|
|
898
|
-
return /*#__PURE__*/ jsx(Fragment$1, {
|
|
899
|
-
children: nodes
|
|
900
|
-
}, name);
|
|
901
|
-
})
|
|
913
|
+
Object.entries(method.callbacks).map(([name, callback])=>/*#__PURE__*/ jsx(WebhookCallback, {
|
|
914
|
+
callback: callback,
|
|
915
|
+
ctx: ctx,
|
|
916
|
+
headingLevel: headingLevel
|
|
917
|
+
}, name))
|
|
902
918
|
]
|
|
903
919
|
});
|
|
904
920
|
}
|
|
@@ -930,6 +946,7 @@ function Operation({ type = 'operation', path, method, ctx, hasHead, headingLeve
|
|
|
930
946
|
]
|
|
931
947
|
}, group);
|
|
932
948
|
}),
|
|
949
|
+
responseNode,
|
|
933
950
|
callbacksNode
|
|
934
951
|
]
|
|
935
952
|
});
|
|
@@ -1005,6 +1022,25 @@ async function APIExample({ method, endpoint, ctx }) {
|
|
|
1005
1022
|
children: children
|
|
1006
1023
|
});
|
|
1007
1024
|
}
|
|
1025
|
+
function WebhookCallback({ callback, ctx, headingLevel }) {
|
|
1026
|
+
return Object.entries(callback).map(([path, pathItem])=>{
|
|
1027
|
+
const pathNodes = methodKeys.map((method)=>{
|
|
1028
|
+
const operation = pathItem[method];
|
|
1029
|
+
if (!operation) return null;
|
|
1030
|
+
return /*#__PURE__*/ jsx(Operation, {
|
|
1031
|
+
type: "webhook",
|
|
1032
|
+
hasHead: true,
|
|
1033
|
+
path: path,
|
|
1034
|
+
headingLevel: headingLevel + 1,
|
|
1035
|
+
method: createMethod(method, pathItem, operation),
|
|
1036
|
+
ctx: ctx
|
|
1037
|
+
}, method);
|
|
1038
|
+
});
|
|
1039
|
+
return /*#__PURE__*/ jsx(Fragment$1, {
|
|
1040
|
+
children: pathNodes
|
|
1041
|
+
}, path);
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1008
1044
|
/**
|
|
1009
1045
|
* Remove duplicated labels
|
|
1010
1046
|
*/ function dedupe(samples) {
|
|
@@ -1031,28 +1067,7 @@ function AuthSection({ ctx: { document, renderer }, requirements }) {
|
|
|
1031
1067
|
})
|
|
1032
1068
|
]
|
|
1033
1069
|
}) : null;
|
|
1034
|
-
if (schema.type === 'http') {
|
|
1035
|
-
info.push(/*#__PURE__*/ jsxs(renderer.Property, {
|
|
1036
|
-
name: "Authorization",
|
|
1037
|
-
type: prefix ? `${prefix} <token>` : '<token>',
|
|
1038
|
-
required: true,
|
|
1039
|
-
children: [
|
|
1040
|
-
schema.description ? /*#__PURE__*/ jsx(Markdown, {
|
|
1041
|
-
text: schema.description
|
|
1042
|
-
}) : null,
|
|
1043
|
-
/*#__PURE__*/ jsxs("p", {
|
|
1044
|
-
children: [
|
|
1045
|
-
"In: ",
|
|
1046
|
-
/*#__PURE__*/ jsx("code", {
|
|
1047
|
-
children: "header"
|
|
1048
|
-
}),
|
|
1049
|
-
scopeElement
|
|
1050
|
-
]
|
|
1051
|
-
})
|
|
1052
|
-
]
|
|
1053
|
-
}, id++));
|
|
1054
|
-
}
|
|
1055
|
-
if (schema.type === 'oauth2') {
|
|
1070
|
+
if (schema.type === 'http' || schema.type === 'oauth2') {
|
|
1056
1071
|
info.push(/*#__PURE__*/ jsxs(renderer.Property, {
|
|
1057
1072
|
name: "Authorization",
|
|
1058
1073
|
type: prefix ? `${prefix} <token>` : '<token>',
|
|
@@ -1312,6 +1327,7 @@ async function getContext({ document, dereferenceMap }, options = {}) {
|
|
|
1312
1327
|
document: document,
|
|
1313
1328
|
dereferenceMap,
|
|
1314
1329
|
proxyUrl: options.proxyUrl,
|
|
1330
|
+
showResponseSchema: options.showResponseSchema,
|
|
1315
1331
|
renderer: {
|
|
1316
1332
|
...createRenders(options.shikiOptions),
|
|
1317
1333
|
...options.renderer
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { forwardRef, createElement, useContext, createContext, useState, useRef, useEffect, useMemo } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { cn, useCopyButton, buttonVariants } from 'fumadocs-ui/components/api';
|
|
5
|
+
import dynamic from 'next/dynamic';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @license lucide-react v0.471.1 - ISC
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the ISC license.
|
|
11
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/ const toKebabCase = (string)=>string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
13
|
+
const mergeClasses = (...classes)=>classes.filter((className, index, array)=>{
|
|
14
|
+
return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
|
|
15
|
+
}).join(" ").trim();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @license lucide-react v0.471.1 - ISC
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the ISC license.
|
|
21
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
22
|
+
*/ var defaultAttributes = {
|
|
23
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
24
|
+
width: 24,
|
|
25
|
+
height: 24,
|
|
26
|
+
viewBox: "0 0 24 24",
|
|
27
|
+
fill: "none",
|
|
28
|
+
stroke: "currentColor",
|
|
29
|
+
strokeWidth: 2,
|
|
30
|
+
strokeLinecap: "round",
|
|
31
|
+
strokeLinejoin: "round"
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const Icon = /*#__PURE__*/ forwardRef(({ color = "currentColor", size = 24, strokeWidth = 2, absoluteStrokeWidth, className = "", children, iconNode, ...rest }, ref)=>{
|
|
35
|
+
return /*#__PURE__*/ createElement("svg", {
|
|
36
|
+
ref,
|
|
37
|
+
...defaultAttributes,
|
|
38
|
+
width: size,
|
|
39
|
+
height: size,
|
|
40
|
+
stroke: color,
|
|
41
|
+
strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
|
|
42
|
+
className: mergeClasses("lucide", className),
|
|
43
|
+
...rest
|
|
44
|
+
}, [
|
|
45
|
+
...iconNode.map(([tag, attrs])=>/*#__PURE__*/ createElement(tag, attrs)),
|
|
46
|
+
...Array.isArray(children) ? children : [
|
|
47
|
+
children
|
|
48
|
+
]
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const createLucideIcon = (iconName, iconNode)=>{
|
|
53
|
+
const Component = /*#__PURE__*/ forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ createElement(Icon, {
|
|
54
|
+
ref,
|
|
55
|
+
iconNode,
|
|
56
|
+
className: mergeClasses(`lucide-${toKebabCase(iconName)}`, className),
|
|
57
|
+
...props
|
|
58
|
+
}));
|
|
59
|
+
Component.displayName = `${iconName}`;
|
|
60
|
+
return Component;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const __iconNode$7 = [
|
|
64
|
+
[
|
|
65
|
+
"path",
|
|
66
|
+
{
|
|
67
|
+
d: "M20 6 9 17l-5-5",
|
|
68
|
+
key: "1gmf2c"
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
];
|
|
72
|
+
const Check = createLucideIcon("Check", __iconNode$7);
|
|
73
|
+
|
|
74
|
+
const __iconNode$6 = [
|
|
75
|
+
[
|
|
76
|
+
"path",
|
|
77
|
+
{
|
|
78
|
+
d: "m6 9 6 6 6-6",
|
|
79
|
+
key: "qrunsl"
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
];
|
|
83
|
+
const ChevronDown = createLucideIcon("ChevronDown", __iconNode$6);
|
|
84
|
+
|
|
85
|
+
const __iconNode$5 = [
|
|
86
|
+
[
|
|
87
|
+
"path",
|
|
88
|
+
{
|
|
89
|
+
d: "m18 15-6-6-6 6",
|
|
90
|
+
key: "153udz"
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
];
|
|
94
|
+
const ChevronUp = createLucideIcon("ChevronUp", __iconNode$5);
|
|
95
|
+
|
|
96
|
+
const __iconNode$4 = [
|
|
97
|
+
[
|
|
98
|
+
"circle",
|
|
99
|
+
{
|
|
100
|
+
cx: "12",
|
|
101
|
+
cy: "12",
|
|
102
|
+
r: "10",
|
|
103
|
+
key: "1mglay"
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
"path",
|
|
108
|
+
{
|
|
109
|
+
d: "m9 12 2 2 4-4",
|
|
110
|
+
key: "dzmm74"
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
];
|
|
114
|
+
const CircleCheck = createLucideIcon("CircleCheck", __iconNode$4);
|
|
115
|
+
|
|
116
|
+
const __iconNode$3 = [
|
|
117
|
+
[
|
|
118
|
+
"circle",
|
|
119
|
+
{
|
|
120
|
+
cx: "12",
|
|
121
|
+
cy: "12",
|
|
122
|
+
r: "10",
|
|
123
|
+
key: "1mglay"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
[
|
|
127
|
+
"path",
|
|
128
|
+
{
|
|
129
|
+
d: "m15 9-6 6",
|
|
130
|
+
key: "1uzhvr"
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
"path",
|
|
135
|
+
{
|
|
136
|
+
d: "m9 9 6 6",
|
|
137
|
+
key: "z0biqf"
|
|
138
|
+
}
|
|
139
|
+
]
|
|
140
|
+
];
|
|
141
|
+
const CircleX = createLucideIcon("CircleX", __iconNode$3);
|
|
142
|
+
|
|
143
|
+
const __iconNode$2 = [
|
|
144
|
+
[
|
|
145
|
+
"rect",
|
|
146
|
+
{
|
|
147
|
+
width: "14",
|
|
148
|
+
height: "14",
|
|
149
|
+
x: "8",
|
|
150
|
+
y: "8",
|
|
151
|
+
rx: "2",
|
|
152
|
+
ry: "2",
|
|
153
|
+
key: "17jyea"
|
|
154
|
+
}
|
|
155
|
+
],
|
|
156
|
+
[
|
|
157
|
+
"path",
|
|
158
|
+
{
|
|
159
|
+
d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",
|
|
160
|
+
key: "zix9uf"
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
];
|
|
164
|
+
const Copy = createLucideIcon("Copy", __iconNode$2);
|
|
165
|
+
|
|
166
|
+
const __iconNode$1 = [
|
|
167
|
+
[
|
|
168
|
+
"path",
|
|
169
|
+
{
|
|
170
|
+
d: "M5 12h14",
|
|
171
|
+
key: "1ays0h"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
[
|
|
175
|
+
"path",
|
|
176
|
+
{
|
|
177
|
+
d: "M12 5v14",
|
|
178
|
+
key: "s699le"
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
];
|
|
182
|
+
const Plus = createLucideIcon("Plus", __iconNode$1);
|
|
183
|
+
|
|
184
|
+
const __iconNode = [
|
|
185
|
+
[
|
|
186
|
+
"path",
|
|
187
|
+
{
|
|
188
|
+
d: "M3 6h18",
|
|
189
|
+
key: "d0wm0j"
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
[
|
|
193
|
+
"path",
|
|
194
|
+
{
|
|
195
|
+
d: "M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",
|
|
196
|
+
key: "4alrt4"
|
|
197
|
+
}
|
|
198
|
+
],
|
|
199
|
+
[
|
|
200
|
+
"path",
|
|
201
|
+
{
|
|
202
|
+
d: "M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",
|
|
203
|
+
key: "v07s0e"
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
[
|
|
207
|
+
"line",
|
|
208
|
+
{
|
|
209
|
+
x1: "10",
|
|
210
|
+
x2: "10",
|
|
211
|
+
y1: "11",
|
|
212
|
+
y2: "17",
|
|
213
|
+
key: "1uufr5"
|
|
214
|
+
}
|
|
215
|
+
],
|
|
216
|
+
[
|
|
217
|
+
"line",
|
|
218
|
+
{
|
|
219
|
+
x1: "14",
|
|
220
|
+
x2: "14",
|
|
221
|
+
y1: "11",
|
|
222
|
+
y2: "17",
|
|
223
|
+
key: "xtxkd"
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
];
|
|
227
|
+
const Trash2 = createLucideIcon("Trash2", __iconNode);
|
|
228
|
+
|
|
229
|
+
const ApiContext = /*#__PURE__*/ createContext(undefined);
|
|
230
|
+
const ServerSelectContext = /*#__PURE__*/ createContext(undefined);
|
|
231
|
+
function useApiContext() {
|
|
232
|
+
const ctx = useContext(ApiContext);
|
|
233
|
+
if (!ctx) throw new Error('Component must be used under <ApiProvider />');
|
|
234
|
+
return ctx;
|
|
235
|
+
}
|
|
236
|
+
function useServerSelectContext() {
|
|
237
|
+
const ctx = useContext(ServerSelectContext);
|
|
238
|
+
if (!ctx) throw new Error('Component must be used under <ApiProvider />');
|
|
239
|
+
return ctx;
|
|
240
|
+
}
|
|
241
|
+
function ApiProvider({ defaultBaseUrl, children, ...props }) {
|
|
242
|
+
const [server, setServer] = useState(()=>{
|
|
243
|
+
const defaultItem = defaultBaseUrl ? props.servers.find((item)=>item.url === defaultBaseUrl) : undefined;
|
|
244
|
+
return defaultItem ? {
|
|
245
|
+
url: defaultItem.url,
|
|
246
|
+
variables: getDefaultValues(defaultItem)
|
|
247
|
+
} : null;
|
|
248
|
+
});
|
|
249
|
+
const serverRef = useRef(server);
|
|
250
|
+
serverRef.current = server;
|
|
251
|
+
useEffect(()=>{
|
|
252
|
+
const cached = localStorage.getItem('apiBaseUrl');
|
|
253
|
+
if (!cached) return;
|
|
254
|
+
try {
|
|
255
|
+
const obj = JSON.parse(cached);
|
|
256
|
+
if (!obj || typeof obj !== 'object') return;
|
|
257
|
+
setServer(obj);
|
|
258
|
+
} catch {
|
|
259
|
+
// ignore
|
|
260
|
+
}
|
|
261
|
+
}, []);
|
|
262
|
+
return /*#__PURE__*/ jsx(ApiContext.Provider, {
|
|
263
|
+
value: useMemo(()=>({
|
|
264
|
+
...props,
|
|
265
|
+
serverRef
|
|
266
|
+
}), [
|
|
267
|
+
props
|
|
268
|
+
]),
|
|
269
|
+
children: /*#__PURE__*/ jsx(ServerSelectContext.Provider, {
|
|
270
|
+
value: useMemo(()=>({
|
|
271
|
+
server,
|
|
272
|
+
setServerVariables (variables) {
|
|
273
|
+
setServer((prev)=>{
|
|
274
|
+
if (!prev) return null;
|
|
275
|
+
const updated = {
|
|
276
|
+
...prev,
|
|
277
|
+
variables
|
|
278
|
+
};
|
|
279
|
+
localStorage.setItem('apiBaseUrl', JSON.stringify(updated));
|
|
280
|
+
return updated;
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
setServer (value) {
|
|
284
|
+
const obj = props.servers.find((item)=>item.url === value);
|
|
285
|
+
if (!obj) return;
|
|
286
|
+
const result = {
|
|
287
|
+
url: value,
|
|
288
|
+
variables: getDefaultValues(obj)
|
|
289
|
+
};
|
|
290
|
+
localStorage.setItem('apiBaseUrl', JSON.stringify(result));
|
|
291
|
+
setServer(result);
|
|
292
|
+
}
|
|
293
|
+
}), [
|
|
294
|
+
server,
|
|
295
|
+
props.servers
|
|
296
|
+
]),
|
|
297
|
+
children: children
|
|
298
|
+
})
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function getDefaultValues(server) {
|
|
302
|
+
return Object.fromEntries(Object.entries(server.variables ?? {}).map(([k, v])=>[
|
|
303
|
+
k,
|
|
304
|
+
v.default
|
|
305
|
+
]));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function getUrl(url, variables) {
|
|
309
|
+
let out = url;
|
|
310
|
+
for (const [key, value] of Object.entries(variables)){
|
|
311
|
+
out = out.replaceAll(`{${key}}`, value);
|
|
312
|
+
}
|
|
313
|
+
return out;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const SchemaContext = /*#__PURE__*/ createContext(undefined);
|
|
317
|
+
function useSchemaContext() {
|
|
318
|
+
const ctx = useContext(SchemaContext);
|
|
319
|
+
if (!ctx) throw new Error('Missing provider');
|
|
320
|
+
return ctx;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const APIPlayground = dynamic(()=>import('./index-client-D_ZwIB_V.js').then(function (n) { return n.i; }).then((mod)=>mod.APIPlayground));
|
|
324
|
+
const ServerSelect = dynamic(()=>import('./server-select-client-prQnF0hV.js'));
|
|
325
|
+
function Root({ children, baseUrl, className, shikiOptions, servers, ...props }) {
|
|
326
|
+
return /*#__PURE__*/ jsx("div", {
|
|
327
|
+
className: cn('flex flex-col gap-24 text-sm text-fd-muted-foreground', className),
|
|
328
|
+
...props,
|
|
329
|
+
children: /*#__PURE__*/ jsx(ApiProvider, {
|
|
330
|
+
servers: servers,
|
|
331
|
+
shikiOptions: shikiOptions,
|
|
332
|
+
defaultBaseUrl: baseUrl,
|
|
333
|
+
children: children
|
|
334
|
+
})
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
function CopyRouteButton({ className, route, ...props }) {
|
|
338
|
+
const { serverRef } = useApiContext();
|
|
339
|
+
const [checked, onCopy] = useCopyButton(()=>{
|
|
340
|
+
void navigator.clipboard.writeText(`${serverRef.current ? getUrl(serverRef.current.url, serverRef.current.variables) : ''}${route}`);
|
|
341
|
+
});
|
|
342
|
+
return /*#__PURE__*/ jsx("button", {
|
|
343
|
+
type: "button",
|
|
344
|
+
className: cn(buttonVariants({
|
|
345
|
+
color: 'ghost',
|
|
346
|
+
className
|
|
347
|
+
})),
|
|
348
|
+
onClick: onCopy,
|
|
349
|
+
"aria-label": "Copy route path",
|
|
350
|
+
...props,
|
|
351
|
+
children: checked ? /*#__PURE__*/ jsx(Check, {
|
|
352
|
+
className: "size-full"
|
|
353
|
+
}) : /*#__PURE__*/ jsx(Copy, {
|
|
354
|
+
className: "size-full"
|
|
355
|
+
})
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export { APIPlayground as A, ChevronDown as C, Plus as P, Root as R, SchemaContext as S, Trash2 as T, Check as a, ChevronUp as b, CircleCheck as c, CircleX as d, useApiContext as e, useServerSelectContext as f, getUrl as g, CopyRouteButton as h, ServerSelect as i, useSchemaContext as u };
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import * as React from 'react';
|
|
3
4
|
import { forwardRef, useId, createContext, useContext, useState, useCallback, useRef, useEffect, useMemo } from 'react';
|
|
4
5
|
import { FormProvider, Controller, useFormContext, useFieldArray, useForm, useWatch } from 'react-hook-form';
|
|
5
6
|
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from 'fumadocs-ui/components/ui/collapsible';
|
|
6
7
|
import { cn, buttonVariants } from 'fumadocs-ui/components/api';
|
|
7
|
-
import {
|
|
8
|
+
import { C as ChevronDown, a as Check, b as ChevronUp, u as useSchemaContext, T as Trash2, P as Plus, c as CircleCheck, d as CircleX, e as useApiContext, S as SchemaContext, g as getUrl } from './client-client-B0hpK9b7.js';
|
|
8
9
|
import { Slot } from '@radix-ui/react-slot';
|
|
9
10
|
import { cva } from 'class-variance-authority';
|
|
10
11
|
import { useOnChange } from 'fumadocs-core/utils/use-on-change';
|
|
12
|
+
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
11
13
|
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
|
12
14
|
|
|
13
15
|
const Form = FormProvider;
|
|
@@ -121,6 +123,98 @@ function getDefaultValues(field, context) {
|
|
|
121
123
|
]));
|
|
122
124
|
}
|
|
123
125
|
|
|
126
|
+
const Select = SelectPrimitive.Root;
|
|
127
|
+
const SelectValue = SelectPrimitive.Value;
|
|
128
|
+
const SelectTrigger = /*#__PURE__*/ forwardRef(({ className, children, ...props }, ref)=>/*#__PURE__*/ jsxs(SelectPrimitive.Trigger, {
|
|
129
|
+
ref: ref,
|
|
130
|
+
className: cn('flex h-10 items-center rounded-md border px-3 py-2 text-start text-sm text-fd-foreground hover:bg-fd-accent focus:outline-none focus:ring-2 focus:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50', className),
|
|
131
|
+
...props,
|
|
132
|
+
children: [
|
|
133
|
+
children,
|
|
134
|
+
/*#__PURE__*/ jsx(SelectPrimitive.Icon, {
|
|
135
|
+
asChild: true,
|
|
136
|
+
children: /*#__PURE__*/ jsx(ChevronDown, {
|
|
137
|
+
className: "ms-auto size-4 text-fd-muted-foreground"
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
}));
|
|
142
|
+
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
|
|
143
|
+
const SelectScrollUpButton = /*#__PURE__*/ forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ jsx(SelectPrimitive.ScrollUpButton, {
|
|
144
|
+
ref: ref,
|
|
145
|
+
className: cn('flex items-center justify-center py-1', className),
|
|
146
|
+
...props,
|
|
147
|
+
children: /*#__PURE__*/ jsx(ChevronUp, {
|
|
148
|
+
className: "size-4"
|
|
149
|
+
})
|
|
150
|
+
}));
|
|
151
|
+
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
|
|
152
|
+
const SelectScrollDownButton = /*#__PURE__*/ forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ jsx(SelectPrimitive.ScrollDownButton, {
|
|
153
|
+
ref: ref,
|
|
154
|
+
className: cn('flex items-center justify-center py-1', className),
|
|
155
|
+
...props,
|
|
156
|
+
children: /*#__PURE__*/ jsx(ChevronDown, {
|
|
157
|
+
className: "size-4"
|
|
158
|
+
})
|
|
159
|
+
}));
|
|
160
|
+
SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
|
|
161
|
+
const SelectContent = /*#__PURE__*/ forwardRef(({ className, children, position = 'popper', ...props }, ref)=>/*#__PURE__*/ jsx(SelectPrimitive.Portal, {
|
|
162
|
+
children: /*#__PURE__*/ jsxs(SelectPrimitive.Content, {
|
|
163
|
+
ref: ref,
|
|
164
|
+
className: cn('z-50 overflow-hidden rounded-lg border bg-fd-popover text-fd-popover-foreground shadow-md data-[state=closed]:animate-fd-popover-out data-[state=open]:animate-fd-popover-in', className),
|
|
165
|
+
position: position,
|
|
166
|
+
...props,
|
|
167
|
+
children: [
|
|
168
|
+
/*#__PURE__*/ jsx(SelectScrollUpButton, {}),
|
|
169
|
+
/*#__PURE__*/ jsx(SelectPrimitive.Viewport, {
|
|
170
|
+
className: cn('p-1', position === 'popper' && 'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'),
|
|
171
|
+
children: children
|
|
172
|
+
}),
|
|
173
|
+
/*#__PURE__*/ jsx(SelectScrollDownButton, {})
|
|
174
|
+
]
|
|
175
|
+
})
|
|
176
|
+
}));
|
|
177
|
+
SelectContent.displayName = SelectPrimitive.Content.displayName;
|
|
178
|
+
const SelectLabel = /*#__PURE__*/ forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ jsx(SelectPrimitive.Label, {
|
|
179
|
+
ref: ref,
|
|
180
|
+
className: cn('py-1.5 pe-2 ps-6 text-sm font-semibold', className),
|
|
181
|
+
...props
|
|
182
|
+
}));
|
|
183
|
+
SelectLabel.displayName = SelectPrimitive.Label.displayName;
|
|
184
|
+
const SelectItem = /*#__PURE__*/ forwardRef(({ className, children, ...props }, ref)=>/*#__PURE__*/ jsxs(SelectPrimitive.Item, {
|
|
185
|
+
ref: ref,
|
|
186
|
+
className: cn('flex select-none flex-row items-center rounded-md py-1.5 pe-2 ps-6 text-sm outline-none focus:bg-fd-accent focus:text-fd-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', className),
|
|
187
|
+
...props,
|
|
188
|
+
children: [
|
|
189
|
+
/*#__PURE__*/ jsx(SelectPrimitive.ItemIndicator, {
|
|
190
|
+
className: "absolute start-2",
|
|
191
|
+
children: /*#__PURE__*/ jsx(Check, {
|
|
192
|
+
className: "size-4"
|
|
193
|
+
})
|
|
194
|
+
}),
|
|
195
|
+
/*#__PURE__*/ jsx(SelectPrimitive.ItemText, {
|
|
196
|
+
children: children
|
|
197
|
+
})
|
|
198
|
+
]
|
|
199
|
+
}));
|
|
200
|
+
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
|
201
|
+
const SelectSeparator = /*#__PURE__*/ forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ jsx(SelectPrimitive.Separator, {
|
|
202
|
+
ref: ref,
|
|
203
|
+
className: cn('my-1 h-px bg-fd-muted', className),
|
|
204
|
+
...props
|
|
205
|
+
}));
|
|
206
|
+
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
|
|
207
|
+
|
|
208
|
+
const Input = /*#__PURE__*/ React.forwardRef(({ className, type, ...props }, ref)=>{
|
|
209
|
+
return /*#__PURE__*/ jsx("input", {
|
|
210
|
+
type: type,
|
|
211
|
+
className: cn('flex h-9 w-full rounded-md border bg-transparent px-2 py-1.5 text-sm text-fd-foreground transition-colors placeholder:text-fd-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50', className),
|
|
212
|
+
ref: ref,
|
|
213
|
+
...props
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
Input.displayName = 'Input';
|
|
217
|
+
|
|
124
218
|
function renderInner({ field, ...props }) {
|
|
125
219
|
if (field.type === 'object') return /*#__PURE__*/ jsx(ObjectInput, {
|
|
126
220
|
field: field,
|
|
@@ -645,7 +739,7 @@ function APIPlayground({ route, method = 'GET', authorization, path = [], header
|
|
|
645
739
|
}
|
|
646
740
|
});
|
|
647
741
|
const testQuery = useQuery(async (input)=>{
|
|
648
|
-
const fetcher = await import('./fetcher-
|
|
742
|
+
const fetcher = await import('./fetcher-CsyGTBlt.js').then((mod)=>mod.createBrowserFetcher(body, schemas));
|
|
649
743
|
const serverUrl = serverRef.current ? getUrl(serverRef.current.url, serverRef.current.variables) : window.location.origin;
|
|
650
744
|
let url = `${serverUrl}${createPathnameFromInput(route, input.path, input.query)}`;
|
|
651
745
|
if (proxyUrl) {
|
|
@@ -871,4 +965,4 @@ var index = {
|
|
|
871
965
|
APIPlayground: APIPlayground
|
|
872
966
|
};
|
|
873
967
|
|
|
874
|
-
export { index as i, resolve as r };
|
|
968
|
+
export { Input as I, Select as S, SelectTrigger as a, SelectValue as b, SelectContent as c, SelectItem as d, index as i, resolve as r };
|