Skip to content

Commit fc752a9

Browse files
committed
[Java] add tests when field is nullable and required
1 parent fe44896 commit fc752a9

13 files changed

Lines changed: 1393 additions & 0 deletions

File tree

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,19 @@ paths:
13821382
$ref: '#/components/schemas/Variable'
13831383
'400':
13841384
description: Invalid Value
1385+
/fake/required-nullable-body:
1386+
get:
1387+
tags:
1388+
- fake
1389+
summary: fields in the response body, required and nullable are both true
1390+
description: ''
1391+
responses:
1392+
'200':
1393+
description: success
1394+
content:
1395+
application/json:
1396+
schema:
1397+
$ref: '#/components/schemas/RequiredNullableBody'
13851398
servers:
13861399
- url: 'http://{server}.swagger.io:{port}/v2'
13871400
description: petstore server
@@ -2748,3 +2761,35 @@ components:
27482761
$ref: '#/components/schemas/ArrayOneOf'
27492762
anyof_prop:
27502763
$ref: '#/components/schemas/ArrayAnyOf'
2764+
NullableEnum:
2765+
type: string
2766+
nullable: true
2767+
enum:
2768+
- custom
2769+
RequiredNullableBody:
2770+
allOf:
2771+
- $ref: '#/components/schemas/NullableClass'
2772+
- type: object
2773+
required:
2774+
- custom_ref_enum
2775+
- custom_enum
2776+
- integer_prop
2777+
- number_prop
2778+
- boolean_prop
2779+
- string_prop
2780+
- date_prop
2781+
- datetime_prop
2782+
- array_nullable_prop
2783+
- array_and_items_nullable_prop
2784+
- array_items_nullable
2785+
- object_nullable_prop
2786+
- object_and_items_nullable_prop
2787+
- object_items_nullable
2788+
properties:
2789+
custom_ref_enum:
2790+
$ref: "#/components/schemas/NullableEnum"
2791+
custom_enum:
2792+
type: string
2793+
nullable: true
2794+
enum:
2795+
- custom

‎samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ docs/NewPet.md
7373
docs/NewPetCategoryInlineAllof.md
7474
docs/NewPetCategoryInlineAllofAllOfCategoryTag.md
7575
docs/NullableClass.md
76+
docs/NullableEnum.md
7677
docs/NullableShape.md
7778
docs/NumberOnly.md
7879
docs/ObjectWithDeprecatedFields.md
@@ -94,6 +95,7 @@ docs/PropertyNameCollision.md
9495
docs/Quadrilateral.md
9596
docs/QuadrilateralInterface.md
9697
docs/ReadOnlyFirst.md
98+
docs/RequiredNullableBody.md
9799
docs/Scalar.md
98100
docs/ScalarAnyOf.md
99101
docs/ScaleneTriangle.md
@@ -216,6 +218,7 @@ src/main/java/org/openapitools/client/model/NewPet.java
216218
src/main/java/org/openapitools/client/model/NewPetCategoryInlineAllof.java
217219
src/main/java/org/openapitools/client/model/NewPetCategoryInlineAllofAllOfCategoryTag.java
218220
src/main/java/org/openapitools/client/model/NullableClass.java
221+
src/main/java/org/openapitools/client/model/NullableEnum.java
219222
src/main/java/org/openapitools/client/model/NullableShape.java
220223
src/main/java/org/openapitools/client/model/NumberOnly.java
221224
src/main/java/org/openapitools/client/model/ObjectWithDeprecatedFields.java
@@ -236,6 +239,7 @@ src/main/java/org/openapitools/client/model/PropertyNameCollision.java
236239
src/main/java/org/openapitools/client/model/Quadrilateral.java
237240
src/main/java/org/openapitools/client/model/QuadrilateralInterface.java
238241
src/main/java/org/openapitools/client/model/ReadOnlyFirst.java
242+
src/main/java/org/openapitools/client/model/RequiredNullableBody.java
239243
src/main/java/org/openapitools/client/model/Scalar.java
240244
src/main/java/org/openapitools/client/model/ScalarAnyOf.java
241245
src/main/java/org/openapitools/client/model/ScaleneTriangle.java
@@ -253,3 +257,5 @@ src/main/java/org/openapitools/client/model/Value.java
253257
src/main/java/org/openapitools/client/model/Variable.java
254258
src/main/java/org/openapitools/client/model/Whale.java
255259
src/main/java/org/openapitools/client/model/Zebra.java
260+
src/test/java/org/openapitools/client/model/NullableEnumTest.java
261+
src/test/java/org/openapitools/client/model/RequiredNullableBodyTest.java

