[BUG] Java codegen does not check classVarName against reserved keywords
Created by: spacether
Description
The java client codegen does not check the classVarName variables agains the reserved list of keywords. Because of this, when I built the java rest-assured client sample, it generated a class method with the name default, which is a reserved keyword in java. My CircleCI test failure is here: https://circleci.com/gh/OpenAPITools/openapi-generator/4075#tests/containers/1 Generated ApiClient.java code
public DefaultApi default() {
return DefaultApi.default(config.baseReqSpec.get());
}
This is invalid Java code because default is a reserved keyword. Mustache file is here: modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/ApiClient.mustache
public {{classname}} {{classVarName}}() {
return {{classname}}.{{classVarName}}(config.baseReqSpec.get());
}
Java clients DO know about reserved keywords per here: modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
openapi-generator version
4.0.0-SNAPSHOT
OpenAPI declaration file content or url
openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml
Command line used for generation
./bin/java-petstore-rest-assured.sh
Steps to reproduce
Generate the above java rest-assured client. Then run the circleCi tests for node 1 from: CI/circle_parallel.sh
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/13
Suggest a fix
Note: I see a hard-coded in naming fix in the google-api-client mustache file: modules/openapi-generator/src/main/resources/Java/libraries/google-api-client/ApiClient.mustache
public {{classname}} {{classVarName}}Api() {
return new {{classname}}(this);
}
I will put in a hard coded fix, but adding a classVarName check against reserved keywords is a more robust way to fix this.