2

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"
            }
          }
        }
      }
    }
Olivier Gérardin
  • 1,113
  • 14
  • 27
  • PS: I also tried to extend the generated interface to add only my own method using Response return type, but OpenFeign only supports one level of inheritance, and the generated interface already extends ApiClient.Api. – Olivier Gérardin Jul 28 '20 at 12:31

0 Answers0