camunda-community-hub / camunda-platform-7-rest-client-java

Community extension to generate a Java client from the provided Camunda 7 OpenAPI descitpion and also warp it into Spring Boot
Apache License 2.0
61 stars 10 forks source link

HTTP 406 Not Acceptable on ExternalTaskApi.getExternalTaskErrorDetails() #75

Open mattiasgreen opened 1 year ago

mattiasgreen commented 1 year ago

Requests to ExternalTaskApi.getExternalTaskErrorDetails(externalTaskId) fail with HTTP 406 Not Acceptable due to accept header value incorrectly listing only "application/json". Correct value is "application/json, text/plain".

mattiasgreen commented 1 year ago

Snippet from generated selectHeaderAccept()

    public String selectHeaderAccept(String[] accepts) {
        if (accepts.length == 0) {
            return null;
        }
        for (String accept : accepts) {
            if (isJsonMime(accept)) {
                return accept;
            }
        }
        return StringUtil.join(accepts, ",");
    }

Snippet from generated getExternalTaskErrorDetailsCall()

        final String[] localVarAccepts = {
            "text/plain", "application/json"
        };
        final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);

Note that this results in localVarAccept variable value "application/json", instead of "text/plain, application/json"

mattiasgreen commented 1 year ago

Temporary local workaround is to patch this generated file, either by editing or overriding this method.

      final String[] localVarAccepts = {
            "text/plain", "application/json"
      };
      final String localVarAccept = StringUtil.join(localVarAccepts, ",");
mattiasgreen commented 1 year ago

Alternatives for permanent fix, top of my head:

  1. Raise issue and PR for OpenAPI Generator for this "special case" with accept headers and "application/json". In my opinion, this is clearly a bug. However, there may be many clients and solutions out there by now relying on this behavior, so it is unlikely this will be fixed upstream.
  2. Figure out how to automatically "patch" this behavior when generating the client. Perhaps by adding/injecting the workaround after generation. Seems hackish, but perhaps doable.
  3. Change Camunda REST API to only return "application/json" for both status 200 and 500. That is, wrap the error details in simple and flat JSON response.
  4. Figure out if Engine REST can disable the accept header check to avoid HTTP 406 and return. Seems like the worst of options, and I'm not clear if OpenAPI-generated client would even accept the response.
mattiasgreen commented 1 year ago

Found this open issue which is spot on. "[BUG][Go] Content type selection breaks when multiple content types present" https://github.com/OpenAPITools/openapi-generator/issues/10340