OpenAPITools / OpenAPITools/openapi-generator
[BUG] Unable to get response headers using Java Webclient client
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
We have an openapi file (validated) that declares response headers, e.g.
"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."
}
}
},
Using java webclient client generated by this project, the return type of the invocations are not including response headers, nor the invokeAPI methods in ApiClient class does give access to the response headers.
Indeed the ApiClient invoke methods are returning a Mono/Flux of the return type, thus no permitting to get response headers
public <T> Mono<T> invokeAPI(String path, HttpMethod method, Map<String, Object> pathParams, MultiValueMap<String, String> queryParams, Object body, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams, MultiValueMap<String, 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);
}
As far as I know, the only way to have access to response headers using Weclient is calling toEntity method instead the bodyToMono.
Am I missing something?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Java ApiClient.invokeAPI method and its requestBuilder.retrieve().bodyToMono(returnType) flow. Trace how response headers declared in the OpenAPI response are represented in the generated client, then verify that an invocation exposes both the response body and headers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100