Open Askeiter opened 2 years ago
I finally had to do a mix with the code generated by openapi and make a javascript fetch call for it to work correctly
let url = customForecatApi.apiClient.buildUrl(
'/custom-forecast/{hotelId}/excel',
{
hotelId: this.$root.hotelId,
},
null
)
let auth = customForecatApi.apiClient.authentications['bearer-token']
let token = typeof auth.accessToken === 'function' ? auth.accessToken() : auth.accessToken
fetch(url, {
method: 'GET',
headers: new Headers({
Authorization: 'Bearer ' + token,
accept: 'application/octet-stream',
}),
})
.then((response) => {
return response.blob()
})
.then((blob) => {
var url = window.URL.createObjectURL(blob)
var a = document.createElement('a')
a.href = url
a.download = `customForecastFromHotel${this.$root.hotelId}.xlsx`
document.body.appendChild(a) // we need to append the element to the dom -> otherwise it will not work in firefox
a.click()
a.remove() //afterwards we remove the element again
})
If I use the generated code from openapi, the response is a text that I have not been able to save correctly as an xlxs
I can confirm we are hitting the exact same issue which makes it impossible to make multipart/form-data requests with any kind of file/buffer or binary data, which is a pretty severe bug.
I think this is the same issue I have trying to serve mp3 files..
Bug Report Checklist
Description
I am trying to download an xlsx file, generating the client api for a vuejs v2 project, but the autogenerated response type is not processed by the generated client api class
openapi-generator version
I have updated to the latest version of "@openapitools/openapi-generator-cli": "^2.5.2",
OpenAPI declaration file content or url
Generation Details
To generate the code, run the following command
node node_modules/@openapitools/openapi-generator-cli/main.js generate -i openapi.json -o src/openapi/ -g javascript -c openapi-generator-config.json
Steps to reproduce
the previous command generates the api class to call back the method to obtain the file declares that the response type is a File type the only statement i could find is the one shown below that extends blob
when I execute the call it ends up calling the ApiClient class
In this class, nothing is done with the return type defined and it delegates the transformation of the response to the deserialize method.
but this engine is unable to infer the type and ends up returning the response.text
Suggest a fix
I understand that if the code generator says that the return type is a file, take that into account, or allow for the expected type as an optional parameter when generating the calling method.