openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [JAVA] [Client] Using different Content Types results in Accept Header [Ljava.lang.String;@XXXXXXXX

Open manuelnagler opened this issue 1 year ago • 4 comments

Description

Regression in 7.5.0: Using different Content Types results in Accept Header generated as [Ljava.lang.String;@XXXXXXXX

openapi-generator version

Broken since 7.5.0. 7.4.0 works as expected

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  title: Demo
  version: "1"
paths:
  /demo:
    post:
      requestBody:
        content:
          application/text:
            schema:
              type: string
      responses:
        '200':
          description: demo
          content:
            application/pdf:
              schema:
                type: string
                format: byte
        '500':
          description: demo
          content:
            application/text:
              schema:
                type: string
Steps to reproduce

Generate e.g. a feign client from the spec.

Result:

@RequestLine("POST /demo")
@Headers({
    "Content-Type: application/text",
    "Accept: [Ljava.lang.String;@7d0332e1",
})
byte[] demoPost(String body);

Expected:

@RequestLine("POST /demo")
@Headers({
    "Content-Type: application/text",
    "Accept: application/pdf,application/text",
})
byte[] demoPost(String body);

The Accept Header is not serialized properly into the generated interface.

manuelnagler avatar May 07 '24 06:05 manuelnagler

looks like it's related to https://github.com/OpenAPITools/openapi-generator/pull/18092

@larsenf-els can you please take a look when you've time?

wing328 avatar May 07 '24 08:05 wing328

Yeah, facing same issue

yasstec avatar May 16 '24 06:05 yasstec

@manuelnagler @wing328 @yasstec: I will have a look.

larsenf-els avatar May 16 '24 07:05 larsenf-els

@manuelnagler @yasstec

I cannot reproduce the issue you are facing. I may need some additional information, and it could be due to me calling the wrong Feign client generator?

I created a small project here at GitHub that uses Gradle to call the OpenAPI Generator 7.5.0 on the provided OpenAPI specification file used for producing the error:

https://github.com/larsenf-els/feign-openapi-generator-test

Hava a look at the build.gradle.kts file. It generates this file: /feign-openapi-generator-test/build/generated/src/main/java/org/openapitools/client/api/DefaultApi.java

package com.example.api;

import com.example.invoker.ApiClient;
import com.example.invoker.EncodingUtils;
import com.example.model.ApiResponse;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import feign.*;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-05-17T10:57:18.694179+02:00[Europe/Copenhagen]", comments = "Generator version: 7.5.0")
public interface DefaultApi extends ApiClient.Api {


  /**
   * 
   * 
   * @param body  (optional)
   * @return byte[]
   */
  @RequestLine("POST /demo")
  @Headers({
    "Content-Type: application/text",
    "Accept: application/pdf,application/text",
  })
  byte[] demoPost(String body);

  /**
   * 
   * Similar to <code>demoPost</code> but it also returns the http response headers .
   * 
   * @param body  (optional)
   * @return A ApiResponse that wraps the response boyd and the http headers.
   */
  @RequestLine("POST /demo")
  @Headers({
    "Content-Type: application/text",
    "Accept: application/pdf,application/text",
  })
  ApiResponse<byte[]> demoPostWithHttpInfo(String body);


}

larsenf-els avatar May 17 '24 09:05 larsenf-els

I noticed, that your initial pullrequest includes this change: https://github.com/OpenAPITools/openapi-generator/pull/18092/files#diff-d50fdea014963dc2aad9184a546a9005256203dce025f8b43255dd35aa3197ee

We were using a local copy of the api.mustache which we forgot to update. This issue is resolved.

manuelnagler avatar May 23 '24 08:05 manuelnagler

I noticed, that your initial pullrequest includes this change: https://github.com/OpenAPITools/openapi-generator/pull/18092/files#diff-d50fdea014963dc2aad9184a546a9005256203dce025f8b43255dd35aa3197ee

We were using a local copy of the api.mustache which we forgot to update. This issue is resolved.

@manuelnagler Thank you for the follow-up. :smile::+1:

larsenf-els avatar May 24 '24 05:05 larsenf-els