From 36c174efcd5cc7238ed405d463a4f4d72724b721 Mon Sep 17 00:00:00 2001 From: Bethibaned Date: Sun, 12 May 2024 10:44:26 +0200 Subject: [PATCH 1/2] [BUG][JAVA] oneOf/anyOf multiple constructors with same erasure #18548 --- .../okhttp-gson/anyof_model.mustache | 4 +- .../okhttp-gson/oneof_model.mustache | 4 +- ...points-models-for-testing-okhttp-gson.yaml | 32 +++ .../client/model/MyExamplePostRequest.java | 2 +- .../client/model/SimpleOneOf.java | 7 +- .../client/model/OneOfStringOrInt.java | 7 +- .../client/model/StringOrInt.java | 7 +- .../java/okhttp-gson/.openapi-generator/FILES | 4 + .../petstore/java/okhttp-gson/README.md | 4 + .../java/okhttp-gson/api/openapi.yaml | 40 +++ .../java/okhttp-gson/docs/DefaultApi.md | 118 +++++++++ .../FakeAnyOfWIthSameErasureGet200Response.md | 12 + .../FakeOneOfWIthSameErasureGet200Response.md | 12 + .../java/org/openapitools/client/JSON.java | 2 + .../openapitools/client/api/DefaultApi.java | 228 ++++++++++++++++ .../AllOfModelArrayAnyOfAllOfAttributesC.java | 7 +- ...elArrayAnyOfAllOfLinkListColumn1Value.java | 7 +- .../openapitools/client/model/ArrayAnyOf.java | 7 +- .../openapitools/client/model/ArrayOneOf.java | 7 +- ...akeAnyOfWIthSameErasureGet200Response.java | 241 +++++++++++++++++ ...akeOneOfWIthSameErasureGet200Response.java | 250 ++++++++++++++++++ .../FreeFormObjectTestClassProperties.java | 7 +- .../org/openapitools/client/model/Fruit.java | 7 +- .../openapitools/client/model/FruitReq.java | 7 +- .../openapitools/client/model/GmFruit.java | 7 +- .../org/openapitools/client/model/Mammal.java | 12 +- .../client/model/NullableShape.java | 7 +- .../org/openapitools/client/model/Pig.java | 7 +- .../client/model/Quadrilateral.java | 7 +- .../org/openapitools/client/model/Scalar.java | 12 +- .../client/model/ScalarAnyOf.java | 12 +- .../org/openapitools/client/model/Shape.java | 7 +- .../client/model/ShapeOrNull.java | 7 +- .../openapitools/client/model/Triangle.java | 12 +- .../org/openapitools/client/model/Value.java | 7 +- ...nyOfWIthSameErasureGet200ResponseTest.java | 34 +++ ...neOfWIthSameErasureGet200ResponseTest.java | 34 +++ 37 files changed, 1035 insertions(+), 153 deletions(-) create mode 100644 samples/client/petstore/java/okhttp-gson/docs/FakeAnyOfWIthSameErasureGet200Response.md create mode 100644 samples/client/petstore/java/okhttp-gson/docs/FakeOneOfWIthSameErasureGet200Response.md create mode 100644 samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200ResponseTest.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200ResponseTest.java diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache index 33d93192d4cd..f2e6dc684382 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache @@ -210,13 +210,11 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}}); } - {{#anyOf}} - public {{classname}}({{{.}}} o) { + public {{classname}}(Object o) { super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}}); setActualInstance(o); } - {{/anyOf}} static { {{#composedSchemas}} {{#anyOf}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache index c2cceb5b1fe4..15d0c542ad64 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache @@ -288,13 +288,11 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}}); } - {{#oneOf}} - public {{classname}}({{{.}}} o) { + public {{classname}}(Object o) { super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}}); setActualInstance(o); } - {{/oneOf}} static { {{#composedSchemas}} {{#oneOf}} diff --git a/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml b/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml index 5e763f1989ab..c2d678c532bb 100644 --- a/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml @@ -938,6 +938,38 @@ paths: $ref: '#/components/schemas/FreeFormObject' description: request body required: true + /fake/oneOfWIthSameErasure: + get: + description: Test route, this shouldn't cause a compiler error + responses: + 200: + description: successful response + content: + application/json: + schema: + oneOf: + - type: array + items: + type: string + - type: array + items: + type: integer + /fake/anyOfWIthSameErasure: + get: + description: Test route, this shouldn't cause a compiler error + responses: + 200: + description: successful response + content: + application/json: + schema: + anyOf: + - type: array + items: + type: string + - type: array + items: + type: integer /fake/stringMap-reference: post: tags: diff --git a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java index 4b2fe83863a5..c2abb81acedd 100644 --- a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java +++ b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java @@ -124,7 +124,7 @@ public MyExamplePostRequest() { super("oneOf", Boolean.FALSE); } - public MyExamplePostRequest(String o) { + public MyExamplePostRequest(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java index 19c136f1c67b..2fc4629528e3 100644 --- a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java +++ b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java @@ -146,12 +146,7 @@ public SimpleOneOf() { super("oneOf", Boolean.FALSE); } - public SimpleOneOf(Integer o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public SimpleOneOf(String o) { + public SimpleOneOf(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java index 99d93213ab65..bcfed1bd343d 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java @@ -145,12 +145,7 @@ public OneOfStringOrInt() { super("oneOf", Boolean.FALSE); } - public OneOfStringOrInt(Integer o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public OneOfStringOrInt(String o) { + public OneOfStringOrInt(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java index 5b8068a9829e..1c9c3599696a 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java @@ -140,12 +140,7 @@ public StringOrInt() { super("anyOf", Boolean.FALSE); } - public StringOrInt(Integer o) { - super("anyOf", Boolean.FALSE); - setActualInstance(o); - } - - public StringOrInt(String o) { + public StringOrInt(Object o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES b/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES index d42445a12dac..02515104fd6b 100644 --- a/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES +++ b/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES @@ -42,8 +42,10 @@ docs/EnumClass.md docs/EnumStringDiscriminator.md docs/EnumTest.md docs/EquilateralTriangle.md +docs/FakeAnyOfWIthSameErasureGet200Response.md docs/FakeApi.md docs/FakeClassnameTags123Api.md +docs/FakeOneOfWIthSameErasureGet200Response.md docs/FileSchemaTestClass.md docs/Foo.md docs/FooGetDefaultResponse.md @@ -185,6 +187,8 @@ src/main/java/org/openapitools/client/model/EnumClass.java src/main/java/org/openapitools/client/model/EnumStringDiscriminator.java src/main/java/org/openapitools/client/model/EnumTest.java src/main/java/org/openapitools/client/model/EquilateralTriangle.java +src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java +src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java src/main/java/org/openapitools/client/model/FileSchemaTestClass.java src/main/java/org/openapitools/client/model/Foo.java src/main/java/org/openapitools/client/model/FooGetDefaultResponse.java diff --git a/samples/client/petstore/java/okhttp-gson/README.md b/samples/client/petstore/java/okhttp-gson/README.md index abd680c94f49..3f8a140359de 100644 --- a/samples/client/petstore/java/okhttp-gson/README.md +++ b/samples/client/petstore/java/okhttp-gson/README.md @@ -118,6 +118,8 @@ Class | Method | HTTP request | Description *AnotherFakeApi* | [**getParameterArrayNumber**](docs/AnotherFakeApi.md#getParameterArrayNumber) | **GET** /fake/parameter-array-number | parameter array number default value *AnotherFakeApi* | [**getParameterStringNumber**](docs/AnotherFakeApi.md#getParameterStringNumber) | **GET** /fake/parameter-string-number | parameter string number *AnotherFakeApi* | [**nullRequestBody**](docs/AnotherFakeApi.md#nullRequestBody) | **GET** /fake/null-request-body | null request body +*DefaultApi* | [**fakeAnyOfWIthSameErasureGet**](docs/DefaultApi.md#fakeAnyOfWIthSameErasureGet) | **GET** /fake/anyOfWIthSameErasure | +*DefaultApi* | [**fakeOneOfWIthSameErasureGet**](docs/DefaultApi.md#fakeOneOfWIthSameErasureGet) | **GET** /fake/oneOfWIthSameErasure | *DefaultApi* | [**fooGet**](docs/DefaultApi.md#fooGet) | **GET** /foo | *FakeApi* | [**fakeGetFreeFormObjectGet**](docs/FakeApi.md#fakeGetFreeFormObjectGet) | **GET** /fake/get-free-form-object | *FakeApi* | [**fakeOuterBooleanSerialize**](docs/FakeApi.md#fakeOuterBooleanSerialize) | **POST** /fake/outer/boolean | @@ -202,6 +204,8 @@ Class | Method | HTTP request | Description - [EnumStringDiscriminator](docs/EnumStringDiscriminator.md) - [EnumTest](docs/EnumTest.md) - [EquilateralTriangle](docs/EquilateralTriangle.md) + - [FakeAnyOfWIthSameErasureGet200Response](docs/FakeAnyOfWIthSameErasureGet200Response.md) + - [FakeOneOfWIthSameErasureGet200Response](docs/FakeOneOfWIthSameErasureGet200Response.md) - [FileSchemaTestClass](docs/FileSchemaTestClass.md) - [Foo](docs/Foo.md) - [FooGetDefaultResponse](docs/FooGetDefaultResponse.md) diff --git a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml index 7170d2f6afb9..979f2695d996 100644 --- a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml @@ -992,6 +992,30 @@ paths: x-content-type: application/json x-accepts: - application/json + /fake/oneOfWIthSameErasure: + get: + description: "Test route, this shouldn't cause a compiler error" + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/_fake_oneOfWIthSameErasure_get_200_response' + description: successful response + x-accepts: + - application/json + /fake/anyOfWIthSameErasure: + get: + description: "Test route, this shouldn't cause a compiler error" + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/_fake_anyOfWIthSameErasure_get_200_response' + description: successful response + x-accepts: + - application/json /fake/stringMap-reference: post: description: "" @@ -2887,6 +2911,22 @@ components: - param - param2 type: object + _fake_oneOfWIthSameErasure_get_200_response: + oneOf: + - items: + type: string + type: array + - items: + type: integer + type: array + _fake_anyOfWIthSameErasure_get_200_response: + anyOf: + - items: + type: string + type: array + - items: + type: integer + type: array testInlineFreeformAdditionalProperties_request: additionalProperties: true properties: diff --git a/samples/client/petstore/java/okhttp-gson/docs/DefaultApi.md b/samples/client/petstore/java/okhttp-gson/docs/DefaultApi.md index 3a31549ed3ea..2b2cb4f9098c 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/DefaultApi.md +++ b/samples/client/petstore/java/okhttp-gson/docs/DefaultApi.md @@ -4,9 +4,127 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | Method | HTTP request | Description | |------------- | ------------- | -------------| +| [**fakeAnyOfWIthSameErasureGet**](DefaultApi.md#fakeAnyOfWIthSameErasureGet) | **GET** /fake/anyOfWIthSameErasure | | +| [**fakeOneOfWIthSameErasureGet**](DefaultApi.md#fakeOneOfWIthSameErasureGet) | **GET** /fake/oneOfWIthSameErasure | | | [**fooGet**](DefaultApi.md#fooGet) | **GET** /foo | | + +# **fakeAnyOfWIthSameErasureGet** +> FakeAnyOfWIthSameErasureGet200Response fakeAnyOfWIthSameErasureGet() + + + +Test route, this shouldn't cause a compiler error + +### Example +```java +// Import classes: +import org.openapitools.client.ApiClient; +import org.openapitools.client.ApiException; +import org.openapitools.client.Configuration; +import org.openapitools.client.models.*; +import org.openapitools.client.api.DefaultApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://petstore.swagger.io:80/v2"); + + DefaultApi apiInstance = new DefaultApi(defaultClient); + try { + FakeAnyOfWIthSameErasureGet200Response result = apiInstance.fakeAnyOfWIthSameErasureGet(); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling DefaultApi#fakeAnyOfWIthSameErasureGet"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**FakeAnyOfWIthSameErasureGet200Response**](FakeAnyOfWIthSameErasureGet200Response.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful response | - | + + +# **fakeOneOfWIthSameErasureGet** +> FakeOneOfWIthSameErasureGet200Response fakeOneOfWIthSameErasureGet() + + + +Test route, this shouldn't cause a compiler error + +### Example +```java +// Import classes: +import org.openapitools.client.ApiClient; +import org.openapitools.client.ApiException; +import org.openapitools.client.Configuration; +import org.openapitools.client.models.*; +import org.openapitools.client.api.DefaultApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://petstore.swagger.io:80/v2"); + + DefaultApi apiInstance = new DefaultApi(defaultClient); + try { + FakeOneOfWIthSameErasureGet200Response result = apiInstance.fakeOneOfWIthSameErasureGet(); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling DefaultApi#fakeOneOfWIthSameErasureGet"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**FakeOneOfWIthSameErasureGet200Response**](FakeOneOfWIthSameErasureGet200Response.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful response | - | + # **fooGet** > FooGetDefaultResponse fooGet() diff --git a/samples/client/petstore/java/okhttp-gson/docs/FakeAnyOfWIthSameErasureGet200Response.md b/samples/client/petstore/java/okhttp-gson/docs/FakeAnyOfWIthSameErasureGet200Response.md new file mode 100644 index 000000000000..c224eb3d572f --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/docs/FakeAnyOfWIthSameErasureGet200Response.md @@ -0,0 +1,12 @@ + + +# FakeAnyOfWIthSameErasureGet200Response + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| + + + diff --git a/samples/client/petstore/java/okhttp-gson/docs/FakeOneOfWIthSameErasureGet200Response.md b/samples/client/petstore/java/okhttp-gson/docs/FakeOneOfWIthSameErasureGet200Response.md new file mode 100644 index 000000000000..0a3fbf6f8fca --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/docs/FakeOneOfWIthSameErasureGet200Response.md @@ -0,0 +1,12 @@ + + +# FakeOneOfWIthSameErasureGet200Response + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| + + + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java index 69d7ec7bf943..db57f2dbba89 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java @@ -269,6 +269,8 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.EnumStringDiscriminator.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.EnumTest.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.EquilateralTriangle.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FakeAnyOfWIthSameErasureGet200Response.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FakeOneOfWIthSameErasureGet200Response.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FileSchemaTestClass.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Foo.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FooGetDefaultResponse.CustomTypeAdapterFactory()); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/DefaultApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/DefaultApi.java index a2756defc239..6af7c9ef4314 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/DefaultApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/DefaultApi.java @@ -27,6 +27,8 @@ import java.io.IOException; +import org.openapitools.client.model.FakeAnyOfWIthSameErasureGet200Response; +import org.openapitools.client.model.FakeOneOfWIthSameErasureGet200Response; import org.openapitools.client.model.FooGetDefaultResponse; import java.lang.reflect.Type; @@ -72,6 +74,232 @@ public void setCustomBaseUrl(String customBaseUrl) { this.localCustomBaseUrl = customBaseUrl; } + /** + * Build call for fakeAnyOfWIthSameErasureGet + * @param _callback Callback for upload/download progress + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 successful response -
+ */ + public okhttp3.Call fakeAnyOfWIthSameErasureGetCall(final ApiCallback _callback) throws ApiException { + String basePath = null; + // Operation Servers + String[] localBasePaths = new String[] { }; + + // Determine Base Path to Use + if (localCustomBaseUrl != null){ + basePath = localCustomBaseUrl; + } else if ( localBasePaths.length > 0 ) { + basePath = localBasePaths[localHostIndex]; + } else { + basePath = null; + } + + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/fake/anyOfWIthSameErasure"; + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + if (localVarContentType != null) { + localVarHeaderParams.put("Content-Type", localVarContentType); + } + + String[] localVarAuthNames = new String[] { }; + return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call fakeAnyOfWIthSameErasureGetValidateBeforeCall(final ApiCallback _callback) throws ApiException { + return fakeAnyOfWIthSameErasureGetCall(_callback); + + } + + /** + * + * Test route, this shouldn't cause a compiler error + * @return FakeAnyOfWIthSameErasureGet200Response + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 successful response -
+ */ + public FakeAnyOfWIthSameErasureGet200Response fakeAnyOfWIthSameErasureGet() throws ApiException { + ApiResponse localVarResp = fakeAnyOfWIthSameErasureGetWithHttpInfo(); + return localVarResp.getData(); + } + + /** + * + * Test route, this shouldn't cause a compiler error + * @return ApiResponse<FakeAnyOfWIthSameErasureGet200Response> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 successful response -
+ */ + public ApiResponse fakeAnyOfWIthSameErasureGetWithHttpInfo() throws ApiException { + okhttp3.Call localVarCall = fakeAnyOfWIthSameErasureGetValidateBeforeCall(null); + Type localVarReturnType = new TypeToken(){}.getType(); + return localVarApiClient.execute(localVarCall, localVarReturnType); + } + + /** + * (asynchronously) + * Test route, this shouldn't cause a compiler error + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 successful response -
+ */ + public okhttp3.Call fakeAnyOfWIthSameErasureGetAsync(final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = fakeAnyOfWIthSameErasureGetValidateBeforeCall(_callback); + Type localVarReturnType = new TypeToken(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } + /** + * Build call for fakeOneOfWIthSameErasureGet + * @param _callback Callback for upload/download progress + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 successful response -
+ */ + public okhttp3.Call fakeOneOfWIthSameErasureGetCall(final ApiCallback _callback) throws ApiException { + String basePath = null; + // Operation Servers + String[] localBasePaths = new String[] { }; + + // Determine Base Path to Use + if (localCustomBaseUrl != null){ + basePath = localCustomBaseUrl; + } else if ( localBasePaths.length > 0 ) { + basePath = localBasePaths[localHostIndex]; + } else { + basePath = null; + } + + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/fake/oneOfWIthSameErasure"; + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + if (localVarContentType != null) { + localVarHeaderParams.put("Content-Type", localVarContentType); + } + + String[] localVarAuthNames = new String[] { }; + return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call fakeOneOfWIthSameErasureGetValidateBeforeCall(final ApiCallback _callback) throws ApiException { + return fakeOneOfWIthSameErasureGetCall(_callback); + + } + + /** + * + * Test route, this shouldn't cause a compiler error + * @return FakeOneOfWIthSameErasureGet200Response + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 successful response -
+ */ + public FakeOneOfWIthSameErasureGet200Response fakeOneOfWIthSameErasureGet() throws ApiException { + ApiResponse localVarResp = fakeOneOfWIthSameErasureGetWithHttpInfo(); + return localVarResp.getData(); + } + + /** + * + * Test route, this shouldn't cause a compiler error + * @return ApiResponse<FakeOneOfWIthSameErasureGet200Response> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 successful response -
+ */ + public ApiResponse fakeOneOfWIthSameErasureGetWithHttpInfo() throws ApiException { + okhttp3.Call localVarCall = fakeOneOfWIthSameErasureGetValidateBeforeCall(null); + Type localVarReturnType = new TypeToken(){}.getType(); + return localVarApiClient.execute(localVarCall, localVarReturnType); + } + + /** + * (asynchronously) + * Test route, this shouldn't cause a compiler error + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 successful response -
+ */ + public okhttp3.Call fakeOneOfWIthSameErasureGetAsync(final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = fakeOneOfWIthSameErasureGetValidateBeforeCall(_callback); + Type localVarReturnType = new TypeToken(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } /** * Build call for fooGet * @param _callback Callback for upload/download progress diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java index 48a7dd3e69af..68cc7c37991a 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java @@ -155,12 +155,7 @@ public AllOfModelArrayAnyOfAllOfAttributesC() { super("oneOf", Boolean.FALSE); } - public AllOfModelArrayAnyOfAllOfAttributesC(Order o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public AllOfModelArrayAnyOfAllOfAttributesC(Pet o) { + public AllOfModelArrayAnyOfAllOfAttributesC(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java index 5b960aadd5bd..b919b16b77ab 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java @@ -146,12 +146,7 @@ public AllOfModelArrayAnyOfAllOfLinkListColumn1Value() { super("anyOf", Boolean.FALSE); } - public AllOfModelArrayAnyOfAllOfLinkListColumn1Value(Tag o) { - super("anyOf", Boolean.FALSE); - setActualInstance(o); - } - - public AllOfModelArrayAnyOfAllOfLinkListColumn1Value(User o) { + public AllOfModelArrayAnyOfAllOfLinkListColumn1Value(Object o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java index 939df865d23f..6f15ba838f5a 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java @@ -151,12 +151,7 @@ public ArrayAnyOf() { super("anyOf", Boolean.FALSE); } - public ArrayAnyOf(Integer o) { - super("anyOf", Boolean.FALSE); - setActualInstance(o); - } - - public ArrayAnyOf(List o) { + public ArrayAnyOf(Object o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java index c80ca18372cc..af75f843b64e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java @@ -156,12 +156,7 @@ public ArrayOneOf() { super("oneOf", Boolean.FALSE); } - public ArrayOneOf(Integer o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public ArrayOneOf(List o) { + public ArrayOneOf(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java new file mode 100644 index 000000000000..e04a0874355d --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java @@ -0,0 +1,241 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import java.util.Objects; +import java.util.List; + + + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.JsonPrimitive; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonParseException; + +import org.openapitools.client.JSON; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.6.0-SNAPSHOT") +public class FakeAnyOfWIthSameErasureGet200Response extends AbstractOpenApiSchema { + private static final Logger log = Logger.getLogger(FakeAnyOfWIthSameErasureGet200Response.class.getName()); + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!FakeAnyOfWIthSameErasureGet200Response.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'FakeAnyOfWIthSameErasureGet200Response' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + + final Type typeInstance = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + + final Type typeInstance = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListInteger = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, FakeAnyOfWIthSameErasureGet200Response value) throws IOException { + if (value == null || value.getActualInstance() == null) { + elementAdapter.write(out, null); + return; + } + + // check if the actual instance is of the type `List` + if (value.getActualInstance() instanceof List) { + JsonPrimitive primitive = adapterListString.toJsonTree((List)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + throw new IOException("Failed to serialize as the type doesn't match anyOf schemas: List, List"); + } + + @Override + public FakeAnyOfWIthSameErasureGet200Response read(JsonReader in) throws IOException { + Object deserialized = null; + JsonElement jsonElement = elementAdapter.read(in); + + ArrayList errorMessages = new ArrayList<>(); + TypeAdapter actualAdapter = elementAdapter; + + // deserialize List + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + if (!element.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + } + actualAdapter = adapterListString; + FakeAnyOfWIthSameErasureGet200Response ret = new FakeAnyOfWIthSameErasureGet200Response(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'List'", e); + } + + throw new IOException(String.format("Failed deserialization for FakeAnyOfWIthSameErasureGet200Response: no class matches result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); + } + }.nullSafe(); + } + } + + // store a list of schema names defined in anyOf + public static final Map> schemas = new HashMap>(); + + public FakeAnyOfWIthSameErasureGet200Response() { + super("anyOf", Boolean.FALSE); + } + + public FakeAnyOfWIthSameErasureGet200Response(Object o) { + super("anyOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("List", List.class); + } + + @Override + public Map> getSchemas() { + return FakeAnyOfWIthSameErasureGet200Response.schemas; + } + + /** + * Set the instance that matches the anyOf child schema, check + * the instance parameter is valid against the anyOf child schemas: + * List, List + * + * It could be an instance of the 'anyOf' schemas. + */ + @Override + public void setActualInstance(Object instance) { + if (instance instanceof List) { + List list = (List) instance; + if (list.get(0) instanceof String) { + super.setActualInstance(instance); + return; + } + } + + throw new RuntimeException("Invalid instance type. Must be List, List"); + } + + /** + * Get the actual instance, which can be the following: + * List, List + * + * @return The actual instance (List, List) + */ + @SuppressWarnings("unchecked") + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `List`. If the actual instance is not `List`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `List` + * @throws ClassCastException if the instance is not `List` + */ + public List getListString() throws ClassCastException { + return (List)super.getActualInstance(); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to FakeAnyOfWIthSameErasureGet200Response + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate anyOf schemas one by one + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with List + try { + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + if (!element.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + } + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + // continue to the next one + } + throw new IOException(String.format("The JSON string is invalid for FakeAnyOfWIthSameErasureGet200Response with anyOf schemas: List, List. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); + } + + /** + * Create an instance of FakeAnyOfWIthSameErasureGet200Response given an JSON string + * + * @param jsonString JSON string + * @return An instance of FakeAnyOfWIthSameErasureGet200Response + * @throws IOException if the JSON string is invalid with respect to FakeAnyOfWIthSameErasureGet200Response + */ + public static FakeAnyOfWIthSameErasureGet200Response fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, FakeAnyOfWIthSameErasureGet200Response.class); + } + + /** + * Convert an instance of FakeAnyOfWIthSameErasureGet200Response to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java new file mode 100644 index 000000000000..1f57b8a4a748 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java @@ -0,0 +1,250 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import java.util.Objects; +import java.util.List; + + + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.JsonPrimitive; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonParseException; + +import org.openapitools.client.JSON; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.6.0-SNAPSHOT") +public class FakeOneOfWIthSameErasureGet200Response extends AbstractOpenApiSchema { + private static final Logger log = Logger.getLogger(FakeOneOfWIthSameErasureGet200Response.class.getName()); + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!FakeOneOfWIthSameErasureGet200Response.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'FakeOneOfWIthSameErasureGet200Response' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + + final Type typeInstance = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + + final Type typeInstance = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListInteger = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, FakeOneOfWIthSameErasureGet200Response value) throws IOException { + if (value == null || value.getActualInstance() == null) { + elementAdapter.write(out, null); + return; + } + + // check if the actual instance is of the type `List` + if (value.getActualInstance() instanceof List) { + JsonPrimitive primitive = adapterListString.toJsonTree((List)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: List, List"); + } + + @Override + public FakeOneOfWIthSameErasureGet200Response read(JsonReader in) throws IOException { + Object deserialized = null; + JsonElement jsonElement = elementAdapter.read(in); + + int match = 0; + ArrayList errorMessages = new ArrayList<>(); + TypeAdapter actualAdapter = elementAdapter; + + // deserialize List + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + if (!element.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + } + actualAdapter = adapterListString; + match++; + log.log(Level.FINER, "Input data matches schema 'List'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'List'", e); + } + + if (match == 1) { + FakeOneOfWIthSameErasureGet200Response ret = new FakeOneOfWIthSameErasureGet200Response(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; + } + + throw new IOException(String.format("Failed deserialization for FakeOneOfWIthSameErasureGet200Response: %d classes match result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", match, errorMessages, jsonElement.toString())); + } + }.nullSafe(); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap>(); + + public FakeOneOfWIthSameErasureGet200Response() { + super("oneOf", Boolean.FALSE); + } + + public FakeOneOfWIthSameErasureGet200Response(Object o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("List", List.class); + } + + @Override + public Map> getSchemas() { + return FakeOneOfWIthSameErasureGet200Response.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check + * the instance parameter is valid against the oneOf child schemas: + * List, List + * + * It could be an instance of the 'oneOf' schemas. + */ + @Override + public void setActualInstance(Object instance) { + if (instance instanceof List) { + List list = (List) instance; + if (list.get(0) instanceof String) { + super.setActualInstance(instance); + return; + } + } + + throw new RuntimeException("Invalid instance type. Must be List, List"); + } + + /** + * Get the actual instance, which can be the following: + * List, List + * + * @return The actual instance (List, List) + */ + @SuppressWarnings("unchecked") + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `List`. If the actual instance is not `List`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `List` + * @throws ClassCastException if the instance is not `List` + */ + public List getListString() throws ClassCastException { + return (List)super.getActualInstance(); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to FakeOneOfWIthSameErasureGet200Response + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with List + try { + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + if (!element.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for FakeOneOfWIthSameErasureGet200Response with oneOf schemas: List, List. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } + } + + /** + * Create an instance of FakeOneOfWIthSameErasureGet200Response given an JSON string + * + * @param jsonString JSON string + * @return An instance of FakeOneOfWIthSameErasureGet200Response + * @throws IOException if the JSON string is invalid with respect to FakeOneOfWIthSameErasureGet200Response + */ + public static FakeOneOfWIthSameErasureGet200Response fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, FakeOneOfWIthSameErasureGet200Response.class); + } + + /** + * Convert an instance of FakeOneOfWIthSameErasureGet200Response to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java index 9ac1b95f8186..25f53eaddb7c 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java @@ -148,12 +148,7 @@ public FreeFormObjectTestClassProperties() { super("oneOf", Boolean.FALSE); } - public FreeFormObjectTestClassProperties(Map o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public FreeFormObjectTestClassProperties(String o) { + public FreeFormObjectTestClassProperties(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java index 3ec330a54625..f53d79dfe489 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java @@ -151,12 +151,7 @@ public Fruit() { super("oneOf", Boolean.FALSE); } - public Fruit(Apple o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Fruit(Banana o) { + public Fruit(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java index 70c28f822bf6..3c89d4186956 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java @@ -151,12 +151,7 @@ public FruitReq() { super("oneOf", Boolean.TRUE); } - public FruitReq(AppleReq o) { - super("oneOf", Boolean.TRUE); - setActualInstance(o); - } - - public FruitReq(BananaReq o) { + public FruitReq(Object o) { super("oneOf", Boolean.TRUE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java index ed121c1ffc0a..8724a476ccc7 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java @@ -146,12 +146,7 @@ public GmFruit() { super("anyOf", Boolean.FALSE); } - public GmFruit(Apple o) { - super("anyOf", Boolean.FALSE); - setActualInstance(o); - } - - public GmFruit(Banana o) { + public GmFruit(Object o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java index b09f0819bc64..208ea09dcc66 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java @@ -196,17 +196,7 @@ public Mammal() { super("oneOf", Boolean.FALSE); } - public Mammal(Pig o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Mammal(Whale o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Mammal(Zebra o) { + public Mammal(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java index 8ae9631fb3d6..897151d5da76 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java @@ -172,12 +172,7 @@ public NullableShape() { super("oneOf", Boolean.TRUE); } - public NullableShape(Quadrilateral o) { - super("oneOf", Boolean.TRUE); - setActualInstance(o); - } - - public NullableShape(Triangle o) { + public NullableShape(Object o) { super("oneOf", Boolean.TRUE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java index e33c0a18d48b..9ac7dfb4e582 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java @@ -172,12 +172,7 @@ public Pig() { super("oneOf", Boolean.FALSE); } - public Pig(BasquePig o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Pig(DanishPig o) { + public Pig(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java index 91e31e91d9cc..31e230b38bc5 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java @@ -172,12 +172,7 @@ public Quadrilateral() { super("oneOf", Boolean.FALSE); } - public Quadrilateral(ComplexQuadrilateral o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Quadrilateral(SimpleQuadrilateral o) { + public Quadrilateral(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java index a9a6352e7449..2572cddad43e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java @@ -167,17 +167,7 @@ public Scalar() { super("oneOf", Boolean.FALSE); } - public Scalar(BigDecimal o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Scalar(Boolean o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Scalar(String o) { + public Scalar(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java index 56526ad35f14..0045468edbc3 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java @@ -163,17 +163,7 @@ public ScalarAnyOf() { super("anyOf", Boolean.FALSE); } - public ScalarAnyOf(BigDecimal o) { - super("anyOf", Boolean.FALSE); - setActualInstance(o); - } - - public ScalarAnyOf(Boolean o) { - super("anyOf", Boolean.FALSE); - setActualInstance(o); - } - - public ScalarAnyOf(String o) { + public ScalarAnyOf(Object o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java index 3da607a3da07..d8b91c1fc51f 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java @@ -172,12 +172,7 @@ public Shape() { super("oneOf", Boolean.FALSE); } - public Shape(Quadrilateral o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Shape(Triangle o) { + public Shape(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java index fa7f1b03b623..4f0a420dd894 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java @@ -172,12 +172,7 @@ public ShapeOrNull() { super("oneOf", Boolean.TRUE); } - public ShapeOrNull(Quadrilateral o) { - super("oneOf", Boolean.TRUE); - setActualInstance(o); - } - - public ShapeOrNull(Triangle o) { + public ShapeOrNull(Object o) { super("oneOf", Boolean.TRUE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java index c83f1b1296eb..15f938c11b08 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java @@ -196,17 +196,7 @@ public Triangle() { super("oneOf", Boolean.FALSE); } - public Triangle(EquilateralTriangle o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Triangle(IsoscelesTriangle o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Triangle(ScaleneTriangle o) { + public Triangle(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java index d7553fb8ba79..52c05257e7e4 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java @@ -156,12 +156,7 @@ public Value() { super("oneOf", Boolean.FALSE); } - public Value(List o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public Value(Scalar o) { + public Value(Object o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200ResponseTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200ResponseTest.java new file mode 100644 index 000000000000..22408ad06868 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200ResponseTest.java @@ -0,0 +1,34 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import java.util.List; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for FakeAnyOfWIthSameErasureGet200Response + */ +public class FakeAnyOfWIthSameErasureGet200ResponseTest { + private final FakeAnyOfWIthSameErasureGet200Response model = new FakeAnyOfWIthSameErasureGet200Response(); + + /** + * Model tests for FakeAnyOfWIthSameErasureGet200Response + */ + @Test + public void testFakeAnyOfWIthSameErasureGet200Response() { + // TODO: test FakeAnyOfWIthSameErasureGet200Response + } + +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200ResponseTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200ResponseTest.java new file mode 100644 index 000000000000..4a0bd78cb384 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200ResponseTest.java @@ -0,0 +1,34 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import java.util.List; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for FakeOneOfWIthSameErasureGet200Response + */ +public class FakeOneOfWIthSameErasureGet200ResponseTest { + private final FakeOneOfWIthSameErasureGet200Response model = new FakeOneOfWIthSameErasureGet200Response(); + + /** + * Model tests for FakeOneOfWIthSameErasureGet200Response + */ + @Test + public void testFakeOneOfWIthSameErasureGet200Response() { + // TODO: test FakeOneOfWIthSameErasureGet200Response + } + +} From adfc6ef520e1faabdd7d17cce93982716a090922 Mon Sep 17 00:00:00 2001 From: Bethibaned Date: Sun, 12 May 2024 11:05:24 +0200 Subject: [PATCH 2/2] [BUG][JAVA] oneOf/anyOf multiple constructors with same erasure #18548 --- .../Java/libraries/okhttp-gson/anyof_model.mustache | 4 ++-- .../Java/libraries/okhttp-gson/oneof_model.mustache | 8 ++++---- .../java/org/openapitools/client/model/ArrayAnyOf.java | 4 ++-- .../java/org/openapitools/client/model/ArrayOneOf.java | 4 ++-- .../model/FakeAnyOfWIthSameErasureGet200Response.java | 8 ++++---- .../model/FakeOneOfWIthSameErasureGet200Response.java | 8 ++++---- .../client/model/FreeFormObjectTestClassProperties.java | 4 ++-- .../main/java/org/openapitools/client/model/Value.java | 4 ++-- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache index f2e6dc684382..18447fc12d0f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache @@ -54,8 +54,8 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im {{/isArray}} {{#isArray}} - final Type typeInstance = new TypeToken<{{{dataType}}}>(){}.getType(); - final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstance{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = new TypeToken<{{{dataType}}}>(){}.getType(); + final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}})); {{/isArray}} {{/anyOf}} {{/composedSchemas}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache index 15d0c542ad64..31c63263e1c2 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache @@ -56,12 +56,12 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im {{/isArray}} {{#isArray}} - final Type typeInstance = new TypeToken<{{{dataType}}}>(){}.getType(); - final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstance{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = new TypeToken<{{{dataType}}}>(){}.getType(); + final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}})); {{/isArray}} {{#isMap}} - final Type typeInstance = new TypeToken<{{{dataType}}}>(){}.getType(); - final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstance{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = new TypeToken<{{{dataType}}}>(){}.getType(); + final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}})); {{/isMap}} {{/oneOf}} {{/composedSchemas}} diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java index 6f15ba838f5a..68c8a225cdfc 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java @@ -65,8 +65,8 @@ public TypeAdapter create(Gson gson, TypeToken type) { final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); final TypeAdapter adapterInteger = gson.getDelegateAdapter(this, TypeToken.get(Integer.class)); - final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstanceListString = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstanceListString)); return (TypeAdapter) new TypeAdapter() { @Override diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java index af75f843b64e..668d716d66cf 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java @@ -65,8 +65,8 @@ public TypeAdapter create(Gson gson, TypeToken type) { final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); final TypeAdapter adapterInteger = gson.getDelegateAdapter(this, TypeToken.get(Integer.class)); - final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstanceListString = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstanceListString)); return (TypeAdapter) new TypeAdapter() { @Override diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java index e04a0874355d..0a6c17c7598a 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java @@ -64,11 +64,11 @@ public TypeAdapter create(Gson gson, TypeToken type) { } final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstanceListString = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstanceListString)); - final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter> adapterListInteger = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstanceListInteger = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListInteger = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstanceListInteger)); return (TypeAdapter) new TypeAdapter() { @Override diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java index 1f57b8a4a748..6a63179cb2e7 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java @@ -64,11 +64,11 @@ public TypeAdapter create(Gson gson, TypeToken type) { } final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstanceListString = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstanceListString)); - final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter> adapterListInteger = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstanceListInteger = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListInteger = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstanceListInteger)); return (TypeAdapter) new TypeAdapter() { @Override diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java index 25f53eaddb7c..228ca3d43c79 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java @@ -64,8 +64,8 @@ public TypeAdapter create(Gson gson, TypeToken type) { } final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); final TypeAdapter adapterString = gson.getDelegateAdapter(this, TypeToken.get(String.class)); - final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter> adapterMapStringObject = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstanceMapStringObject = new TypeToken>(){}.getType(); + final TypeAdapter> adapterMapStringObject = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstanceMapStringObject)); return (TypeAdapter) new TypeAdapter() { @Override diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java index 52c05257e7e4..7a33fc1ffa31 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java @@ -66,8 +66,8 @@ public TypeAdapter create(Gson gson, TypeToken type) { final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); final TypeAdapter adapterScalar = gson.getDelegateAdapter(this, TypeToken.get(Scalar.class)); - final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter> adapterListScalar = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstanceListScalar = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListScalar = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstanceListScalar)); return (TypeAdapter) new TypeAdapter() { @Override