Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][JAVA] oneOf/anyOf multiple constructors with same erasure #18548 #18645

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi. this is consistent with the constructor implementation in oneOf

super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
setActualInstance(o);
}

{{/anyOf}}
static {
{{#composedSchemas}}
{{#anyOf}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public MyExamplePostRequest() {
super("oneOf", Boolean.FALSE);
}

public MyExamplePostRequest(String o) {
public MyExamplePostRequest(Object o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions samples/client/petstore/java/okhttp-gson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions samples/client/petstore/java/okhttp-gson/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down Expand Up @@ -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:
Expand Down
118 changes: 118 additions & 0 deletions samples/client/petstore/java/okhttp-gson/docs/DefaultApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |


<a id="fakeAnyOfWIthSameErasureGet"></a>
# **fakeAnyOfWIthSameErasureGet**
> FakeAnyOfWIthSameErasureGet200Response fakeAnyOfWIthSameErasureGet()


Test route, this shouldn&#39;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 | - |

<a id="fakeOneOfWIthSameErasureGet"></a>
# **fakeOneOfWIthSameErasureGet**
> FakeOneOfWIthSameErasureGet200Response fakeOneOfWIthSameErasureGet()


Test route, this shouldn&#39;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 | - |

<a id="fooGet"></a>
# **fooGet**
> FooGetDefaultResponse fooGet()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


# FakeAnyOfWIthSameErasureGet200Response


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|



Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


# FakeOneOfWIthSameErasureGet200Response


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|



Loading
Loading