Reputation: 2563
I have a method which returns an InputStream as an InputStreamResource, when I let swagger generate the documentation it says the return type is InputStreamResource. How do I change this so the return type in the documentation is the InputStream?
@ApiOperation()
@RequestMapping(value = "/item/{id}", produces = "application/octet-stream", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getStream(
@PathVariable(value = "id") String id,
HttpServletResponse response
) {
InputStream stream = null;
try {
stream = getData(id);
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(new InputStreamResource(stream));
} catch (Exception e) {
IOUtils.closeQuietly(stream);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return null;
}
}
Upvotes: 2
Views: 2964
Reputation: 6824
Well I don't think returning an InputStream
will add much value to your consumers. Inside the input stream is data, and that's what they are going to care about the most. Using InputStream may indeed offload the burden of serving from your servlet context but the end of the day, consumers don't care.
Can you model the data instead? Is it a string or a complex object? Maybe a byte array? That would be best to describe.
Upvotes: 1
Reputation: 963
Try this :
@ApiOperation(response = InputStream.class)
According to the documentation :
response : default response class from the operation
Upvotes: 1