Skip to content

Commit c7c28bf

Browse files
committed
bugfix-20188: Add test data to fake Api in petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml
1 parent 23ceafe commit c7c28bf

7 files changed

Lines changed: 171 additions & 4 deletions

File tree

modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,23 @@ paths:
681681
- '-efg'
682682
- (xyz)
683683
default: '-efg'
684+
enum_form_integer:
685+
description: Form parameter enum test (integer)
686+
type: integer
687+
enum:
688+
- 1
689+
- -1
690+
- 0
691+
default: 1
692+
enum_form_double:
693+
description: Form parameter enum test (double)
694+
type: double
695+
enum:
696+
- 1.1
697+
- -1.1
698+
- 0.1
699+
- 0.0
700+
default: 1.1
684701
post:
685702
tags:
686703
- fake
@@ -1558,6 +1575,18 @@ components:
15581575
complete:
15591576
type: boolean
15601577
default: false
1578+
paymentMethod:
1579+
type: number
1580+
format: int32
1581+
description: "Various payment methods"
1582+
default: 1
1583+
example: 1
1584+
x-enum-description:
1585+
- Paypal
1586+
- Creditcard
1587+
enum:
1588+
- 1
1589+
- 2
15611590
xml:
15621591
name: Order
15631592
Category:

samples/client/petstore/java/okhttp-gson/api/openapi.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,7 @@ components:
15971597
example:
15981598
petId: 6
15991599
quantity: 1
1600+
paymentMethod: 1
16001601
id: 0
16011602
shipDate: 2020-02-02T20:20:20.000222Z
16021603
complete: false
@@ -1625,6 +1626,18 @@ components:
16251626
complete:
16261627
default: false
16271628
type: boolean
1629+
paymentMethod:
1630+
default: 1
1631+
description: Various payment methods
1632+
enum:
1633+
- 1
1634+
- 2
1635+
example: 1
1636+
format: int32
1637+
type: number
1638+
x-enum-description:
1639+
- Paypal
1640+
- Creditcard
16281641
type: object
16291642
xml:
16301643
name: Order
@@ -2903,6 +2916,22 @@ components:
29032916
- -efg
29042917
- (xyz)
29052918
type: string
2919+
enum_form_integer:
2920+
default: 1
2921+
description: Form parameter enum test (integer)
2922+
enum:
2923+
- 1
2924+
- -1
2925+
- 0
2926+
type: integer
2927+
enum_form_double:
2928+
description: Form parameter enum test (double)
2929+
enum:
2930+
- 1.1
2931+
- -1.1
2932+
- 0.1
2933+
- 0.0
2934+
type: double
29062935
type: object
29072936
testEndpointParameters_request:
29082937
properties:

samples/client/petstore/java/okhttp-gson/docs/AllOfModelArrayAnyOfAllOfAttributesC.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
|**quantity** | **Integer** | | [optional] |
1818
|**shipDate** | **OffsetDateTime** | | [optional] |
1919
|**complete** | **Boolean** | | [optional] |
20+
|**paymentMethod** | [**PaymentMethodEnum**](#PaymentMethodEnum) | Various payment methods | [optional] |
2021

2122

2223

@@ -30,3 +31,12 @@
3031

3132

3233

34+
## Enum: PaymentMethodEnum
35+
36+
| Name | Value |
37+
|---- | -----|
38+
| NUMBER_1 | new BigDecimal("1") |
39+
| NUMBER_2 | new BigDecimal("2") |
40+
41+
42+

samples/client/petstore/java/okhttp-gson/docs/FakeApi.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ null (empty response body)
982982

983983
<a id="testEnumParameters"></a>
984984
# **testEnumParameters**
985-
> testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString)
985+
> testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString, enumFormInteger, enumFormDouble)
986986
987987
To test enum parameters
988988

