fix NPE in get type, add test (#19014)

This commit is contained in:
William Cheng 2024-06-25 18:05:09 +08:00 committed by GitHub
parent 6aa825bcf7
commit da7105bc6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 602 additions and 3 deletions

View File

@ -2128,7 +2128,7 @@ public class ModelUtils {
}
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;

View File

@ -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'
@ -981,3 +1022,5 @@ components:
AllOfSimpleModel:
allOf:
- $ref: '#/components/schemas/SimpleModelWithArrayProperty'
myObject:
type: object

View File

@ -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());
@ -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

View File

@ -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:
@ -1074,6 +1115,8 @@ components:
AllOfSimpleModel:
allOf:
- $ref: '#/components/schemas/SimpleModelWithArrayProperty'
myObject:
type: object
updatePetWithForm_request:
properties:
name:

View File

@ -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 |
@ -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()

View File

@ -73,6 +73,345 @@ public class FakeApi {
this.localCustomBaseUrl = customBaseUrl;
}
/**
* Build call for fakeInlineSchemaAnyofPath1Get
* @param _callback Callback for upload/download progress
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public okhttp3.Call fakeInlineSchemaAnyofPath1GetCall(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/inline/schema/anyof/path1";
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
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 fakeInlineSchemaAnyofPath1GetValidateBeforeCall(final ApiCallback _callback) throws ApiException {
return fakeInlineSchemaAnyofPath1GetCall(_callback);
}
/**
*
*
* @return Object
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public Object fakeInlineSchemaAnyofPath1Get() throws ApiException {
ApiResponse<Object> localVarResp = fakeInlineSchemaAnyofPath1GetWithHttpInfo();
return localVarResp.getData();
}
/**
*
*
* @return ApiResponse&lt;Object&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public ApiResponse<Object> fakeInlineSchemaAnyofPath1GetWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath1GetValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<Object>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
/**
* (asynchronously)
*
* @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
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public okhttp3.Call fakeInlineSchemaAnyofPath1GetAsync(final ApiCallback<Object> _callback) throws ApiException {
okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath1GetValidateBeforeCall(_callback);
Type localVarReturnType = new TypeToken<Object>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
/**
* Build call for fakeInlineSchemaAnyofPath2Get
* @param _callback Callback for upload/download progress
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public okhttp3.Call fakeInlineSchemaAnyofPath2GetCall(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/inline/schema/anyof/path2";
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
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 fakeInlineSchemaAnyofPath2GetValidateBeforeCall(final ApiCallback _callback) throws ApiException {
return fakeInlineSchemaAnyofPath2GetCall(_callback);
}
/**
*
*
* @return Object
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public Object fakeInlineSchemaAnyofPath2Get() throws ApiException {
ApiResponse<Object> localVarResp = fakeInlineSchemaAnyofPath2GetWithHttpInfo();
return localVarResp.getData();
}
/**
*
*
* @return ApiResponse&lt;Object&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public ApiResponse<Object> fakeInlineSchemaAnyofPath2GetWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath2GetValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<Object>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
/**
* (asynchronously)
*
* @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
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public okhttp3.Call fakeInlineSchemaAnyofPath2GetAsync(final ApiCallback<Object> _callback) throws ApiException {
okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath2GetValidateBeforeCall(_callback);
Type localVarReturnType = new TypeToken<Object>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
/**
* Build call for fakeInlineSchemaAnyofPath3Get
* @param _callback Callback for upload/download progress
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public okhttp3.Call fakeInlineSchemaAnyofPath3GetCall(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/inline/schema/anyof/path3";
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
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 fakeInlineSchemaAnyofPath3GetValidateBeforeCall(final ApiCallback _callback) throws ApiException {
return fakeInlineSchemaAnyofPath3GetCall(_callback);
}
/**
*
*
* @return List&lt;Object&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public List<Object> fakeInlineSchemaAnyofPath3Get() throws ApiException {
ApiResponse<List<Object>> localVarResp = fakeInlineSchemaAnyofPath3GetWithHttpInfo();
return localVarResp.getData();
}
/**
*
*
* @return ApiResponse&lt;List&lt;Object&gt;&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public ApiResponse<List<Object>> fakeInlineSchemaAnyofPath3GetWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath3GetValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<List<Object>>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
/**
* (asynchronously)
*
* @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
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public okhttp3.Call fakeInlineSchemaAnyofPath3GetAsync(final ApiCallback<List<Object>> _callback) throws ApiException {
okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath3GetValidateBeforeCall(_callback);
Type localVarReturnType = new TypeToken<List<Object>>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
/**
* Build call for op1
* @param _callback Callback for upload/download progress