简体   繁体   中英

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.

OpenAPI Generator is used for code generation. 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 . The generated interface would then be something like: CompletableFuture<ResponseEntity<org.springframework.core.io.Resource>> downloadFile() .

How can we specify an alternative body type for ResponseEntity ? (eg StreamingResponseBody described in this blog )

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, ...).

In your particular case, you could try to map the "binary" type to something different from "java.util.File".

The default mappings are defined here - see as from line 1464

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM