forked from loafle/openapi-generator-original
[Java] enum space value must not be generated as underscore (#13136)
* [Java] enum space value must not be generated as underscore as this is invalid in Java 9 this closes #9607 * script changes Co-authored-by: Sven Meier <sven@meiers.net>
This commit is contained in:
@@ -1536,6 +1536,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return getSymbolName(value).toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
if (" ".equals(value)) {
|
||||
return "SPACE";
|
||||
}
|
||||
|
||||
// number
|
||||
if ("Integer".equals(datatype) || "Long".equals(datatype) ||
|
||||
"Float".equals(datatype) || "Double".equals(datatype) || "BigDecimal".equals(datatype)) {
|
||||
|
||||
@@ -55,6 +55,14 @@ public class AbstractJavaCodegenTest {
|
||||
Assert.assertEquals(fakeJavaCodegen.toEnumVarName("_,.", "String"), "__");
|
||||
}
|
||||
|
||||
/**
|
||||
* As of Java 9, '_' is a keyword, and may not be used as an identifier.
|
||||
*/
|
||||
@Test
|
||||
public void toEnumVarNameShouldNotResultInSingleUnderscore() throws Exception {
|
||||
Assert.assertEquals(fakeJavaCodegen.toEnumVarName(" ", "String"), "SPACE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toVarNameShouldAvoidOverloadingGetClassMethod() throws Exception {
|
||||
Assert.assertEquals(fakeJavaCodegen.toVarName("class"), "propertyClass");
|
||||
|
||||
Reference in New Issue
Block a user