OpenAPI Generator : generate correct method profile for downloading binary file

Viewed 1244

I have a Swagger file (OAS 2) with an endpoint used to download a file. I'm using openapi-generator (through the Maven plugin) to generate Java / OpenFeign client code.

The problem is that this particular endpoint translates to:

 @RequestLine("GET /files/{id}/content")
 @Headers({
    "Accept: application/octet-stream",
 })
 File downloadByIdUsingGET(@Param("id") String id);

which returns null when invoked. According to this, the correct method profile should be:

 Response downloadByIdUsingGET(@Param("id") String id);

And indeed if I write the interface myself, with this method I can use:

Response downloadResponse = api.downloadByIdUsingGET(id);
InputStream downloadInputStream = downloadResponse.body().asInputStream();

So the question is: how can I configure the generator to use the Response type for this endpoint?

I have tried:

<typeMappings>file=feign.Response</typeMappings>

but this substitutes File type with Response everywhere, including in other endpoints where I don't want it, particularly (guess what) the upload endpoint, which is generated as:

  FileProperties uploadUsingPOST(@Param("file") File file);

and works fine like this.

Here's the relevant part of the Swagger file:

 "/files/{id}/content": {
      "get": {
        "produces": [
          "application/octet-stream"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "type": "string",
          }
        ],
        "responses": {
          "200": {
            "description": "Successful",
            "schema": {
              "type": "file"
            }
          }
        }
      }
    }
0 Answers
Related