‎samples/client/petstore/java/okhttp-gson/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Class | Method | HTTP request | Description
126126
*FakeApi* | [**fakeOuterCompositeSerialize**](docs/FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite |
127127
*FakeApi* | [**fakeOuterNumberSerialize**](docs/FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number |
128128
*FakeApi* | [**fakeOuterStringSerialize**](docs/FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string |
129+
*FakeApi* | [**fakeRequiredNullableBodyGet**](docs/FakeApi.md#fakeRequiredNullableBodyGet) | **GET** /fake/required-nullable-body | fields in the response body, required and nullable are both true
129130
*FakeApi* | [**fakeUploadRefRequestBodies**](docs/FakeApi.md#fakeUploadRefRequestBodies) | **POST** /fake/pet/{petId}/uploadImage | fake uploads an image with ref request bodies
130131
*FakeApi* | [**getFakeArrayofenums**](docs/FakeApi.md#getFakeArrayofenums) | **GET** /fake/array-of-enums | Array of Enums
131132
*FakeApi* | [**getFakeHealth**](docs/FakeApi.md#getFakeHealth) | **GET** /fake/health | Health check endpoint
@@ -233,6 +234,7 @@ Class | Method | HTTP request | Description
233234
- [NewPetCategoryInlineAllof](docs/NewPetCategoryInlineAllof.md)
234235
- [NewPetCategoryInlineAllofAllOfCategoryTag](docs/NewPetCategoryInlineAllofAllOfCategoryTag.md)
235236
- [NullableClass](docs/NullableClass.md)
237+
- [NullableEnum](docs/NullableEnum.md)
236238
- [NullableShape](docs/NullableShape.md)
237239
- [NumberOnly](docs/NumberOnly.md)
238240
- [ObjectWithDeprecatedFields](docs/ObjectWithDeprecatedFields.md)
@@ -253,6 +255,7 @@ Class | Method | HTTP request | Description
253255
- [Quadrilateral](docs/Quadrilateral.md)
254256
- [QuadrilateralInterface](docs/QuadrilateralInterface.md)
255257
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
258+
- [RequiredNullableBody](docs/RequiredNullableBody.md)
256259
- [Scalar](docs/Scalar.md)
257260
- [ScalarAnyOf](docs/ScalarAnyOf.md)
258261
- [ScaleneTriangle](docs/ScaleneTriangle.md)

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,21 @@ paths:
14791479
x-internal: true
14801480
x-accepts:
14811481
- application/json
1482+
/fake/required-nullable-body:
1483+
get:
1484+
description: ""
1485+
responses:
1486+
"200":
1487+
content:
1488+
application/json:
1489+
schema:
1490+
$ref: '#/components/schemas/RequiredNullableBody'
1491+
description: success
1492+
summary: "fields in the response body, required and nullable are both true"
1493+
tags:
1494+
- fake
1495+
x-accepts:
1496+
- application/json
14821497
components:
14831498
requestBodies:
14841499
upload_body:
@@ -2778,6 +2793,62 @@ components:
27782793
anyof_prop:
27792794
$ref: '#/components/schemas/ArrayAnyOf'
27802795
type: object
2796+
NullableEnum:
2797+
enum:
2798+
- custom
2799+
nullable: true
2800+
type: string
2801+
RequiredNullableBody:
2802+
allOf:
2803+
- $ref: '#/components/schemas/NullableClass'
2804+
- properties:
2805+
custom_ref_enum:
2806+
$ref: '#/components/schemas/NullableEnum'
2807+
custom_enum:
2808+
enum:
2809+
- custom
2810+
nullable: true
2811+
type: string
2812+
required:
2813+
- array_and_items_nullable_prop
2814+
- array_items_nullable
2815+
- array_nullable_prop
2816+
- boolean_prop
2817+
- custom_enum
2818+
- custom_ref_enum
2819+
- date_prop
2820+
- datetime_prop
2821+
- integer_prop
2822+
- number_prop
2823+
- object_and_items_nullable_prop
2824+
- object_items_nullable
2825+
- object_nullable_prop
2826+
- string_prop
2827+
type: object
2828+
example:
2829+
number_prop: 6.027456183070403
2830+
datetime_prop: 2000-01-23T04:56:07.000+00:00
2831+
custom_ref_enum: custom
2832+
boolean_prop: true
2833+
string_prop: string_prop
2834+
array_nullable_prop:
2835+
- "{}"
2836+
- "{}"
2837+
custom_enum: custom
2838+
integer_prop: 0
2839+
array_and_items_nullable_prop:
2840+
- "{}"
2841+
- "{}"
2842+
object_items_nullable:
2843+
key: "{}"
2844+
object_nullable_prop:
2845+
key: "{}"
2846+
object_and_items_nullable_prop:
2847+
key: "{}"
2848+
date_prop: 2000-01-23
2849+
array_items_nullable:
2850+
- "{}"
2851+
- "{}"
27812852
_foo_get_default_response:
27822853
example:
27832854
string:

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
99
| [**fakeOuterCompositeSerialize**](FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite | |
1010
| [**fakeOuterNumberSerialize**](FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number | |
1111
| [**fakeOuterStringSerialize**](FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | |
12+
| [**fakeRequiredNullableBodyGet**](FakeApi.md#fakeRequiredNullableBodyGet) | **GET** /fake/required-nullable-body | fields in the response body, required and nullable are both true |
1213
| [**fakeUploadRefRequestBodies**](FakeApi.md#fakeUploadRefRequestBodies) | **POST** /fake/pet/{petId}/uploadImage | fake uploads an image with ref request bodies |
1314
| [**getFakeArrayofenums**](FakeApi.md#getFakeArrayofenums) | **GET** /fake/array-of-enums | Array of Enums |
1415
| [**getFakeHealth**](FakeApi.md#getFakeHealth) | **GET** /fake/health | Health check endpoint |
@@ -333,6 +334,64 @@ No authorization required
333334
|-------------|-------------|------------------|
334335
| **200** | Output string | - |
335336

337+
<a id="fakeRequiredNullableBodyGet"></a>
338+
# **fakeRequiredNullableBodyGet**
339+
> RequiredNullableBody fakeRequiredNullableBodyGet()
340+
341+
fields in the response body, required and nullable are both true
342+
343+
344+
345+
### Example
346+
```java
347+
// Import classes:
348+
import org.openapitools.client.ApiClient;
349+
import org.openapitools.client.ApiException;
350+
import org.openapitools.client.Configuration;
351+
import org.openapitools.client.models.*;
352+
import org.openapitools.client.api.FakeApi;
353+
354+
public class Example {
355+
public static void main(String[] args) {
356+
ApiClient defaultClient = Configuration.getDefaultApiClient();
357+
defaultClient.setBasePath("http://petstore.swagger.io:80/v2");
358+
359+
FakeApi apiInstance = new FakeApi(defaultClient);
360+
try {
361+
RequiredNullableBody result = apiInstance.fakeRequiredNullableBodyGet();
362+
System.out.println(result);
363+
} catch (ApiException e) {
364+
System.err.println("Exception when calling FakeApi#fakeRequiredNullableBodyGet");
365+
System.err.println("Status code: " + e.getCode());
366+
System.err.println("Reason: " + e.getResponseBody());
367+
System.err.println("Response headers: " + e.getResponseHeaders());
368+
e.printStackTrace();
369+
}
370+
}
371+
}
372+
```
373+
374+
### Parameters
375+
This endpoint does not need any parameter.
376+
377+
### Return type
378+
379+
[**RequiredNullableBody**](RequiredNullableBody.md)
380+
381+
### Authorization
382+
383+
No authorization required
384+
385+
### HTTP request headers
386+
387+
- **Content-Type**: Not defined
388+
- **Accept**: application/json
389+
390+
### HTTP response details
391+
| Status code | Description | Response headers |
392+
|-------------|-------------|------------------|
393+
| **200** | success | - |
394+
336395
<a id="fakeUploadRefRequestBodies"></a>
337396
# **fakeUploadRefRequestBodies**
338397
> ModelApiResponse fakeUploadRefRequestBodies(petId, additionalMetadata, _file)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
# NullableEnum
4+
5+
## Enum
6+
7+
8+
* `CUSTOM` (value: `"custom"`)
9+
10+
11+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
3+
# RequiredNullableBody
4+
5+
6+
## Properties
7+
8+
| Name | Type | Description | Notes |
9+
|------------ | ------------- | ------------- | -------------|
10+
|**integerProp** | **Integer** | | |
11+
|**numberProp** | **BigDecimal** | | |
12+
|**booleanProp** | **Boolean** | | |
13+
|**stringProp** | **String** | | |
14+
|**dateProp** | **LocalDate** | | |
15+
|**datetimeProp** | **OffsetDateTime** | | |
16+
|**arrayNullableProp** | **List&lt;Object&gt;** | | |
17+
|**arrayAndItemsNullableProp** | **List&lt;Object&gt;** | | |
18+
|**arrayItemsNullable** | **List&lt;Object&gt;** | | |
19+
|**objectNullableProp** | **Map&lt;String, Object&gt;** | | |
20+
|**objectAndItemsNullableProp** | **Map&lt;String, Object&gt;** | | |
21+
|**objectItemsNullable** | **Map&lt;String, Object&gt;** | | |
22+
|**customRefEnum** | **NullableEnum** | | |
23+
|**customEnum** | [**CustomEnumEnum**](#CustomEnumEnum) | | |
24+
25+
26+
27+
## Enum: CustomEnumEnum
28+
29+
| Name | Value |
30+
|---- | -----|
31+
| CUSTOM | &quot;custom&quot; |
32+
33+
34+

‎samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri
313313
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Quadrilateral.CustomTypeAdapterFactory());
314314
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.QuadrilateralInterface.CustomTypeAdapterFactory());
315315
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ReadOnlyFirst.CustomTypeAdapterFactory());
316+
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.RequiredNullableBody.CustomTypeAdapterFactory());
316317
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Scalar.CustomTypeAdapterFactory());
317318
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ScalarAnyOf.CustomTypeAdapterFactory());
318319
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ScaleneTriangle.CustomTypeAdapterFactory());

0 commit comments

Comments
 (0)