OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVASCRIPT] Response type File no work
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
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
{
"/custom-forecast/{hotelId}/excel":{
"get":{
"tags":[
"Custom Forecast"
],
"operationId":"getCustomForecastByHotelId",
"parameters":[
{
"name":"hotelId",
"in":"path",
"required":true,
"schema":{
"type":"integer",
"format":"int32"
}
}
],
"responses":{
"200":{
"description":"OK",
"content":{
"application/octet-stream":{
"schema":{
"type":"string",
"format":"binary"
}
}
}
}
}
},
"put":{
"tags":[
"Custom Forecast"
],
"operationId":"updateCustomForecastByHotelId",
"parameters":[
{
"name":"hotelId",
"in":"path",
"required":true,
"schema":{
"type":"integer",
"format":"int32"
}
}
],
"requestBody":{
"content":{
"multipart/form-data":{
"schema":{
"required":[
"excel"
],
"type":"object",
"properties":{
"excel":{
"type":"string",
"format":"binary"
}
}
}
}
}
},
"responses":{
"200":{
"description":"OK"
}
}
}
}
}
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated JavaScript ApiClient and its deserialize method, using the supplied OpenAPI declaration and the generation command to reproduce the response handling. Trace the application/octet-stream response for the binary string schema and compare it with the generated File type. Done means the generated client returns the downloaded file data instead of response.text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100