Skip to content

[Java] Fix missing underscores for PascalCase enum values #4837 #18594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | "SomeObjIdentifier" |
| SOME_OBJ_IDENTIFIER | "SomeObjIdentifier" |


## 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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildCat" |
| CHILD_CAT | "ChildCat" |



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 | "ChildCat" |
| CHILD_CAT | "ChildCat" |



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 | "ChildCat" |
| CHILD_CAT | "ChildCat" |



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

| Name | Value |
|---- | -----|
| CHILDWITHNULLABLE | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildWithNullable" |
| CHILD_WITH_NULLABLE | "ChildWithNullable" |



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 | "ChildCat" |
| CHILD_CAT | "ChildCat" |



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
Loading
Loading