[REQ][jaxrs-spec] Config option to generate StreamingOutput instead of File as response type
Created by: kariem
Instead of using java.io.File as response type, I would like the generator to use javax.ws.rs.core.StreamingOutput. Except for actually serving files, this option would simplify implementation and improve performance by wrapping an OutputStream.
Solution
It would be great to add a configuration option similar to returnResponse:
Name: returnStreamingOutput or returnStreamingOutputForBinary
Description: Whether the generated API interface should return javax.ws.rs.core.StreamingOutput instead of java.util.File for a binary response type.
Alternatives
I currently extend JavaJAXRSSpecServerCodegen and override importMapping and typeMapping. These are actually only two lines of code. See this response on StackOverflow for the details and more context.
Additional context
I currently use jaxrs-spec generator with the following settings (via maven plugin, formatted for readability):
| Name | Value |
|---|---|
| hideGenerationTimestamp | true |
| interfaceOnly | true |
| useSwaggerAnnotations | false |
A schema definition of something like this
/{id}:
get:
summary: Get the given document as PDF
operationId: getDocument
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
200:
description: Get the PDF document
content:
application/pdf:
schema:
type: string
format: binary
will generate a java interface with this method
@GET
@Path("/{id}")
@Produces({"application/pdf"})
File getDocument(@PathParam("id") String id)
I would prefer this
@GET
@Path("/{id}")
@Produces({"application/pdf"})
StreamingOutput getDocument(@PathParam("id") String id)