@@ -1011,8 +1011,10 @@ public class Example {
10111011
Double enumQueryDouble = 1.1D; // Double | Query parameter enum test (double)
10121012
List<String> enumFormStringArray = Arrays.asList("$"); // List<String> | Form parameter enum test (string array)
10131013
String enumFormString = "_abc"; // String | Form parameter enum test (string)
1014+
Integer enumFormInteger = 1; // Integer | Form parameter enum test (integer)
1015+
Double enumFormDouble = 1.1D; // Double | Form parameter enum test (double)
10141016
try {
1015-
apiInstance.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString);
1017+
apiInstance.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString, enumFormInteger, enumFormDouble);
10161018
} catch (ApiException e) {
10171019
System.err.println("Exception when calling FakeApi#testEnumParameters");
10181020
System.err.println("Status code: " + e.getCode());
@@ -1036,6 +1038,8 @@ public class Example {
10361038
| **enumQueryDouble** | **Double**| Query parameter enum test (double) | [optional] [enum: 1.1, -1.2] |
10371039
| **enumFormStringArray** | [**List&lt;String&gt;**](String.md)| Form parameter enum test (string array) | [optional] [enum: >, $] |
10381040
| **enumFormString** | **String**| Form parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)] |
1041+
| **enumFormInteger** | **Integer**| Form parameter enum test (integer) | [optional] [default to 1] [enum: 1, -1, 0] |
1042+
| **enumFormDouble** | [**Double**](Double.md)| Form parameter enum test (double) | [optional] [enum: 1.1, -1.1, 0.1, 0.0] |
10391043

10401044
### Return type
10411045

samples/client/petstore/java/okhttp-gson/docs/Order.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
|**shipDate** | **OffsetDateTime** | | [optional] |
1414
|**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional] |
1515
|**complete** | **Boolean** | | [optional] |
16+
|**paymentMethod** | [**PaymentMethodEnum**](#PaymentMethodEnum) | Various payment methods | [optional] |
1617

1718

1819

@@ -26,3 +27,12 @@
2627

2728

2829

30+
## Enum: PaymentMethodEnum
31+
32+
| Name | Value |
33+
|---- | -----|
34+
| NUMBER_1 | new BigDecimal(&quot;1&quot;) |
35+
| NUMBER_2 | new BigDecimal(&quot;2&quot;) |
36+
37+
38+

samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.gson.stream.JsonReader;
2121
import com.google.gson.stream.JsonWriter;
2222
import java.io.IOException;
23+
import java.math.BigDecimal;
2324
import java.time.OffsetDateTime;
2425
import java.util.ArrayList;
2526
import java.util.Arrays;

samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Order.java

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.gson.stream.JsonReader;
2121
import com.google.gson.stream.JsonWriter;
2222
import java.io.IOException;
23+
import java.math.BigDecimal;
2324
import java.time.OffsetDateTime;
2425
import java.util.Arrays;
2526

@@ -135,6 +136,63 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
135136
@javax.annotation.Nullable
136137
private Boolean complete = false;
137138

139+
/**
140+
* Various payment methods
141+
*/
142+
@JsonAdapter(PaymentMethodEnum.Adapter.class)
143+
public enum PaymentMethodEnum {
144+
NUMBER_1(new BigDecimal("1")),
145+
146+
NUMBER_2(new BigDecimal("2"));
147+
148+
private BigDecimal value;
149+
150+
PaymentMethodEnum(BigDecimal value) {
151+
this.value = value;
152+
}
153+
154+
public BigDecimal getValue() {
155+
return value;
156+
}
157+
158+
@Override
159+
public String toString() {
160+
return String.valueOf(value);
161+
}
162+
163+
public static PaymentMethodEnum fromValue(BigDecimal value) {
164+
for (PaymentMethodEnum b : PaymentMethodEnum.values()) {
165+
if (b.value.equals(value)) {
166+
return b;
167+
}
168+
}
169+
throw new IllegalArgumentException("Unexpected value '" + value + "'");
170+
}
171+
172+
public static class Adapter extends TypeAdapter<PaymentMethodEnum> {
173+
@Override
174+
public void write(final JsonWriter jsonWriter, final PaymentMethodEnum enumeration) throws IOException {
175+
jsonWriter.value(enumeration.getValue());
176+
}
177+
178+
@Override
179+
public PaymentMethodEnum read(final JsonReader jsonReader) throws IOException {
180+
String value = jsonReader.nextString();
181+
return PaymentMethodEnum.fromValue(new BigDecimal(value));
182+
}
183+
}
184+
185+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
186+
String value = jsonElement.getAsString();
187+
PaymentMethodEnum.fromValue(new BigDecimal(value));
188+
}
189+
}
190+
191+
public static final String SERIALIZED_NAME_PAYMENT_METHOD = "paymentMethod";
192+
@SerializedName(SERIALIZED_NAME_PAYMENT_METHOD)
193+
@javax.annotation.Nullable
194+
private PaymentMethodEnum paymentMethod = PaymentMethodEnum.NUMBER_1;
195+
138196
public Order() {
139197
}
140198

