OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA][Native] Variable already exists (Exception variable)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
While generating for Java native we get an invalid code, which looks like this:
public ApiResponse<Void> collectGetWithHttpInfo(..., String e, ...) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = collectGetRequestBuilder(..., e, ...);
try {
HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("collectGet", localVarResponse);
}
return new ApiResponse<Void>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
null
);
} finally {
// Drain the InputStream
while (localVarResponse.body().read() != -1) {
// Ignore
}
localVarResponse.body().close();
}
} catch (IOException e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}
As you can see there is a method parameter "e" and the Exceptions "e" which hold the same name.
openapi-generator version
7.1.0
OpenAPI declaration file content or url
Our spec contains something like:
...
{
"in": "query",
"name": "e",
"required": true,
"schema": {
"type": "string",
"enum": [
"conversion:summary",
"conversion:item"
]
}
},
...
Generation Details
Steps to reproduce
configuration looks as follows:
<execution>
<id>some-service</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>openapi.json</inputSpec>
<generatorName>java</generatorName>
<skipValidateSpec>true</skipValidateSpec>
<library>native</library>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<configOptions>
<dateLibrary>legacy</dateLibrary>
<sourceFolder>src/gen/java/main</sourceFolder>
<packageName>ch.x.y</packageName>
<apiPackage>ch.x.y</apiPackage>
<modelPackage>ch.x.y.model</modelPackage>
<invokerPackage>ch.x.y</invokerPackage>
</configOptions>
</configuration>
</execution>
Suggest a fix
Give exceptions an unique name within the block or give everything else an prefix.
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
Reproduce the issue with an OpenAPI query parameter named e and the Java generator using the native library. Inspect the Java native generator's exception and parameter naming logic, then verify that generated methods compile and that a regression test covers the conflicting name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100