Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][JAVA][RESTTEMPLATE] Name conflict when using parameter named Content-Type #9566

Closed
4 of 6 tasks
desmese opened this issue May 24, 2021 · 0 comments · Fixed by #9568
Closed
4 of 6 tasks

[BUG][JAVA][RESTTEMPLATE] Name conflict when using parameter named Content-Type #9566

desmese opened this issue May 24, 2021 · 0 comments · Fixed by #9568

Comments

@desmese
Copy link
Contributor

desmese commented May 24, 2021

Bug Report Checklist

Description

I tried to generate a new client using the java resttemplate library. The OpenAPI specification I am using has got a header specified which is named 'Content-Type'. The generated parameter is called contentType. This clashes with the contentType variable defined in the api.mustache. The local variable should have got the localVar prefix.

openapi-generator version

5.1.1

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  title: Hello World
  version: "1.0"
servers:
  - url: http://localhost:9090/v1.0

paths:
  /greeting:
    get:
      summary: Generate greeting
      description: Generates a greeting message.
      operationId: hello.post_greeting
      responses:
        200:
          description: greeting response
          content:
            text/plain:
              schema:
                type: string
                example: "hello dave!"
      parameters:
        - name: Content-Type
          in: header
          description: Name of the person to greet.
          required: true
          schema:
            type: string
            example: "dave"
Generation Details

I am generating the client using the openapi-generator-maven-plugin. The bug however is found in the template, so it should shall exists in all generators.

    <build>
        <plugins>
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <!-- RELEASE_VERSION -->
                <version>5.1.0</version>
                <!-- /RELEASE_VERSION -->
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
                            <generatorName>java</generatorName>
                            <library>resttemplate</library>
                            <configOptions>
                                <dateLibrary>java8</dateLibrary>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
Steps to reproduce

The bug can be reproduced by generating a client using the java generator and the resttemplate library. You could use the above configuration for the maven-plugin, and the openapi file specified above.

Related issues/PRs

#9565

Suggest a fix

I created a PR which adds the localVar prefix before the local variable called contentType. I will link it to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant