openapi-typescript
openapi-typescript copied to clipboard
feat: allow form data through default body serializer
I was trying to use openapi-fetch for file uploading, but by default that wasn't possible (using multipart/form-data). Looking at the source code I noticed that part of the solution for fixing it seemed to be missing as defaultBodySerializer never allows FormData to be passed through it:
if (requestInit.body) {
// Here, bodySerializer always returns a JSON string by default
requestInit.body = bodySerializer(requestInit.body);
// remove `Content-Type` if serialized body is FormData; browser will correctly set Content-Type & boundary expression
if (requestInit.body instanceof FormData) {
requestInit.headers.delete("Content-Type");
}
}
I'm trying to fix that in this PR by allowing FormData to be passed through the defaultBodySerializer enabling file uploads with multipart/form-data by default.
Changes
Allow FormData to be passed through defaultBodySerializer as body to enable file uploading by default.
How to Review
Upload a file as part of multipart/form-data
Checklist
- [ ] Unit tests updated
- [ ]
docs/updated (if necessary) - [ ]
pnpm run update:examplesrun (only applicable for openapi-typescript)