OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java][jersey2] ApiClient.setUserAgent does not set userAgent
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Error Prone fails compilation of project which includes generated ApiClient.java with error:
[SelfAssignment] Variable assigned to itself
(see https://errorprone.info/bugpattern/SelfAssignment)
Did you mean 'this.userAgent = userAgent;'?
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2021-02-12T13:57:28.286366700+01:00[Europe/Paris]")
public class ApiClient {
...
protected String userAgent;
...
/**
* Set the User-Agent header's value (by adding to the default header map).
* @param userAgent Http user agent
* @return API client
*/
public ApiClient setUserAgent(String userAgent) {
userAgent = userAgent;
addDefaultHeader("User-Agent", userAgent);
return this;
}
...
openapi-generator version
openapi-generator-maven-plugin version 5.0.1
Steps to reproduce
Generate a Java jerrsey2 client using the following configuration
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.0.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/vdx-swagger.yaml</inputSpec>
<generatorName>java</generatorName>
<library>jersey2</library>
<modelNamePrefix>Vdx</modelNamePrefix>
<modelPackage>dk.sundhed.ehealth.futvdx2fhir.api.model</modelPackage>
<generateApis>false</generateApis>
<generateModelTests>false</generateModelTests>
<output>${project.build.directory}/generated-sources</output>
<configOptions>
<dateLibrary>legacy</dateLibrary>
<caseInsensitiveResponseHeaders>true</caseInsensitiveResponseHeaders>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Suggest a fix
/**
* Set the User-Agent header's value (by adding to the default header map).
* @param userAgent Http user agent
* @return API client
*/
public ApiClient setUserAgent(String userAgent) {
this.userAgent = userAgent;
addDefaultHeader("User-Agent", userAgent);
return this;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Java jersey2 generator templates or entry points that produce ApiClient.java, using the provided Maven configuration to reproduce the generated setter. Confirm that the generated method assigns the instance field rather than the parameter to itself, then regenerate a client and verify the resulting Java source compiles without the Error Prone SelfAssignment error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100