Skip to content

Commit

Permalink
Add missing underscores for PascalCase enum values #4837
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomameli authored and Renato Mameli committed May 17, 2024
1 parent 7e94c87 commit 3a6a427
Show file tree
Hide file tree
Showing 55 changed files with 64 additions and 57 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 | "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 @@ -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
6 changes: 3 additions & 3 deletions samples/documentation/html2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9591,19 +9591,19 @@ <h3 id="examples-User-loginUser-title-200"></h3>
<th>Description</th>
</tr>
<tr>
<td>SetDashCookie</td>
<td>SetMinusCookie</td>
<td>String</td>
<td></td>
<td>Cookie authentication key for use with the &#x60;api_key&#x60; apiKey authentication.</td>
</tr>
<tr>
<td>XDashRateDashLimit</td>
<td>XMinusRateMinusLimit</td>
<td>Integer</td>
<td>int32</td>
<td>calls per hour allowed by the user</td>
</tr>
<tr>
<td>XDashExpiresDashAfter</td>
<td>XMinusExpiresMinusAfter</td>
<td>Date</td>
<td>date-time</td>
<td>date in UTC when token expires</td>
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 @@ -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
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

0 comments on commit 3a6a427

Please sign in to comment.