[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