orval: Wrong code gets generated with array of formData fields
What are the steps to reproduce this issue?
- Generate code with a swagger.json that has a formData field of an array type
"parameters": [
{
"type": "array",
"items": {
"type": "string"
},
"description": "Image to upload",
"name": "image",
"in": "formData",
"required": true
}
]
What happens?
The following code gets generated
export const meAvatarUpload = <TData = WebMediaUploadResponse[]>(
meAvatarUploadBody: MeAvatarUploadBody,
options?: SecondParameter<typeof customInstance>) => {const formData = new FormData();
formData.append('image', JSON.stringify(meAvatarUploadBody.image)
// ^ this is wrong, both because of the JSON.stringify() approach and because of the missing closing paren.
return customInstance<TData>(
{url: `/me/media`, method: 'post',
data: formData
},
// eslint-disable-next-line
// @ts-ignore
options);
}
What were you expecting to happen?
The following code to be generated instead
export const meAvatarUpload = <TData = WebMediaUploadResponse[]>(
meAvatarUploadBody: MeAvatarUploadBody,
options?: SecondParameter<typeof customInstance>) => {const formData = new FormData();
meAvatarUploadBody.image.forEach(image => formData.append('image', image))
// Manually editing the code makes it work
return customInstance<TData>(
{url: `/me/media`, method: 'post',
data: formData
},
// eslint-disable-next-line
// @ts-ignore
options);
}
What versions are you using?
Operating System: macOS 11.5 Package Version: 5.5.2 Browser Version: 92.0.4515.107
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (15 by maintainers)
fixed with
6.2.4
In version 6, I will add a way to override the default generation (I am currently working on it on the next branch)