Add missing underscores for PascalCase enum values #4837 (#18594)

Co-authored-by: Renato Mameli <renato.mameli@teamviewer.com>
This commit is contained in:
Renato Mameli 2024-05-21 09:29:34 +02:00 committed by GitHub
parent 9398c6444a
commit bfa26ea6be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
58 changed files with 65 additions and 58 deletions

View File

@ -2055,7 +2055,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
}
// string
String var = value.replaceAll("\\W+", "_").toUpperCase(Locale.ROOT);
String var = underscore(value.replaceAll("\\W+", "_")).toUpperCase(Locale.ROOT);
if (var.matches("\\d.*")) {
var = "_" + var;
}

View File

@ -61,6 +61,13 @@ public class AbstractJavaCodegenTest {
Assert.assertEquals(fakeJavaCodegen.toEnumVarName("==", "String"), "u");
}
@Test
public void toEnumVarNameAddUnderscoresIfValueIsPascalCase() {
Assert.assertEquals(fakeJavaCodegen.toEnumVarName("OnlyCamelCase", "String"), "ONLY_CAMEL_CASE");
Assert.assertEquals(fakeJavaCodegen.toEnumVarName("WithNumber1", "String"), "WITH_NUMBER1");
Assert.assertEquals(fakeJavaCodegen.toEnumVarName("_LeadingUnderscore", "String"), "_LEADING_UNDERSCORE");
}
@Test
public void toVarNameShouldAvoidOverloadingGetClassMethod() throws Exception {
Assert.assertEquals(fakeJavaCodegen.toVarName("class"), "propertyClass");

View File

@ -19,7 +19,7 @@
| Name | Value |
|---- | -----|
| SOMEOBJIDENTIFIER | &quot;SomeObjIdentifier&quot; |
| SOME_OBJ_IDENTIFIER | &quot;SomeObjIdentifier&quot; |
## Implemented Interfaces

View File

@ -59,7 +59,7 @@ public class SomeObj implements Serializable {
*/
@JsonAdapter(TypeEnum.Adapter.class)
public enum TypeEnum {
SOMEOBJIDENTIFIER("SomeObjIdentifier");
SOME_OBJ_IDENTIFIER("SomeObjIdentifier");
private String value;
@ -106,7 +106,7 @@ public class SomeObj implements Serializable {
public static final String SERIALIZED_NAME_$_TYPE = "$_type";
@SerializedName(SERIALIZED_NAME_$_TYPE)
private TypeEnum $type = TypeEnum.SOMEOBJIDENTIFIER;
private TypeEnum $type = TypeEnum.SOME_OBJ_IDENTIFIER;
public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -31,7 +31,7 @@ public class ParentWithNullable {
public enum TypeEnum {
CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));
String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -31,7 +31,7 @@ public class ParentWithNullable {
public enum TypeEnum {
CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));
String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -31,7 +31,7 @@ public class ParentWithNullable {
public enum TypeEnum {
CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));
String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -55,7 +55,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDCAT | &quot;ChildCat&quot; |
| CHILD_CAT | &quot;ChildCat&quot; |

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDCAT | &quot;ChildCat&quot; |
| CHILD_CAT | &quot;ChildCat&quot; |

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDCAT | &quot;ChildCat&quot; |
| CHILD_CAT | &quot;ChildCat&quot; |

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -53,7 +53,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -62,7 +62,7 @@ public class ParentWithNullable {
@XmlEnum(String.class)
public enum TypeEnum {
@XmlEnumValue("ChildWithNullable")
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -53,7 +53,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |

View File

@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -39,7 +39,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -40,7 +40,7 @@ public class ParentWithNullableDto {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -16,7 +16,7 @@
| Name | Value |
|---- | -----|
| CHILDCAT | &quot;ChildCat&quot; |
| CHILD_CAT | &quot;ChildCat&quot; |

View File

@ -41,7 +41,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -41,7 +41,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -41,7 +41,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -31,7 +31,7 @@ public class ParentWithNullable {
public enum TypeEnum {
CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));
private String value;

View File

@ -18,7 +18,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -31,7 +31,7 @@ public class ParentWithNullable {
public enum TypeEnum {
CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));
private String value;

View File

@ -43,7 +43,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class ParentWithNullable implements Serializable {
public enum TypeEnum {
CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));
private String value;

View File

@ -28,7 +28,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class ParentWithNullable implements Serializable {
public enum TypeEnum {
CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));
private String value;

View File

@ -42,7 +42,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -41,7 +41,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -38,7 +38,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -42,7 +42,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -42,7 +42,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -42,7 +42,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -42,7 +42,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -42,7 +42,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -42,7 +42,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -42,7 +42,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -41,7 +41,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;

View File

@ -43,7 +43,7 @@ public class ParentWithNullableDto {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");
private String value;