[英]How to customise the body type of response entity in OpenAPI?
I am working on a Spring project that allows users to download CSV files from an endpoint.我正在开发一个 Spring 项目,该项目允许用户从端点下载 CSV 文件。
OpenAPI Generator is used for code generation. OpenAPI Generator 用于代码生成。 According to the "Response That Returns a File" section of the documentation , the schema for the response can be defined as
type: string
with format: binary
.根据文档的“返回文件的响应”部分,响应的架构可以定义为
type: string
和format: binary
。 The generated interface would then be something like: CompletableFuture<ResponseEntity<org.springframework.core.io.Resource>> downloadFile()
.生成的界面将类似于:
CompletableFuture<ResponseEntity<org.springframework.core.io.Resource>> downloadFile()
。
How can we specify an alternative body type for ResponseEntity
?我们如何为
ResponseEntity
指定替代的主体类型? (eg StreamingResponseBody
described in this blog ) (例如本博客中描述的
StreamingResponseBody
)
The OpenAPI Generator has a configuration option named typeMappings
which allows you to change the default mapping of OpenApi primitive types (such as array, float, etc...) to the corresponding java class (java.util.List, Float, ...). OpenAPI 生成器有一个名为
typeMappings
的配置选项,它允许您将 OpenApi 基本类型(例如数组、浮点数等)的默认映射更改为相应的 java class (java.util.List, Float, ... )。
In your particular case, you could try to map the "binary" type to something different from "java.util.File".在您的特定情况下,您可以尝试将“二进制”类型 map 转换为与“java.util.File”不同的东西。
The default mappings are defined here - see as from line 1464默认映射在此处定义 - 参见第 1464 行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.