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 3 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 @@ -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 @@ -681,6 +681,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: double
enum:
- 1.1
- -1.1
- 0.1
- 0.0
default: 1.1
post:
tags:
- fake
Expand Down Expand Up @@ -1558,6 +1575,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 @@ -136,9 +136,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(Integer.valueOf(1)),
NUMBER_1(1),

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

private Integer value;

Expand Down Expand Up @@ -175,9 +175,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(Double.valueOf(1.1)),
NUMBER_1_DOT_1(1.1),

NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_MINUS_1_DOT_2(-1.2);

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(Integer.valueOf(1)),
NUMBER_1(1),

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

private Integer value;

Expand Down Expand Up @@ -167,9 +167,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(Double.valueOf(1.1)),
NUMBER_1_DOT_1(1.1),

NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_MINUS_1_DOT_2(-1.2);

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(Integer.valueOf(1)),
NUMBER_1(1),

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

private Integer value;

Expand Down Expand Up @@ -172,9 +172,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(Double.valueOf(1.1)),
NUMBER_1_DOT_1(1.1),

NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_MINUS_1_DOT_2(-1.2);

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(Integer.valueOf(1)),
NUMBER_1(1),

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

private Integer value;

Expand Down Expand Up @@ -162,9 +162,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(Double.valueOf(1.1)),
NUMBER_1_DOT_1(1.1),

NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_MINUS_1_DOT_2(-1.2);

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(Integer.valueOf(1)),
NUMBER_1(1),

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

private Integer value;

Expand Down Expand Up @@ -165,9 +165,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(Double.valueOf(1.1)),
NUMBER_1_DOT_1(1.1),

NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_MINUS_1_DOT_2(-1.2);

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(Integer.valueOf(1)),
NUMBER_1(1),

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

private Integer value;

Expand Down Expand Up @@ -165,9 +165,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(Double.valueOf(1.1)),
NUMBER_1_DOT_1(1.1),

NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_MINUS_1_DOT_2(-1.2);

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(Integer.valueOf(1)),
NUMBER_1(1),

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

private Integer value;

Expand Down Expand Up @@ -180,9 +180,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumIntegerOnly
*/
public enum EnumIntegerOnlyEnum {
NUMBER_2(Integer.valueOf(2)),
NUMBER_2(2),

NUMBER_MINUS_2(Integer.valueOf(-2));
NUMBER_MINUS_2(-2);

private Integer value;

Expand Down Expand Up @@ -219,9 +219,9 @@ public static EnumIntegerOnlyEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(Double.valueOf(1.1)),
NUMBER_1_DOT_1(1.1),

NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_MINUS_1_DOT_2(-1.2);

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(Integer.valueOf(1)),
NUMBER_1(1),

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

private Integer value;

Expand Down Expand Up @@ -178,9 +178,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumIntegerOnly
*/
public enum EnumIntegerOnlyEnum {
NUMBER_2(Integer.valueOf(2)),
NUMBER_2(2),

NUMBER_MINUS_2(Integer.valueOf(-2));
NUMBER_MINUS_2(-2);

private Integer value;

Expand Down Expand Up @@ -217,9 +217,9 @@ public static EnumIntegerOnlyEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(Double.valueOf(1.1)),
NUMBER_1_DOT_1(1.1),

NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_MINUS_1_DOT_2(-1.2);

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(Integer.valueOf(1)),
NUMBER_1(1),

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

private Integer value;

Expand Down Expand Up @@ -180,9 +180,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumIntegerOnly
*/
public enum EnumIntegerOnlyEnum {
NUMBER_2(Integer.valueOf(2)),
NUMBER_2(2),

NUMBER_MINUS_2(Integer.valueOf(-2));
NUMBER_MINUS_2(-2);

private Integer value;

Expand Down Expand Up @@ -219,9 +219,9 @@ public static EnumIntegerOnlyEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(Double.valueOf(1.1)),
NUMBER_1_DOT_1(1.1),

NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
NUMBER_MINUS_1_DOT_2(-1.2);

private Double value;

Expand Down
29 changes: 29 additions & 0 deletions samples/client/petstore/java/okhttp-gson/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,7 @@ components:
example:
petId: 6
quantity: 1
paymentMethod: 1
id: 0
shipDate: 2020-02-02T20:20:20.000222Z
complete: false
Expand Down Expand Up @@ -1625,6 +1626,18 @@ components:
complete:
default: false
type: boolean
paymentMethod:
default: 1
description: Various payment methods
enum:
- 1
- 2
example: 1
format: int32
type: number
x-enum-description:
- Paypal
- Creditcard
type: object
xml:
name: Order
Expand Down Expand Up @@ -2913,6 +2926,22 @@ components:
- -efg
- (xyz)
type: string
enum_form_integer:
default: 1
description: Form parameter enum test (integer)
enum:
- 1
- -1
- 0
type: integer
enum_form_double:
description: Form parameter enum test (double)
enum:
- 1.1
- -1.1
- 0.1
- 0.0
type: double
type: object
testEndpointParameters_request:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
|**quantity** | **Integer** | | [optional] |
|**shipDate** | **OffsetDateTime** | | [optional] |
|**complete** | **Boolean** | | [optional] |
|**paymentMethod** | [**PaymentMethodEnum**](#PaymentMethodEnum) | Various payment methods | [optional] |



Expand All @@ -30,3 +31,12 @@



## Enum: PaymentMethodEnum

| Name | Value |
|---- | -----|
| NUMBER_1 | new BigDecimal("1") |
| NUMBER_2 | new BigDecimal("2") |



Loading