diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java index 3f5465a3c668..daed144eb13d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java @@ -933,6 +933,11 @@ public class OpenAPINormalizer { return new Schema(); } + // return schema if nothing in 3.1 spec types to normalize + if (schema.getTypes() == null) { + return schema; + } + // process null if (schema.getTypes().contains("null")) { schema.setNullable(true); 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 4f5478f77913..491785afdb81 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 @@ -609,6 +609,44 @@ paths: $ref: '#/components/responses/ref' parameters: - $ref: '#/components/parameters/ref_to_uuid' + "/fake/api/changeowner": + post: + summary: op1 + operationId: op1 + tags: + - fake + parameters: [] + responses: + '201': + description: Successful Response + content: + application/json: + schema: {} + '422': + description: Validation Error + content: + application/json: + schema: + "$ref": "#/components/schemas/HTTPValidationError" + "/fake/api/changename": + post: + summary: op2 + operationId: op2 + tags: + - fake + parameters: [] + responses: + '201': + description: Successful Response + content: + application/json: + schema: {} + '422': + description: Validation Error + content: + application/json: + schema: + "$ref": "#/components/schemas/HTTPValidationError" externalDocs: description: Find out more about Swagger url: 'http://swagger.io' @@ -847,3 +885,7 @@ components: description: test array in 3.1 spec items: type: string + HTTPValidationError: + properties: {} + type: object + title: HTTPValidationError 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 8a4562dbc092..8e78bf3d184d 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/README.md +++ b/samples/client/petstore/java/okhttp-gson-3.1/README.md @@ -91,12 +91,11 @@ public class Example { defaultClient.setBasePath("http://petstore.swagger.io/v2"); FakeApi apiInstance = new FakeApi(defaultClient); - UUID refToUuid = UUID.fromString("61864654-6e6b-4152-a62f-795fdd606bc2"); // UUID | to test ref to parameter (uuid) try { - String result = apiInstance.refToRefParameter(refToUuid); + Object result = apiInstance.op1(); System.out.println(result); } catch (ApiException e) { - System.err.println("Exception when calling FakeApi#refToRefParameter"); + System.err.println("Exception when calling FakeApi#op1"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); @@ -113,6 +112,8 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*FakeApi* | [**op1**](docs/FakeApi.md#op1) | **POST** /fake/api/changeowner | op1 +*FakeApi* | [**op2**](docs/FakeApi.md#op2) | **POST** /fake/api/changename | op2 *FakeApi* | [**refToRefParameter**](docs/FakeApi.md#refToRefParameter) | **GET** /ref/ref_to_parameter | *FakeApi* | [**responseNoRef**](docs/FakeApi.md#responseNoRef) | **GET** /no_ref | *FakeApi* | [**responseRefToNoRef**](docs/FakeApi.md#responseRefToNoRef) | **GET** /ref/no_ref | 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 6546aa0e4039..c6c895706207 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 @@ -654,6 +654,46 @@ paths: x-accepts: text/plain parameters: - $ref: '#/components/parameters/ref_to_uuid' + /fake/api/changeowner: + post: + operationId: op1 + parameters: [] + responses: + "201": + content: + application/json: + schema: {} + description: Successful Response + "422": + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPValidationError' + description: Validation Error + summary: op1 + tags: + - fake + x-accepts: application/json + /fake/api/changename: + post: + operationId: op2 + parameters: [] + responses: + "201": + content: + application/json: + schema: {} + description: Successful Response + "422": + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPValidationError' + description: Validation Error + summary: op2 + tags: + - fake + x-accepts: application/json components: parameters: ref_to_uuid: @@ -912,6 +952,10 @@ components: items: type: string type: array + HTTPValidationError: + properties: {} + title: HTTPValidationError + 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 79da3fbb4fd3..a4c5c8b350e4 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,12 +4,128 @@ All URIs are relative to *http://petstore.swagger.io/v2* | Method | HTTP request | Description | |------------- | ------------- | -------------| +| [**op1**](FakeApi.md#op1) | **POST** /fake/api/changeowner | op1 | +| [**op2**](FakeApi.md#op2) | **POST** /fake/api/changename | op2 | | [**refToRefParameter**](FakeApi.md#refToRefParameter) | **GET** /ref/ref_to_parameter | | | [**responseNoRef**](FakeApi.md#responseNoRef) | **GET** /no_ref | | | [**responseRefToNoRef**](FakeApi.md#responseRefToNoRef) | **GET** /ref/no_ref | | | [**responseRefToRef**](FakeApi.md#responseRefToRef) | **GET** /ref/ref | | + +# **op1** +> Object op1() + +op1 + +### 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.op1(); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling FakeApi#op1"); + 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 | +|-------------|-------------|------------------| +| **201** | Successful Response | - | +| **422** | Validation Error | - | + + +# **op2** +> Object op2() + +op2 + +### 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.op2(); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling FakeApi#op2"); + 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 | +|-------------|-------------|------------------| +| **201** | Successful Response | - | +| **422** | Validation Error | - | + # **refToRefParameter** > String refToRefParameter(refToUuid) 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 c830be226b64..54a7d12652a0 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 @@ -72,6 +72,240 @@ public class FakeApi { this.localCustomBaseUrl = customBaseUrl; } + /** + * Build call for op1 + * @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
201 Successful Response -
422 Validation Error -
+ */ + public okhttp3.Call op1Call(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/api/changeowner"; + + 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, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call op1ValidateBeforeCall(final ApiCallback _callback) throws ApiException { + return op1Call(_callback); + + } + + /** + * op1 + * + * @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
201 Successful Response -
422 Validation Error -
+ */ + public Object op1() throws ApiException { + ApiResponse localVarResp = op1WithHttpInfo(); + return localVarResp.getData(); + } + + /** + * op1 + * + * @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
201 Successful Response -
422 Validation Error -
+ */ + public ApiResponse op1WithHttpInfo() throws ApiException { + okhttp3.Call localVarCall = op1ValidateBeforeCall(null); + Type localVarReturnType = new TypeToken(){}.getType(); + return localVarApiClient.execute(localVarCall, localVarReturnType); + } + + /** + * op1 (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
201 Successful Response -
422 Validation Error -
+ */ + public okhttp3.Call op1Async(final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = op1ValidateBeforeCall(_callback); + Type localVarReturnType = new TypeToken(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } + /** + * Build call for op2 + * @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
201 Successful Response -
422 Validation Error -
+ */ + public okhttp3.Call op2Call(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/api/changename"; + + 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, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call op2ValidateBeforeCall(final ApiCallback _callback) throws ApiException { + return op2Call(_callback); + + } + + /** + * op2 + * + * @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
201 Successful Response -
422 Validation Error -
+ */ + public Object op2() throws ApiException { + ApiResponse localVarResp = op2WithHttpInfo(); + return localVarResp.getData(); + } + + /** + * op2 + * + * @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
201 Successful Response -
422 Validation Error -
+ */ + public ApiResponse op2WithHttpInfo() throws ApiException { + okhttp3.Call localVarCall = op2ValidateBeforeCall(null); + Type localVarReturnType = new TypeToken(){}.getType(); + return localVarApiClient.execute(localVarCall, localVarReturnType); + } + + /** + * op2 (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
201 Successful Response -
422 Validation Error -
+ */ + public okhttp3.Call op2Async(final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = op2ValidateBeforeCall(_callback); + Type localVarReturnType = new TypeToken(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } /** * Build call for refToRefParameter * @param refToUuid to test ref to parameter (uuid) (required)