@@ -46,7 +46,7 @@ import {
4646 CollapsibleTrigger ,
4747} from 'fumadocs-ui/components/ui/collapsible' ;
4848import { ChevronDown , LoaderCircle } from 'lucide-react' ;
49- import type { RequestData } from '@/requests/_shared' ;
49+ import { encodeRequestData , type RequestData } from '@/requests/_shared' ;
5050import { buttonVariants } from 'fumadocs-ui/components/ui/button' ;
5151import { cn } from 'fumadocs-ui/utils/cn' ;
5252import {
@@ -68,13 +68,16 @@ import {
6868 SelectValue ,
6969} from '@/ui/components/select' ;
7070import { labelVariants } from '@/ui/components/input' ;
71+ import type { ParsedSchema } from '@/utils/schema' ;
7172
7273interface FormValues {
73- path : Record < string , string > ;
74- query : Record < string , string > ;
75- header : Record < string , string > ;
76- cookie : Record < string , string > ;
74+ path : Record < string , unknown > ;
75+ query : Record < string , unknown > ;
76+ header : Record < string , unknown > ;
77+ cookie : Record < string , unknown > ;
7778 body : unknown ;
79+
80+ _encoded ?: RequestData ;
7881}
7982
8083export interface CustomField < TName extends FieldPath < FormValues > , Info > {
@@ -120,22 +123,6 @@ export interface ClientProps extends HTMLAttributes<HTMLFormElement> {
120123
121124const AuthPrefix = '__fumadocs_auth' ;
122125
123- function toRequestData (
124- method : string ,
125- mediaType : string | undefined ,
126- value : FormValues ,
127- ) : RequestData {
128- return {
129- path : value . path ,
130- method,
131- header : value . header ,
132- body : value . body ,
133- bodyMediaType : mediaType ,
134- cookie : value . cookie ,
135- query : value . query ,
136- } ;
137- }
138-
139126const ServerSelect = lazy ( ( ) => import ( '@/ui/server-select' ) ) ;
140127const OauthDialog = lazy ( ( ) =>
141128 import ( './auth/oauth-dialog' ) . then ( ( mod ) => ( {
@@ -152,7 +139,7 @@ export default function Client({
152139 route,
153140 method = 'GET' ,
154141 securities,
155- parameters,
142+ parameters = [ ] ,
156143 body,
157144 fields,
158145 references,
@@ -187,19 +174,24 @@ export default function Client({
187174 const fetcher = await import ( './fetcher' ) . then ( ( mod ) =>
188175 mod . createBrowserFetcher ( mediaAdapters ) ,
189176 ) ;
190- const data = toRequestData ( method , body ?. mediaType , input ) ;
177+
178+ input . _encoded ??= encodeRequestData (
179+ { ...mapInputs ( input ) , method, bodyMediaType : body ?. mediaType } ,
180+ mediaAdapters ,
181+ parameters ,
182+ ) ;
191183
192184 return fetcher . fetch (
193185 joinURL (
194186 withBase (
195187 server ? resolveServerUrl ( server . url , server . variables ) : '/' ,
196188 window . location . origin ,
197189 ) ,
198- resolveRequestData ( route , data ) ,
190+ resolveRequestData ( route , input . _encoded ) ,
199191 ) ,
200192 {
201193 proxyUrl,
202- ...data ,
194+ ...input . _encoded ,
203195 } ,
204196 ) ;
205197 } ) ;
@@ -254,7 +246,13 @@ export default function Client({
254246 }
255247 }
256248
257- updater . setData ( toRequestData ( method , body ?. mediaType , mapInputs ( values ) ) ) ;
249+ const data = {
250+ ...mapInputs ( values ) ,
251+ method,
252+ bodyMediaType : body ?. mediaType ,
253+ } ;
254+ values . _encoded ??= encodeRequestData ( data , mediaAdapters , parameters ) ;
255+ updater . setData ( data , values . _encoded ) ;
258256 } ) ;
259257
260258 useEffect ( ( ) => {
@@ -265,6 +263,9 @@ export default function Client({
265263 values : true ,
266264 } ,
267265 callback ( { values } ) {
266+ // remove cached encoded request data
267+ delete values . _encoded ;
268+
268269 if ( timer ) window . clearTimeout ( timer ) ;
269270 timer = window . setTimeout (
270271 ( ) => onUpdateDebounced ( values ) ,
@@ -425,11 +426,16 @@ function FormBody({
425426 < CollapsiblePanel key = { name } title = { name } >
426427 { param . map ( ( field ) => {
427428 const fieldName = `${ type } .${ field . name } ` as const ;
429+ const schema = (
430+ field . content
431+ ? field . content [ Object . keys ( field . content ) [ 0 ] ] . schema
432+ : field . schema
433+ ) as ParsedSchema ;
428434
429435 if ( fields ?. parameter ) {
430436 return renderCustomField (
431437 fieldName ,
432- field . schema ,
438+ schema ,
433439 fields . parameter ,
434440 field . name ,
435441 ) ;
@@ -440,7 +446,7 @@ function FormBody({
440446 key = { fieldName }
441447 name = { field . name }
442448 fieldName = { fieldName }
443- field = { field . schema }
449+ field = { schema }
444450 />
445451 ) ;
446452 } ) }
0 commit comments