Skip to content

[FEAT] [java] [resttemplate] Support file abstraction in response body #13146

Closed
@LubomirS

Description

@LubomirS

Is your feature request related to a problem? Please describe.

I would like to be able to use Resource as the return type for my rest template client operation instead of File, when using application/octet-stream with format binary.
Here's a snippet of the openapi spec:

"responses": {
  "200": {
    "description": "OK",
    "content": {
      "application/octet-stream": {
        "schema": {
          "type": "string",
          "format": "binary"
        }
      }
    }
  }
}

Similar feature is already present for request parameters, where using config option useAbstractionForFiles = true the generated method will have this signature:
ResponseEntity<void> sendFile(org.springframework.core.io.Resource _file)

Describe the solution you'd like

I would like to use config option useAbstractionForFiles = true to generate client method like such:

ResponseEntity<org.springframework.core.io.Resource> getFile()

instead of:

ResponseEntity<java.io.File> getFile()

The solution should probably be using mustache templates to override the responseType in api.mustache when isResponseFile and useAbstractionForFiles are present in operation properties, similar to how it's done for requests params. #7567

Describe alternatives you've considered

I tried to use File as the response entity and it works. But the drawback is that for each invocation, there is a risk that the file will stay on the file system because of some error and I would like to avoid that.

Similar feature has been requested for okhttp-gson client, where the proposed solution is to use InputStream. However, to keep the implementation consistent with the request parameter, which uses Resource, I believe that's a better solution to chose. #11933

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions