@@ -271,7 +271,6 @@ export const createHook = ({
271
271
return props . map ( ( item ) => `["${ item . name } "]: props["${ item . name } "]` ) . join ( ',' ) ;
272
272
} ;
273
273
274
- let defaultHeaders = { } ;
275
274
const generateBodyProps = ( ) => {
276
275
if ( definitionKey && ! hasRequestBodyArrray ) {
277
276
const scheme = schemasComponents ?. schemas ?. [ definitionKey ] as SchemaObject ;
@@ -281,7 +280,6 @@ export const createHook = ({
281
280
'content' in operation . requestBody &&
282
281
Object . keys ( operation . requestBody . content ) [ 0 ] === 'multipart/form-data'
283
282
) {
284
- defaultHeaders = JSON . stringify ( { ...defaultHeaders , ...{ ContentType : 'multipart/form-data' } } ) ;
285
283
let formData = `const body = new FormData()` ;
286
284
schemProperties . forEach ( ( item ) => {
287
285
if ( scheme . required ?. includes ( item ) ) {
@@ -304,7 +302,10 @@ export const createHook = ({
304
302
let bodyData = '' ;
305
303
const contentTypes = Object . keys ( operation . requestBody . content ) ;
306
304
if ( contentTypes . includes ( 'multipart/form-data' ) ) {
305
+ console . log ( 'UPDATE2' ) ;
306
+
307
307
bodyData += `const body = new FormData()` ;
308
+
308
309
for ( let contentType of contentTypes ) {
309
310
const schema = operation . requestBody . content [ contentType ] . schema ! ;
310
311
if ( 'properties' in schema ) {
@@ -338,6 +339,11 @@ export const createHook = ({
338
339
}
339
340
} ;
340
341
342
+ const hasFormData = generateBodyProps ( ) ?. includes ( 'FormData' ) ;
343
+ const defaultHeaders = JSON . stringify ( {
344
+ ContentType : hasFormData ? 'multipart/form-data' : 'application/json' ,
345
+ } ) ;
346
+
341
347
if ( ! requestBodyComponent && ! paramsInPath . length && ! queryParam && ! headerParam ) {
342
348
output += `
343
349
export const ${ fetchName } = async () => {
@@ -445,7 +451,7 @@ export const createHook = ({
445
451
446
452
export const ${ fetchName } = async (${ bodyProps } : ${ componentName } Params) => {
447
453
${ generateBodyProps ( ) }
448
- const headers = { ${ generateProps ( header ) } , ... ${ defaultHeaders } }
454
+ const headers = null
449
455
const result = await api.${ verb } <${ responseTypes } >("${ route } ", body, {headers})
450
456
return result.data
451
457
}
@@ -459,7 +465,7 @@ export const createHook = ({
459
465
};
460
466
export const ${ fetchName } = async (${ bodyProps } : ${ componentName } Params) => {
461
467
${ generateBodyProps ( ) }
462
- const headers = { ${ generateProps ( header ) } , ... ${ defaultHeaders } }
468
+ const headers = null
463
469
const params = {${ generateProps ( queryParams ) } }
464
470
const result = await api.${ verb } <${ responseTypes } >("${ route } ", body, {headers, params})
465
471
return result.data
0 commit comments