OpenAPITools / OpenAPITools/openapi-generator

[BUG] Unable to get response headers using Java Webclient client

Open
#9,418 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.