[BUG][JAVA][RESTTEMPLATE] Name conflict when using parameter named Content-Type
Created by: desmese
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? I noticed #9565 (closed) too late, because i started working on the bugfix yesterday, and didn't search again for new issues today. -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
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
https://github.com/OpenAPITools/openapi-generator/issues/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.