I am using swagger-codegen-maven-plugin to generate Spring interface from OpenAPI file (OpenAPI 3.0.2)
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.14</version>
The response of one rest API should be PDF file
components:
schemas:
contractFile:
type: string
format: binary
Generated Java REST interface then contains the following method
default ResponseEntity<File> getContract(@ApiParam(value = "File to download",required=true) @PathVariable("uid") String uid) {
...
}
File class represents the path to the filesystem, but I don't have the file on the filesystem, just bytes in java memory and I don't want to save them as the file to disk.
I want getContract to return some StreamResource or some other representation of file from Stream/bytes in memory. Is it possible this via swagger-codegen-maven-plugin or some other option?
In the end, I switched from
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.14</version>
...
</plugin>
to
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.3</version>
...
</plugin>
This plugin got it right and generates Resource instead of ResponseEntity
Try something like this:
responses:
'200':
description: A PDF file
content:
application/pdf:
schema:
type: string
format: binary
maybe you could try something like this
/myendpoint:
get:
tags: [myendpint]
summary: my cool endpoint
operationId: getStuff
x-custom-return-type: 'java.something.stream.Stream'
than use mustache and specify it in mustache file with vendor extensions
ResponseEntity<{{#responseWrapper}}{{
.}}<{{/responseWrapper}}{{>returnTypes}}{{#vendorExtensions.x-custom-return-type}}
I use that for interface API and maybe somehow you could use it in your case too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With