Typescript axios generators does not handle correctly multipart requests. Content-Type header is never set.
4.0.0-beta3
openapi: 3.0.0
paths:
'upload':
post:
summary: Upload File
description: ''
operationId: uploadFile
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/logoForCreation'
encoding:
medicalCertificateFileName:
contentType: image/png, image/jpeg
required:
true
description: body
responses:
201:
description: Created or updated club's logo
content:
application/json:
schema:
$ref: '#/components/schemas/photo'
components:
schemas:
logoForCreation:
type: object
required:
- logoFileName
properties:
logoFileName:
type: string
format: binary
photo:
required:
- location
properties:
location:
type: string
openapi-generator generate -i swagger.yaml -g typescript-axios -o src/generated --skip-validate-spec
Run the above command with the included yaml
Notice that the following expected line is missing:
localVarHeaderParameter['Content-Type'] = 'multipart/form-data';
multipartFormData mustache is used without vendorExtensions so it's not detected
馃憤 Thanks for opening this issue!
馃彿 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
Before this issue PR, My test case is correct, but after that, I got an error of
error:"Internal Server Error"
message:"Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found"
path:"/rest/s/oem-configure/update"
status:500
timestamp:"2019-08-13 04:21:44"
There are someone saids the headers will auto set;
https://stackoverflow.com/questions/17415084/multipart-data-post-using-python-requests-no-multipart-boundary-was-found
the SO answer relates to python.
In https://stackoverflow.com/questions/41878838/how-do-i-set-multipart-in-axios-with-react the and https://github.com/axios/axios/issues/318#issuecomment-218948420 content type is automatically set when using FormData
@vellengs would you like to file a PR that removes https://github.com/OpenAPITools/openapi-generator/pull/2695/files#diff-d270de95051055e6c877f904c360ecadR175 ?
@nicokoenig can you help here?
this one is important to consider:
https://github.com/axios/axios/issues/318#issuecomment-444827876
if on nodejs side should use form.getHeaders() otherwise browser side will auto set.
because correct headers should like
'content-type':
'multipart/form-data; boundary=--------------------------671856582217525463534855'
https://github.com/axios/axios/issues/1006#issuecomment-320165427
Might use
if((localVarFormParams as any).getHeaders){
localVarHeaderParameter['Content-Type'] = (localVarFormParams as any).getHeaders();
}
instead of
localVarHeaderParameter['Content-Type'] = 'multipart/form-data';
Currently it should be like this:
if((localVarFormParams as any).getHeaders){
Object.assign(localVarHeaderParameter, (<any>localVarFormParams).getHeaders());
}
else {
localVarHeaderParameter['Content-Type'] = 'multipart/form-data';
}
Most helpful comment
Might use
instead of