-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Milestone
Description
Description
At the moment it is not possible to actually send multipart/form-data requests using generated code with the typescript-angular2 generator as it will always call formParams.toString() for the body contents which will always result in [object FormData] in the actual request.
Swagger-codegen version
v2.3.0
Swagger declaration file content or url
Problematic file: swagger-codegen/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache
Problematic lines:
let formParams = new (useForm ? FormData : URLSearchParams as any)() as {
set(param: string, value: any): void;
};
...
{{#hasFormParams}}
body: formParams.toString(),
{{/hasFormParams}}Steps to reproduce
- Create an API service which can upload files
- Generate the API client as usual using typescript-angular2 template
- Try to use the Service with a file
=> Request will show up with [object FormData] in the body
Suggest a fix/enhancement
Angulars HTTP handling of forms is actually pretty smart. I think simply changing the line to the following works.
{{#hasFormParams}}
body: useForm ? formParams : formParams.toString(),
{{/hasFormParams}}magnusbakken and macjohnny