Open ddurham2 opened 4 years ago
Hello, This is related to the fix for bug [#2733]
For the typescript-angular generator, there is an additional issue with the code generated, when using a multipart/form-data object.
I'm using the latest version as of this writing
Declare a POST method with the following requestBody:
'/test/upload': post: requestBody: content: multipart/form-data: schema: type: object properties: foo: type: object properties: f1: type: string f2: type: string fileUpload: type: string format: binary
The generated service works, but the request body's foo object has a filename.
------WebKitFormBoundaryVXPcUvxGz0M5kWFb Content-Disposition: form-data; name="foo"; filename="blob" Content-Type: application/json ...
The problem is that filename="blob" value. It is making some backends think I'm uploading a file here.
The generated code looks something like:
formParams = formParams.append('foo', useForm ? new Blob([JSON.stringify(foo)], { type: 'application/json' }) : foo) || formParams;
Blob() is naming itself "blob", but the problem for these backends goes away when I change the generated code to:
formParams = formParams.append('foo', useForm ? new Blob([JSON.stringify(foo)], { type: 'application/json' }) : foo, "") || formParams;
... where I have explicitly given an empty filename to the append() method.
The request body now looks like
------WebKitFormBoundaryVXPcUvxGz0M5kWFb Content-Disposition: form-data; name="foo"; filename="" Content-Type: application/json ...
Otherwise, how is a backend to know whether it's to pass a real file on disk (named "blob") to the handler or an in memory object?
I'll be glad to take a stab at creating a PR unless there are obvious objections to making such a change.
What is the state of this bug? Is there a workaround? Is there a property to set?
https://github.com/OpenAPITools/openapi-generator/blob/69e72203aeca023cb2f3bd392d3c080af6e2a0fe/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache#L353C15-L353C15
why do you parse the object as Blob if the type is a Model? why not just JSON.stringify it?
Hello, This is related to the fix for bug [#2733]
For the typescript-angular generator, there is an additional issue with the code generated, when using a multipart/form-data object.
I'm using the latest version as of this writing
Declare a POST method with the following requestBody:
The generated service works, but the request body's foo object has a filename.
The problem is that filename="blob" value. It is making some backends think I'm uploading a file here.
The generated code looks something like:
Blob() is naming itself "blob", but the problem for these backends goes away when I change the generated code to:
... where I have explicitly given an empty filename to the append() method.
The request body now looks like
Otherwise, how is a backend to know whether it's to pass a real file on disk (named "blob") to the handler or an in memory object?
I'll be glad to take a stab at creating a PR unless there are obvious objections to making such a change.