问题描述
我们有一个声明响应头的 openapi 文件(已验证),例如
"responses": {
"200": {
"description": "OK","schema": {
"type": "object","properties": {
"results": {
"type": "array","items": {
"$ref": "#/deFinitions/CourseV2"
}
},"paging": {
"$ref": "#/deFinitions/PagingInfo"
}
},"required": [
"results"
]
},"headers": {
"X-RateLimit-Limit": {
"type": "integer","description": "Request limit per hour."
},"X-RateLimit-Remaining": {
"type": "integer","description": "The number of requests left for the time window."
},"X-RateLimit-Reset": {
"type": "string","format": "date-time","description": "The UTC date/time at which the current rate limit window resets."
}
}
},
使用由 openapi-generator 项目(maven 或 cli)生成的 java webclient 客户端,调用的返回类型不包括响应头,apiclient 类中的 invokeAPI 方法也不提供对响应头的访问。 实际上,apiclient 调用方法正在返回返回类型的 Mono/Flux,因此不允许获取响应头
public <T> Mono<T> invokeAPI(String path,HttpMethod method,Map<String,Object> pathParams,MultiValueMap<String,String> queryParams,Object body,HttpHeaders headerParams,String> cookieParams,Object> formParams,List<MediaType> accept,MediaType contentType,String[] authNames,ParameterizedTypeReference<T> returnType) throws RestClientException {
final WebClient.RequestBodySpec requestBuilder = prepareRequest(path,method,pathParams,queryParams,body,headerParams,cookieParams,formParams,accept,contentType,authNames);
return requestBuilder.retrieve().bodyToMono(returnType);
}
据我所知,使用 Spring Webclient 访问响应标头的唯一方法是使用 toEntity 提供 ResponseEntity 方法(以及 .getHeaders)而不是 bodyToMono。
我错过了什么吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)