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

Fix NPE in ModelUtils getType #19014

Merged
merged 1 commit into from
Jun 25, 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 @@ -2128,7 +2128,7 @@ public static String getType(Schema schema) {
}

if (schema instanceof JsonSchema) {
if (schema.getTypes() != null) {
if (schema.getTypes() != null && !schema.getTypes().isEmpty()) {
return String.valueOf(schema.getTypes().iterator().next());
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,47 @@ paths:
responses:
'200':
description: Successful Response
"/fake/inline/schema/anyof/path1":
get:
tags:
- fake
responses:
'200':
description: ''
content:
application/json:
schema:
anyOf:
- type: 'null'
- "$ref": "#/components/schemas/myObject"
"/fake/inline/schema/anyof/path2":
get:
tags:
- fake
responses:
'200':
description: ''
content:
application/json:
schema:
anyOf:
- "$ref": "#/components/schemas/myObject"
- type: 'null'
"/fake/inline/schema/anyof/path3":
get:
tags:
- fake
responses:
'200':
description: ''
content:
application/json:
schema:
anyOf:
- type: array
items:
"$ref": "#/components/schemas/myObject"
- type: 'null'
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
Expand Down Expand Up @@ -981,3 +1022,5 @@ components:
AllOfSimpleModel:
allOf:
- $ref: '#/components/schemas/SimpleModelWithArrayProperty'
myObject:
type: object
7 changes: 5 additions & 2 deletions samples/client/petstore/java/okhttp-gson-3.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public class Example {

FakeApi apiInstance = new FakeApi(defaultClient);
try {
Object result = apiInstance.op1();
Object result = apiInstance.fakeInlineSchemaAnyofPath1Get();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#op1");
System.err.println("Exception when calling FakeApi#fakeInlineSchemaAnyofPath1Get");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
Expand All @@ -113,6 +113,9 @@ All URIs are relative to *http://petstore.swagger.io/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*FakeApi* | [**fakeInlineSchemaAnyofPath1Get**](docs/FakeApi.md#fakeInlineSchemaAnyofPath1Get) | **GET** /fake/inline/schema/anyof/path1 |
*FakeApi* | [**fakeInlineSchemaAnyofPath2Get**](docs/FakeApi.md#fakeInlineSchemaAnyofPath2Get) | **GET** /fake/inline/schema/anyof/path2 |
*FakeApi* | [**fakeInlineSchemaAnyofPath3Get**](docs/FakeApi.md#fakeInlineSchemaAnyofPath3Get) | **GET** /fake/inline/schema/anyof/path3 |
*FakeApi* | [**op1**](docs/FakeApi.md#op1) | **POST** /fake/api/changeowner | op1
*FakeApi* | [**op2**](docs/FakeApi.md#op2) | **POST** /fake/api/changename | op2
*FakeApi* | [**op3**](docs/FakeApi.md#op3) | **POST** /fake/api/query/enum | op3
Expand Down
43 changes: 43 additions & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,47 @@ paths:
- fake
x-accepts:
- application/json
/fake/inline/schema/anyof/path1:
get:
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/myObject'
description: ""
tags:
- fake
x-accepts:
- application/json
/fake/inline/schema/anyof/path2:
get:
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/myObject'
description: ""
tags:
- fake
x-accepts:
- application/json
/fake/inline/schema/anyof/path3:
get:
responses:
"200":
content:
application/json:
schema:
items:
$ref: '#/components/schemas/myObject'
nullable: true
description: ""
tags:
- fake
x-accepts:
- application/json
components:
parameters:
ref_to_uuid:
Expand Down Expand Up @@ -1074,6 +1115,8 @@ components:
AllOfSimpleModel:
allOf:
- $ref: '#/components/schemas/SimpleModelWithArrayProperty'
myObject:
type: object
updatePetWithForm_request:
properties:
name:
Expand Down
171 changes: 171 additions & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All URIs are relative to *http://petstore.swagger.io/v2*

| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**fakeInlineSchemaAnyofPath1Get**](FakeApi.md#fakeInlineSchemaAnyofPath1Get) | **GET** /fake/inline/schema/anyof/path1 | |
| [**fakeInlineSchemaAnyofPath2Get**](FakeApi.md#fakeInlineSchemaAnyofPath2Get) | **GET** /fake/inline/schema/anyof/path2 | |
| [**fakeInlineSchemaAnyofPath3Get**](FakeApi.md#fakeInlineSchemaAnyofPath3Get) | **GET** /fake/inline/schema/anyof/path3 | |
| [**op1**](FakeApi.md#op1) | **POST** /fake/api/changeowner | op1 |
| [**op2**](FakeApi.md#op2) | **POST** /fake/api/changename | op2 |
| [**op3**](FakeApi.md#op3) | **POST** /fake/api/query/enum | op3 |
Expand All @@ -13,6 +16,174 @@ All URIs are relative to *http://petstore.swagger.io/v2*
| [**responseRefToRef**](FakeApi.md#responseRefToRef) | **GET** /ref/ref | |


<a id="fakeInlineSchemaAnyofPath1Get"></a>
# **fakeInlineSchemaAnyofPath1Get**
> Object fakeInlineSchemaAnyofPath1Get()



### 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.FakeApi;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io/v2");

FakeApi apiInstance = new FakeApi(defaultClient);
try {
Object result = apiInstance.fakeInlineSchemaAnyofPath1Get();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#fakeInlineSchemaAnyofPath1Get");
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

**Object**

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json

### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | | - |

<a id="fakeInlineSchemaAnyofPath2Get"></a>
# **fakeInlineSchemaAnyofPath2Get**
> Object fakeInlineSchemaAnyofPath2Get()



### 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.FakeApi;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io/v2");

FakeApi apiInstance = new FakeApi(defaultClient);
try {
Object result = apiInstance.fakeInlineSchemaAnyofPath2Get();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#fakeInlineSchemaAnyofPath2Get");
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

**Object**

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json

### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | | - |

<a id="fakeInlineSchemaAnyofPath3Get"></a>
# **fakeInlineSchemaAnyofPath3Get**
> List&lt;Object&gt; fakeInlineSchemaAnyofPath3Get()



### 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.FakeApi;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io/v2");

FakeApi apiInstance = new FakeApi(defaultClient);
try {
List<Object> result = apiInstance.fakeInlineSchemaAnyofPath3Get();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#fakeInlineSchemaAnyofPath3Get");
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

**List&lt;Object&gt;**

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json

### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | | - |

<a id="op1"></a>
# **op1**
> Object op1()
Expand Down
Loading
Loading