OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVASCRIPT] Response type File no work

Open
#13,947 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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
image
the only statement i could find is the one shown below that extends blob
image

when I execute the call it ends up calling the ApiClient class
image

In this class, nothing is done with the return type defined and it delegates the transformation of the response to the deserialize method.

image

but this engine is unable to infer the type and ends up returning the response.text
image
image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.