Skip to content
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

[JAVA][BUG] Do not use valueOf for numeric types for generating inner enums #20293

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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 @@ -15,7 +15,7 @@
{{#enumVars}}@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}) {{name}}({{dataType}}.valueOf({{{value}}})){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
{{/withXml}}
{{^withXml}}
{{#enumVars}}{{name}}({{^isUri}}{{dataType}}.valueOf({{/isUri}}{{{value}}}{{^isUri}}){{/isUri}}){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
{{#enumVars}}{{name}}({{^isUri}}{{^isNumeric}}{{dataType}}.valueOf({{/isNumeric}}{{/isUri}}{{{value}}}{{^isUri}}){{/isUri}}{{^isNumeric}}){{/isNumeric}}{{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
{{/withXml}}
{{/allowableValues}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{#withXml}}
@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
{{/withXml}}
{{{name}}}({{{value}}}){{^-last}},
{{{name}}}({{^isUri}}{{^isNumeric}}{{dataType}}.valueOf({{/isNumeric}}{{/isUri}}{{{value}}}{{^isUri}}{{^isNumeric}}){{/isNumeric}}{{/isUri}}){{^-last}},
{{/-last}}{{#-last}};{{/-last}}
{{/enumVars}}
{{/allowableValues}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{#withXml}}
@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
{{/withXml}}
{{{name}}}({{^isUri}}{{dataType}}.valueOf({{/isUri}}{{{value}}}{{^isUri}}){{/isUri}}){{^-last}},
{{{name}}}({{^isUri}}{{^isNumeric}}{{dataType}}.valueOf({{/isNumeric}}{{/isUri}}{{{value}}}{{^isUri}}{{^isNumeric}}){{/isNumeric}}{{/isUri}}){{^-last}},
{{/-last}}{{#-last}};{{/-last}}
{{/enumVars}}
{{/allowableValues}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{>additionalEnumTypeAnnotations}}public enum {{datatypeWithEnum}} {

{{#allowableValues}}
{{#enumVars}}{{name}}({{dataType}}.valueOf({{{value}}})){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
{{#enumVars}}{{name}}({{^isNumeric}}{{dataType}}.valueOf({{/isNumeric}}{{{value}}}{{^isNumeric}}){{/isNumeric}}){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
{{/allowableValues}}

{{dataType}} value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{>additionalEnumTypeAnnotations}}public enum {{datatypeWithEnum}} {

{{#allowableValues}}
{{#enumVars}}{{name}}({{dataType}}.valueOf({{{value}}})){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
{{#enumVars}}{{name}}({{^isNumeric}}{{dataType}}.valueOf({{/isNumeric}}{{{value}}}{{^isNumeric}}){{/isNumeric}}){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
{{/allowableValues}}

{{dataType}} value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{>additionalEnumTypeAnnotations}}public enum {{datatypeWithEnum}} {

{{#allowableValues}}
{{#enumVars}}{{name}}({{dataType}}.valueOf({{{value}}})){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
{{#enumVars}}{{name}}({{^isNumeric}}{{dataType}}.valueOf({{/isNumeric}}{{{value}}}{{^isNumeric}}){{/isNumeric}}){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
{{/allowableValues}}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,14 @@ paths:
- '-efg'
- (xyz)
default: '-efg'
enum_form_integer:
description: Form parameter enum test (integer)
type: integer
enum:
- 1
- -1
- 0
default: 1
post:
tags:
- fake
Expand Down Expand Up @@ -1558,6 +1566,18 @@ components:
complete:
type: boolean
default: false
paymentMethod:
type: number
format: int32
description: "Various payment methods"
default: 1
example: 1
x-enum-description:
- Paypal
- Creditcard
enum:
- 1
- 2
xml:
name: Order
Category:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,23 @@ paths:
- '-efg'
- (xyz)
default: '-efg'
enum_form_integer:
description: Form parameter enum test (integer)
type: integer
enum:
- 1
- -1
- 0
default: 1
enum_form_double:
description: Form parameter enum test (double)
type: number
enum:
- 1.1
- -1.1
- 0.1
- 0.0
default: 1.1
post:
tags:
- fake
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public class Order {
*/
@JsonAdapter(StatusEnum.Adapter.class)
public enum StatusEnum {
PLACED("placed"),
PLACED(String.valueOf("placed")),

APPROVED("approved"),
APPROVED(String.valueOf("approved")),

DELIVERED("delivered");
DELIVERED(String.valueOf("delivered"));

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public class Pet {
*/
@JsonAdapter(StatusEnum.Adapter.class)
public enum StatusEnum {
AVAILABLE("available"),
AVAILABLE(String.valueOf("available")),

PENDING("pending"),
PENDING(String.valueOf("pending")),

SOLD("sold");
SOLD(String.valueOf("sold"));

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public class DefaultValue {
*/
@JsonAdapter(ArrayStringEnumDefaultEnum.Adapter.class)
public enum ArrayStringEnumDefaultEnum {
SUCCESS("success"),
SUCCESS(String.valueOf("success")),

FAILURE("failure"),
FAILURE(String.valueOf("failure")),

UNCLASSIFIED("unclassified");
UNCLASSIFIED(String.valueOf("unclassified"));

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public class Pet {
*/
@JsonAdapter(StatusEnum.Adapter.class)
public enum StatusEnum {
AVAILABLE("available"),
AVAILABLE(String.valueOf("available")),

PENDING("pending"),
PENDING(String.valueOf("pending")),

SOLD("sold");
SOLD(String.valueOf("sold"));

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public class Query {
*/
@JsonAdapter(OutcomesEnum.Adapter.class)
public enum OutcomesEnum {
SUCCESS("SUCCESS"),
SUCCESS(String.valueOf("SUCCESS")),

FAILURE("FAILURE"),
FAILURE(String.valueOf("FAILURE")),

SKIPPED("SKIPPED");
SKIPPED(String.valueOf("SKIPPED"));

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class SomeObj implements Serializable {
*/
@JsonAdapter(TypeEnum.Adapter.class)
public enum TypeEnum {
SOMEOBJIDENTIFIER("SomeObjIdentifier");
SOMEOBJIDENTIFIER(String.valueOf("SomeObjIdentifier"));

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン

## testEnumParameters

> void testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString)
> void testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString, enumFormInteger, enumFormDouble)

To test enum parameters

Expand All @@ -546,6 +546,8 @@ To test enum parameters
| **enumQueryModelArray** | [**List<EnumClass>**](EnumClass.md)| | [optional] |
| **enumFormStringArray** | [**List<String>**](String.md)| Form parameter enum test (string array) | [optional] [enum: >, $] |
| **enumFormString** | **String**| Form parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)] |
| **enumFormInteger** | **Integer**| Form parameter enum test (integer) | [optional] [default to 1] [enum: 1, -1, 0] |
| **enumFormDouble** | **BigDecimal**| Form parameter enum test (double) | [optional] [default to 1.1] [enum: 1.1, -1.1, 0.1, 0.0] |

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public interface FakeApi {
@GET

@Consumes({ "application/x-www-form-urlencoded" })
void testEnumParameters(@HeaderParam("enum_header_string_array") List<String> enumHeaderStringArray, @HeaderParam("enum_header_string") String enumHeaderString, @QueryParam("enum_query_string_array") List<String> enumQueryStringArray, @QueryParam("enum_query_string") @DefaultValue("-efg") String enumQueryString, @QueryParam("enum_query_integer") Integer enumQueryInteger, @QueryParam("enum_query_double") Double enumQueryDouble, @QueryParam("enum_query_model_array") List<EnumClass> enumQueryModelArray, @FormParam("enum_form_string_array") List<String> enumFormStringArray, @FormParam("enum_form_string") String enumFormString) throws ApiException, ProcessingException;
void testEnumParameters(@HeaderParam("enum_header_string_array") List<String> enumHeaderStringArray, @HeaderParam("enum_header_string") String enumHeaderString, @QueryParam("enum_query_string_array") List<String> enumQueryStringArray, @QueryParam("enum_query_string") @DefaultValue("-efg") String enumQueryString, @QueryParam("enum_query_integer") Integer enumQueryInteger, @QueryParam("enum_query_double") Double enumQueryDouble, @QueryParam("enum_query_model_array") List<EnumClass> enumQueryModelArray, @FormParam("enum_form_string_array") List<String> enumFormStringArray, @FormParam("enum_form_string") String enumFormString, @FormParam("enum_form_integer") Integer enumFormInteger, @FormParam("enum_form_double") BigDecimal enumFormDouble) throws ApiException, ProcessingException;

/**
* Fake endpoint to test group parameters (optional)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public String toString() {

public enum EnumIntegerEnum {

NUMBER_1(Integer.valueOf(1)), NUMBER_MINUS_1(Integer.valueOf(-1));
NUMBER_1(1), NUMBER_MINUS_1(-1);

Integer value;

Expand All @@ -101,7 +101,7 @@ public String toString() {

public enum EnumNumberEnum {

NUMBER_1_DOT_1(Double.valueOf(1.1)), NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_1_DOT_1(1.1), NUMBER_MINUS_1_DOT_2(-1.2);

Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ null (empty response body)

## testEnumParameters

> testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString)
> testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString, enumFormInteger, enumFormDouble)

To test enum parameters

Expand Down Expand Up @@ -1007,8 +1007,10 @@ public class Example {
List<EnumClass> enumQueryModelArray = Arrays.asList(-efg); // List<EnumClass> |
List<String> enumFormStringArray = Arrays.asList("$"); // List<String> | Form parameter enum test (string array)
String enumFormString = "_abc"; // String | Form parameter enum test (string)
Integer enumFormInteger = 1; // Integer | Form parameter enum test (integer)
BigDecimal enumFormDouble = new BigDecimal("1.1"); // BigDecimal | Form parameter enum test (double)
try {
apiInstance.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString);
apiInstance.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString, enumFormInteger, enumFormDouble);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testEnumParameters");
System.err.println("Status code: " + e.getCode());
Expand All @@ -1034,6 +1036,8 @@ public class Example {
| **enumQueryModelArray** | [**List&lt;EnumClass&gt;**](EnumClass.md)| | [optional] |
| **enumFormStringArray** | [**List&lt;String&gt;**](String.md)| Form parameter enum test (string array) | [optional] [enum: >, $] |
| **enumFormString** | **String**| Form parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)] |
| **enumFormInteger** | **Integer**| Form parameter enum test (integer) | [optional] [default to 1] [enum: 1, -1, 0] |
| **enumFormDouble** | **BigDecimal**| Form parameter enum test (double) | [optional] [default to 1.1] [enum: 1.1, -1.1, 0.1, 0.0] |

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ public interface FakeApi {
* @param enumQueryModelArray (optional)
* @param enumFormStringArray Form parameter enum test (string array) (optional)
* @param enumFormString Form parameter enum test (string) (optional, default to -efg)
* @param enumFormInteger Form parameter enum test (integer) (optional, default to 1)
* @param enumFormDouble Form parameter enum test (double) (optional, default to 1.1)
* @return {@code ApiResponse<Void>}
*/
ApiResponse<Void> testEnumParameters(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<EnumClass> enumQueryModelArray, List<String> enumFormStringArray, String enumFormString);
ApiResponse<Void> testEnumParameters(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<EnumClass> enumQueryModelArray, List<String> enumFormStringArray, String enumFormString, Integer enumFormInteger, BigDecimal enumFormDouble);

/**
* Fake endpoint to test group parameters (optional)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,9 @@ protected ApiResponse<Void> testEndpointParametersSubmit(WebClientRequestBuilder
}

@Override
public ApiResponse<Void> testEnumParameters(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<EnumClass> enumQueryModelArray, List<String> enumFormStringArray, String enumFormString) {
WebClientRequestBuilder webClientRequestBuilder = testEnumParametersRequestBuilder(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString);
return testEnumParametersSubmit(webClientRequestBuilder, enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString);
public ApiResponse<Void> testEnumParameters(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<EnumClass> enumQueryModelArray, List<String> enumFormStringArray, String enumFormString, Integer enumFormInteger, BigDecimal enumFormDouble) {
WebClientRequestBuilder webClientRequestBuilder = testEnumParametersRequestBuilder(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString, enumFormInteger, enumFormDouble);
return testEnumParametersSubmit(webClientRequestBuilder, enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString, enumFormInteger, enumFormDouble);
}

/**
Expand All @@ -699,9 +699,11 @@ public ApiResponse<Void> testEnumParameters(List<String> enumHeaderStringArray,
* @param enumQueryModelArray (optional)
* @param enumFormStringArray Form parameter enum test (string array) (optional)
* @param enumFormString Form parameter enum test (string) (optional, default to -efg)
* @param enumFormInteger Form parameter enum test (integer) (optional, default to 1)
* @param enumFormDouble Form parameter enum test (double) (optional, default to 1.1)
* @return WebClientRequestBuilder for testEnumParameters
*/
protected WebClientRequestBuilder testEnumParametersRequestBuilder(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<EnumClass> enumQueryModelArray, List<String> enumFormStringArray, String enumFormString) {
protected WebClientRequestBuilder testEnumParametersRequestBuilder(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<EnumClass> enumQueryModelArray, List<String> enumFormStringArray, String enumFormString, Integer enumFormInteger, BigDecimal enumFormDouble) {
WebClientRequestBuilder webClientRequestBuilder = apiClient.webClient()
.method("GET");

Expand Down Expand Up @@ -742,12 +744,16 @@ protected WebClientRequestBuilder testEnumParametersRequestBuilder(List<String>
* @param enumQueryModelArray (optional)
* @param enumFormStringArray Form parameter enum test (string array) (optional)
* @param enumFormString Form parameter enum test (string) (optional, default to -efg)
* @param enumFormInteger Form parameter enum test (integer) (optional, default to 1)
* @param enumFormDouble Form parameter enum test (double) (optional, default to 1.1)
* @return {@code ApiResponse<Void>} for the submitted request
*/
protected ApiResponse<Void> testEnumParametersSubmit(WebClientRequestBuilder webClientRequestBuilder, List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<EnumClass> enumQueryModelArray, List<String> enumFormStringArray, String enumFormString) {
protected ApiResponse<Void> testEnumParametersSubmit(WebClientRequestBuilder webClientRequestBuilder, List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<EnumClass> enumQueryModelArray, List<String> enumFormStringArray, String enumFormString, Integer enumFormInteger, BigDecimal enumFormDouble) {
String formParams = new StringJoiner("&")
.add("enum_form_string_array=" + enumFormStringArray)
.add("enum_form_string=" + enumFormString)
.add("enum_form_integer=" + enumFormInteger)
.add("enum_form_double=" + enumFormDouble)
.toString();
Single<WebClientResponse> webClientResponse = webClientRequestBuilder.submit(formParams);
return ApiResponse.create(RESPONSE_TYPE_testEnumParameters, webClientResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public String toString() {

public enum EnumIntegerEnum {

NUMBER_1(Integer.valueOf(1)), NUMBER_MINUS_1(Integer.valueOf(-1));
NUMBER_1(1), NUMBER_MINUS_1(-1);

Integer value;

Expand All @@ -101,7 +101,7 @@ public String toString() {

public enum EnumNumberEnum {

NUMBER_1_DOT_1(Double.valueOf(1.1)), NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_1_DOT_1(1.1), NUMBER_MINUS_1_DOT_2(-1.2);

Double value;

Expand Down
Loading