【发布时间】:2022-08-09 20:55:21
【问题描述】:
您好我正在使用 OpenAPI Generator Maven 插件生成一些 Java 客户端代码(使用 Spring WebClient 库)。我的规范的端点之一。返回二进制内容,例如:
\"schema\": {
\"type\": \"string\",
\"format\": \"binary\"
}
生成的代码使用 java.io.File 作为返回类型,例如:
public Mono<ResponseEntity<File>> downloadWithHttpInfo(String filename) throws WebClientResponseException {
ParameterizedTypeReference<File> localVarReturnType = new ParameterizedTypeReference<File>() {};
return downloadRequestCreation(filename).toEntity(localVarReturnType);
}
调用此生成的方法时,响应代码为 200(即来自服务器端的 OK),但我的客户端代码中出现以下错误:
org.springframework.web.reactive.function.UnsupportedMediaTypeException:
Content type \'application/octet-stream\' not supported for bodyType=java.io.File
这来自 toEntity() 方法,它是 Spring WebClient 代码的一部分,而不是我的代码。
有没有办法解决这个问题? A:指示OpenAPI Generator Maven Plugin不要使用java.io.File类型而是使用Resource类型? B: 以某种方式让 WebClient 能够将 application/octet-stream 解码为java.io.File?
标签: java spring-webflux spring-webclient openapi-generator openapi-generator-maven-plugin