@@ -251,6 +309,25 @@ public void setComplete(@javax.annotation.Nullable Boolean complete) {
251309
this.complete = complete;
252310
}
253311

312+
313+
public Order paymentMethod(@javax.annotation.Nullable PaymentMethodEnum paymentMethod) {
314+
this.paymentMethod = paymentMethod;
315+
return this;
316+
}
317+
318+
/**
319+
* Various payment methods
320+
* @return paymentMethod
321+
*/
322+
@javax.annotation.Nullable
323+
public PaymentMethodEnum getPaymentMethod() {
324+
return paymentMethod;
325+
}
326+
327+
public void setPaymentMethod(@javax.annotation.Nullable PaymentMethodEnum paymentMethod) {
328+
this.paymentMethod = paymentMethod;
329+
}
330+
254331
/**
255332
* A container for additional, undeclared properties.
256333
* This is a holder for any undeclared properties as specified with
@@ -311,13 +388,14 @@ public boolean equals(Object o) {
311388
Objects.equals(this.quantity, order.quantity) &&
312389
Objects.equals(this.shipDate, order.shipDate) &&
313390
Objects.equals(this.status, order.status) &&
314-
Objects.equals(this.complete, order.complete)&&
391+
Objects.equals(this.complete, order.complete) &&
392+
Objects.equals(this.paymentMethod, order.paymentMethod)&&
315393
Objects.equals(this.additionalProperties, order.additionalProperties);
316394
}
317395

318396
@Override
319397
public int hashCode() {
320-
return Objects.hash(id, petId, quantity, shipDate, status, complete, additionalProperties);
398+
return Objects.hash(id, petId, quantity, shipDate, status, complete, paymentMethod, additionalProperties);
321399
}
322400

323401
@Override
@@ -330,6 +408,7 @@ public String toString() {
330408
sb.append(" shipDate: ").append(toIndentedString(shipDate)).append("\n");
331409
sb.append(" status: ").append(toIndentedString(status)).append("\n");
332410
sb.append(" complete: ").append(toIndentedString(complete)).append("\n");
411+
sb.append(" paymentMethod: ").append(toIndentedString(paymentMethod)).append("\n");
333412
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
334413
sb.append("}");
335414
return sb.toString();
@@ -359,6 +438,7 @@ private String toIndentedString(Object o) {
359438
openapiFields.add("shipDate");
360439
openapiFields.add("status");
361440
openapiFields.add("complete");
441+
openapiFields.add("paymentMethod");
362442

363443
// a set of required properties/fields (JSON key names)
364444
openapiRequiredFields = new HashSet<String>();
@@ -384,6 +464,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
384464
if (jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) {
385465
StatusEnum.validateJsonElement(jsonObj.get("status"));
386466
}
467+
// validate the optional field `paymentMethod`
468+
if (jsonObj.get("paymentMethod") != null && !jsonObj.get("paymentMethod").isJsonNull()) {
469+
PaymentMethodEnum.validateJsonElement(jsonObj.get("paymentMethod"));
470+
}
387471
}
388472

389473
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {

0 commit comments

Comments
 (0)