Skip to content

Commit

Permalink
Add missing underscores for PascalCase enum values #4837 (#18594)
Browse files Browse the repository at this point in the history
Co-authored-by: Renato Mameli <[email protected]>
  • Loading branch information
renatomameli and Renato Mameli committed May 21, 2024
1 parent 9398c64 commit bfa26ea
Show file tree
Hide file tree
Showing 58 changed files with 65 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ public String toEnumVarName(String value, String datatype) {
}

// string
String var = value.replaceAll("\\W+", "_").toUpperCase(Locale.ROOT);
String var = underscore(value.replaceAll("\\W+", "_")).toUpperCase(Locale.ROOT);
if (var.matches("\\d.*")) {
var = "_" + var;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public void toEnumVarNameShouldNotResultInSingleUnderscore() throws Exception {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

| Name | Value |
|---- | -----|
| SOMEOBJIDENTIFIER | &quot;SomeObjIdentifier&quot; |
| SOME_OBJ_IDENTIFIER | &quot;SomeObjIdentifier&quot; |


## Implemented Interfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -106,7 +106,7 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ParentWithNullable {

public enum TypeEnum {

CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));

String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ParentWithNullable {

public enum TypeEnum {

CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));

String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ParentWithNullable {

public enum TypeEnum {

CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));

String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/jersey3/docs/ChildCat.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDCAT | &quot;ChildCat&quot; |
| CHILD_CAT | &quot;ChildCat&quot; |



2 changes: 1 addition & 1 deletion samples/client/petstore/java/native-async/docs/ChildCat.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDCAT | &quot;ChildCat&quot; |
| CHILD_CAT | &quot;ChildCat&quot; |



2 changes: 1 addition & 1 deletion samples/client/petstore/java/native/docs/ChildCat.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDCAT | &quot;ChildCat&quot; |
| CHILD_CAT | &quot;ChildCat&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class ParentWithNullable {
@XmlEnum(String.class)
public enum TypeEnum {
@XmlEnumValue("ChildWithNullable")
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | &quot;ChildWithNullable&quot; |
| CHILD_WITH_NULLABLE | &quot;ChildWithNullable&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ParentWithNullableDto {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

| Name | Value |
|---- | -----|
| CHILDCAT | &quot;ChildCat&quot; |
| CHILD_CAT | &quot;ChildCat&quot; |



Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ParentWithNullable {

public enum TypeEnum {

CHILDWITHNULLABLE(String.valueOf("ChildWithNullable"));
CHILD_WITH_NULLABLE(String.valueOf("ChildWithNullable"));


private String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ParentWithNullable {
* Gets or Sets type
*/
public enum TypeEnum {
CHILDWITHNULLABLE("ChildWithNullable");
CHILD_WITH_NULLABLE("ChildWithNullable");

private String value;

Expand Down

0 comments on commit bfa26ea

Please sign in to comment.