Skip to content

[BUG][JAVA][RestTemplate] Specified Accept header values generates uncompilable code #4222

@crosbyb

Description

@crosbyb
Description
openapi-generator version

4.1.0, 4.1.3

OpenAPI declaration file content or url

See the attached swagger contract for the full example.

        "parameters": [
          {
            "in": "header",
            "name": "Accept",
            "schema": {
              "enum": [
                "application/vnd.geo+json",
                "text/csv"
              ]
            },
            "required": true
          }
        ],
Command line used for generation

swagger-client-config.json:

{
  "modelPackage": "sc.v0.client.model",
  "apiPackage": "svc.v0.client",
  "library": "resttemplate",
  "groupId": "api.clients",
  "artifactId": "svc-client",
  "artifactVersion": "0.0.1"
}

java -jar ./codegen.jar generate -c ./swagger-client-config.json -i ./swagger.json -g java -o client/

Steps to reproduce
mkdir client
java -jar ./codegen.jar generate -c ./swagger-client-config.json  -i ./swagger.json -g java -o client/
cd client/ && mvn install  -q -Dmaven.test.skip=true -Dmaven.javadoc.skip=true && cd ..

You'll see the following error when Maven tries to compile:

[ERROR] /Users/brad/tmp/openapi-accept/client/src/main/java/svc/v0/client/ServiceApi.java:[77,31] variable accept is already defined in method getAllThings(java.lang.String)

There is already a local variable in the method named accept, so adding the accept header as an argument to the method creates the conflict.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions