我使用swagger-codegen-maven-plugin从OpenAPI文件(OpenAPI 3.0.2)生成Spring接口。
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.14</version>一个rest的响应应该是PDF文件。
components:
schemas:
contractFile:
type: string
format: binary生成的Java接口包含以下方法
default ResponseEntity<File> getContract(@ApiParam(value = "File to download",required=true) @PathVariable("uid") String uid) {
...
}文件类表示文件系统的路径,但文件系统上没有文件,只有java内存中的字节,我不想将它们保存为磁盘文件。
我希望getContract从内存中的流/字节返回一些StreamResource或文件的其他表示形式。这有可能是通过swagger-codegen-maven-plugin还是其他选项实现的?
发布于 2020-02-20 16:42:32
最后,我从
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.14</version>
...
</plugin>至
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.3</version>
...
</plugin>这个插件正确地实现了它并生成了资源,而不是ResponseEntity
发布于 2020-02-18 19:13:40
试着做这样的事情:
responses:
'200':
description: A PDF file
content:
application/pdf:
schema:
type: string
format: binary发布于 2020-02-18 19:25:03
也许你可以试试这样的方法
/myendpoint:
get:
tags: [myendpint]
summary: my cool endpoint
operationId: getStuff
x-custom-return-type: 'java.something.stream.Stream'而不是使用胡子,并在带有供应商扩展的胡子文件中指定它。
ResponseEntity<{{#responseWrapper}}{{
.}}<{{/responseWrapper}}{{>returnTypes}}{{#vendorExtensions.x-custom-return-type}}我将它用于接口API,也许您也可以在您的情况下使用它。
https://stackoverflow.com/questions/60192594
复制相似问题