Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #13146
Closed
Open
Issue created Aug 10, 2022 by Administrator@rootContributor

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

Created by: 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. https://github.com/OpenAPITools/openapi-generator/pull/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. https://github.com/OpenAPITools/openapi-generator/issues/11933

Additional context

Assignee
Assign to
Time tracking