diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index 77b471c59c9..b8bf2bcd669 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -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; diff --git a/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml b/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml index 5877e4448fa..4b20b4fa28b 100644 --- a/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml @@ -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 \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson-3.1/README.md b/samples/client/petstore/java/okhttp-gson-3.1/README.md index ef09be2b770..4e0b2c0ce5f 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/README.md +++ b/samples/client/petstore/java/okhttp-gson-3.1/README.md @@ -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 diff --git a/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml index 4f61199e49a..262309383b0 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml @@ -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: diff --git a/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md b/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md index 12709419253..19db959c0ed 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md +++ b/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md @@ -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 | | + +# **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** | | - | + + +# **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** | | - | + + +# **fakeInlineSchemaAnyofPath3Get** +> List<Object> 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 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<Object>** + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | | - | + # **op1** > Object op1() diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/api/FakeApi.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/api/FakeApi.java index 198eb7a1ba6..67436864a00 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/api/FakeApi.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/api/FakeApi.java @@ -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 + + + +
Status Code Description Response Headers
200 -
+ */ + 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 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 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 + + + +
Status Code Description Response Headers
200 -
+ */ + public Object fakeInlineSchemaAnyofPath1Get() throws ApiException { + ApiResponse localVarResp = fakeInlineSchemaAnyofPath1GetWithHttpInfo(); + return localVarResp.getData(); + } + + /** + * + * + * @return ApiResponse<Object> + * @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 -
+ */ + public ApiResponse fakeInlineSchemaAnyofPath1GetWithHttpInfo() throws ApiException { + okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath1GetValidateBeforeCall(null); + Type localVarReturnType = new TypeToken(){}.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 + + + +
Status Code Description Response Headers
200 -
+ */ + public okhttp3.Call fakeInlineSchemaAnyofPath1GetAsync(final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath1GetValidateBeforeCall(_callback); + Type localVarReturnType = new TypeToken(){}.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 + + + +
Status Code Description Response Headers
200 -
+ */ + 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 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 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 + + + +
Status Code Description Response Headers
200 -
+ */ + public Object fakeInlineSchemaAnyofPath2Get() throws ApiException { + ApiResponse localVarResp = fakeInlineSchemaAnyofPath2GetWithHttpInfo(); + return localVarResp.getData(); + } + + /** + * + * + * @return ApiResponse<Object> + * @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 -
+ */ + public ApiResponse fakeInlineSchemaAnyofPath2GetWithHttpInfo() throws ApiException { + okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath2GetValidateBeforeCall(null); + Type localVarReturnType = new TypeToken(){}.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 + + + +
Status Code Description Response Headers
200 -
+ */ + public okhttp3.Call fakeInlineSchemaAnyofPath2GetAsync(final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath2GetValidateBeforeCall(_callback); + Type localVarReturnType = new TypeToken(){}.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 + + + +
Status Code Description Response Headers
200 -
+ */ + 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 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 fakeInlineSchemaAnyofPath3GetValidateBeforeCall(final ApiCallback _callback) throws ApiException { + return fakeInlineSchemaAnyofPath3GetCall(_callback); + + } + + /** + * + * + * @return List<Object> + * @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 -
+ */ + public List fakeInlineSchemaAnyofPath3Get() throws ApiException { + ApiResponse> localVarResp = fakeInlineSchemaAnyofPath3GetWithHttpInfo(); + return localVarResp.getData(); + } + + /** + * + * + * @return ApiResponse<List<Object>> + * @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 -
+ */ + public ApiResponse> fakeInlineSchemaAnyofPath3GetWithHttpInfo() throws ApiException { + okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath3GetValidateBeforeCall(null); + Type localVarReturnType = new TypeToken>(){}.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 + + + +
Status Code Description Response Headers
200 -
+ */ + public okhttp3.Call fakeInlineSchemaAnyofPath3GetAsync(final ApiCallback> _callback) throws ApiException { + + okhttp3.Call localVarCall = fakeInlineSchemaAnyofPath3GetValidateBeforeCall(_callback); + Type localVarReturnType = new TypeToken>(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } /** * Build call for op1 * @param _callback Callback for upload/download progress