diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache index 141d144b701..372ea771440 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache @@ -239,10 +239,9 @@ public class {{classname}} { } {{#vendorExtensions.x-java-text-plain-string}} // for plain text response - InputStream responseBody = localVarResponse.body(); if (localVarResponse.headers().map().containsKey("Content-Type") && "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { - java.util.Scanner s = new java.util.Scanner(responseBody).useDelimiter("\\A"); + java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( localVarResponse.statusCode(), @@ -254,14 +253,11 @@ public class {{classname}} { } {{/vendorExtensions.x-java-text-plain-string}} {{^vendorExtensions.x-java-text-plain-string}} - {{#returnType}} - InputStream responseBody = localVarResponse.body(); - {{/returnType}} return new ApiResponse<{{{returnType}}}{{^returnType}}Void{{/returnType}}>( localVarResponse.statusCode(), localVarResponse.headers().map(), {{#returnType}} - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference<{{{returnType}}}>() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<{{{returnType}}}>() {}) // closes the InputStream {{/returnType}} {{^returnType}} null diff --git a/modules/openapi-generator/src/test/resources/3_0/echo_api.yaml b/modules/openapi-generator/src/test/resources/3_0/echo_api.yaml index 34ef848a500..e04cd0b3575 100644 --- a/modules/openapi-generator/src/test/resources/3_0/echo_api.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/echo_api.yaml @@ -26,6 +26,10 @@ info: servers: - url: http://localhost:3000/ paths: + # Path usually starts with parameter type such as path, query, header, form + # For body/form parameters, path starts with "/echo" so the the echo server + # will response with the same body in the HTTP request. + # # path parameter tests /path/string/{path_string}/integer/{path_integer}: get: @@ -133,8 +137,31 @@ paths: text/plain: schema: type: string + /echo/body/Pet: + post: + tags: + - body + summary: Test body parameter(s) + description: Test body parameter(s) + operationId: test/echo/body/Pet + requestBody: + $ref: '#/components/requestBodies/Pet' + responses: + '200': + description: Successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' components: + requestBodies: + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store schemas: Category: type: object diff --git a/samples/client/echo_api/java/apache-httpclient/.openapi-generator/FILES b/samples/client/echo_api/java/apache-httpclient/.openapi-generator/FILES index c62abc624a1..c13a3b293ca 100644 --- a/samples/client/echo_api/java/apache-httpclient/.openapi-generator/FILES +++ b/samples/client/echo_api/java/apache-httpclient/.openapi-generator/FILES @@ -5,6 +5,7 @@ README.md api/openapi.yaml build.gradle build.sbt +docs/BodyApi.md docs/Category.md docs/PathApi.md docs/Pet.md @@ -29,6 +30,7 @@ src/main/java/org/openapitools/client/RFC3339DateFormat.java src/main/java/org/openapitools/client/ServerConfiguration.java src/main/java/org/openapitools/client/ServerVariable.java src/main/java/org/openapitools/client/StringUtil.java +src/main/java/org/openapitools/client/api/BodyApi.java src/main/java/org/openapitools/client/api/PathApi.java src/main/java/org/openapitools/client/api/QueryApi.java src/main/java/org/openapitools/client/auth/ApiKeyAuth.java diff --git a/samples/client/echo_api/java/apache-httpclient/README.md b/samples/client/echo_api/java/apache-httpclient/README.md index 4b27be4f2bf..3f6adfee9d3 100644 --- a/samples/client/echo_api/java/apache-httpclient/README.md +++ b/samples/client/echo_api/java/apache-httpclient/README.md @@ -75,22 +75,21 @@ Please follow the [installation](#installation) instruction and execute the foll import org.openapitools.client.*; import org.openapitools.client.auth.*; import org.openapitools.client.model.*; -import org.openapitools.client.api.PathApi; +import org.openapitools.client.api.BodyApi; -public class PathApiExample { +public class BodyApiExample { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost:3000"); - PathApi apiInstance = new PathApi(defaultClient); - String pathString = "pathString_example"; // String | - Integer pathInteger = 56; // Integer | + BodyApi apiInstance = new BodyApi(defaultClient); + Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store try { - String result = apiInstance.testsPathStringPathStringIntegerPathInteger(pathString, pathInteger); + Pet result = apiInstance.testEchoBodyPet(pet); System.out.println(result); } catch (ApiException e) { - System.err.println("Exception when calling PathApi#testsPathStringPathStringIntegerPathInteger"); + System.err.println("Exception when calling BodyApi#testEchoBodyPet"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); @@ -107,6 +106,7 @@ All URIs are relative to *http://localhost:3000* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*BodyApi* | [**testEchoBodyPet**](docs/BodyApi.md#testEchoBodyPet) | **POST** /echo/body/Pet | Test body parameter(s) *PathApi* | [**testsPathStringPathStringIntegerPathInteger**](docs/PathApi.md#testsPathStringPathStringIntegerPathInteger) | **GET** /path/string/{path_string}/integer/{path_integer} | Test path parameter(s) *QueryApi* | [**testQueryIntegerBooleanString**](docs/QueryApi.md#testQueryIntegerBooleanString) | **GET** /query/integer/boolean/string | Test query parameter(s) *QueryApi* | [**testQueryStyleFormExplodeTrueArrayString**](docs/QueryApi.md#testQueryStyleFormExplodeTrueArrayString) | **GET** /query/style_form/explode_true/array_string | Test query parameter(s) diff --git a/samples/client/echo_api/java/apache-httpclient/api/openapi.yaml b/samples/client/echo_api/java/apache-httpclient/api/openapi.yaml index b782a803dab..4dd00e16318 100644 --- a/samples/client/echo_api/java/apache-httpclient/api/openapi.yaml +++ b/samples/client/echo_api/java/apache-httpclient/api/openapi.yaml @@ -124,9 +124,37 @@ paths: tags: - query x-accepts: text/plain + /echo/body/Pet: + post: + description: Test body parameter(s) + operationId: test/echo/body/Pet + requestBody: + $ref: '#/components/requestBodies/Pet' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: Successful operation + summary: Test body parameter(s) + tags: + - body + x-content-type: application/json + x-accepts: application/json components: + requestBodies: + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store schemas: Category: + example: + name: Dogs + id: 1 properties: id: example: 1 @@ -139,6 +167,9 @@ components: xml: name: category Tag: + example: + name: name + id: 0 properties: id: format: int64 @@ -149,6 +180,21 @@ components: xml: name: tag Pet: + example: + photoUrls: + - photoUrls + - photoUrls + name: doggie + id: 10 + category: + name: Dogs + id: 1 + tags: + - name: name + id: 0 + - name: name + id: 0 + status: available properties: id: example: 10 diff --git a/samples/client/echo_api/java/apache-httpclient/docs/BodyApi.md b/samples/client/echo_api/java/apache-httpclient/docs/BodyApi.md new file mode 100644 index 00000000000..298dede6e49 --- /dev/null +++ b/samples/client/echo_api/java/apache-httpclient/docs/BodyApi.md @@ -0,0 +1,75 @@ +# BodyApi + +All URIs are relative to *http://localhost:3000* + +| Method | HTTP request | Description | +|------------- | ------------- | -------------| +| [**testEchoBodyPet**](BodyApi.md#testEchoBodyPet) | **POST** /echo/body/Pet | Test body parameter(s) | + + + +## testEchoBodyPet + +> Pet testEchoBodyPet(pet) + +Test body parameter(s) + +Test body parameter(s) + +### 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.BodyApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://localhost:3000"); + + BodyApi apiInstance = new BodyApi(defaultClient); + Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store + try { + Pet result = apiInstance.testEchoBodyPet(pet); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling BodyApi#testEchoBodyPet"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +| Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store | [optional] | + +### Return type + +[**Pet**](Pet.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | Successful operation | - | + diff --git a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/BodyApi.java b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/BodyApi.java new file mode 100644 index 00000000000..825922c1257 --- /dev/null +++ b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/BodyApi.java @@ -0,0 +1,102 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import org.openapitools.client.ApiException; +import org.openapitools.client.ApiClient; +import org.openapitools.client.Configuration; +import org.openapitools.client.model.*; +import org.openapitools.client.Pair; + +import org.openapitools.client.model.Pet; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class BodyApi { + private ApiClient apiClient; + + public BodyApi() { + this(Configuration.getDefaultApiClient()); + } + + public BodyApi(ApiClient apiClient) { + this.apiClient = apiClient; + } + + public ApiClient getApiClient() { + return apiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.apiClient = apiClient; + } + + /** + * Test body parameter(s) + * Test body parameter(s) + * @param pet Pet object that needs to be added to the store (optional) + * @return Pet + * @throws ApiException if fails to make API call + */ + public Pet testEchoBodyPet(Pet pet) throws ApiException { + Object localVarPostBody = pet; + + // create path and map variables + String localVarPath = "/echo/body/Pet"; + + // query params + 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 = apiClient.selectHeaderAccept(localVarAccepts); + + final String[] localVarContentTypes = { + "application/json" + }; + final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); + + String[] localVarAuthNames = new String[] { }; + + TypeReference localVarReturnType = new TypeReference() {}; + return apiClient.invokeAPI( + localVarPath, + "POST", + localVarQueryParams, + localVarCollectionQueryParams, + localVarPostBody, + localVarHeaderParams, + localVarCookieParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarAuthNames, + localVarReturnType + ); + } +} diff --git a/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/api/BodyApiTest.java b/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/api/BodyApiTest.java new file mode 100644 index 00000000000..352e8e2e19b --- /dev/null +++ b/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/api/BodyApiTest.java @@ -0,0 +1,52 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.api; + +import org.openapitools.client.ApiException; +import org.openapitools.client.model.Pet; +import org.junit.Test; +import org.junit.Ignore; +import org.junit.Assert; + +import java.time.LocalDate; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * API tests for BodyApi + */ +@Ignore +public class BodyApiTest { + + private final BodyApi api = new BodyApi(); + + /** + * Test body parameter(s) + * + * Test body parameter(s) + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void testEchoBodyPetTest() throws ApiException { + Pet pet = null; + Pet response = api.testEchoBodyPet(pet); + + // TODO: test validations + } +} diff --git a/samples/client/echo_api/java/native/.openapi-generator/FILES b/samples/client/echo_api/java/native/.openapi-generator/FILES index de036ed7e73..23dec04e62b 100644 --- a/samples/client/echo_api/java/native/.openapi-generator/FILES +++ b/samples/client/echo_api/java/native/.openapi-generator/FILES @@ -5,6 +5,7 @@ README.md api/openapi.yaml build.gradle build.sbt +docs/BodyApi.md docs/Category.md docs/PathApi.md docs/Pet.md @@ -29,6 +30,7 @@ src/main/java/org/openapitools/client/Pair.java src/main/java/org/openapitools/client/RFC3339DateFormat.java src/main/java/org/openapitools/client/ServerConfiguration.java src/main/java/org/openapitools/client/ServerVariable.java +src/main/java/org/openapitools/client/api/BodyApi.java src/main/java/org/openapitools/client/api/PathApi.java src/main/java/org/openapitools/client/api/QueryApi.java src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java diff --git a/samples/client/echo_api/java/native/README.md b/samples/client/echo_api/java/native/README.md index b31d16de140..9a315449382 100644 --- a/samples/client/echo_api/java/native/README.md +++ b/samples/client/echo_api/java/native/README.md @@ -74,22 +74,21 @@ Please follow the [installation](#installation) instruction and execute the foll import org.openapitools.client.*; import org.openapitools.client.model.*; -import org.openapitools.client.api.PathApi; +import org.openapitools.client.api.BodyApi; -public class PathApiExample { +public class BodyApiExample { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); // Configure clients using the `defaultClient` object, such as // overriding the host and port, timeout, etc. - PathApi apiInstance = new PathApi(defaultClient); - String pathString = "pathString_example"; // String | - Integer pathInteger = 56; // Integer | + BodyApi apiInstance = new BodyApi(defaultClient); + Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store try { - String result = apiInstance.testsPathStringPathStringIntegerPathInteger(pathString, pathInteger); + Pet result = apiInstance.testEchoBodyPet(pet); System.out.println(result); } catch (ApiException e) { - System.err.println("Exception when calling PathApi#testsPathStringPathStringIntegerPathInteger"); + System.err.println("Exception when calling BodyApi#testEchoBodyPet"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); @@ -106,6 +105,8 @@ All URIs are relative to *http://localhost:3000* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*BodyApi* | [**testEchoBodyPet**](docs/BodyApi.md#testEchoBodyPet) | **POST** /echo/body/Pet | Test body parameter(s) +*BodyApi* | [**testEchoBodyPetWithHttpInfo**](docs/BodyApi.md#testEchoBodyPetWithHttpInfo) | **POST** /echo/body/Pet | Test body parameter(s) *PathApi* | [**testsPathStringPathStringIntegerPathInteger**](docs/PathApi.md#testsPathStringPathStringIntegerPathInteger) | **GET** /path/string/{path_string}/integer/{path_integer} | Test path parameter(s) *PathApi* | [**testsPathStringPathStringIntegerPathIntegerWithHttpInfo**](docs/PathApi.md#testsPathStringPathStringIntegerPathIntegerWithHttpInfo) | **GET** /path/string/{path_string}/integer/{path_integer} | Test path parameter(s) *QueryApi* | [**testQueryIntegerBooleanString**](docs/QueryApi.md#testQueryIntegerBooleanString) | **GET** /query/integer/boolean/string | Test query parameter(s) diff --git a/samples/client/echo_api/java/native/api/openapi.yaml b/samples/client/echo_api/java/native/api/openapi.yaml index b782a803dab..4dd00e16318 100644 --- a/samples/client/echo_api/java/native/api/openapi.yaml +++ b/samples/client/echo_api/java/native/api/openapi.yaml @@ -124,9 +124,37 @@ paths: tags: - query x-accepts: text/plain + /echo/body/Pet: + post: + description: Test body parameter(s) + operationId: test/echo/body/Pet + requestBody: + $ref: '#/components/requestBodies/Pet' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: Successful operation + summary: Test body parameter(s) + tags: + - body + x-content-type: application/json + x-accepts: application/json components: + requestBodies: + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store schemas: Category: + example: + name: Dogs + id: 1 properties: id: example: 1 @@ -139,6 +167,9 @@ components: xml: name: category Tag: + example: + name: name + id: 0 properties: id: format: int64 @@ -149,6 +180,21 @@ components: xml: name: tag Pet: + example: + photoUrls: + - photoUrls + - photoUrls + name: doggie + id: 10 + category: + name: Dogs + id: 1 + tags: + - name: name + id: 0 + - name: name + id: 0 + status: available properties: id: example: 10 diff --git a/samples/client/echo_api/java/native/docs/BodyApi.md b/samples/client/echo_api/java/native/docs/BodyApi.md new file mode 100644 index 00000000000..f96e1e3d23d --- /dev/null +++ b/samples/client/echo_api/java/native/docs/BodyApi.md @@ -0,0 +1,144 @@ +# BodyApi + +All URIs are relative to *http://localhost:3000* + +| Method | HTTP request | Description | +|------------- | ------------- | -------------| +| [**testEchoBodyPet**](BodyApi.md#testEchoBodyPet) | **POST** /echo/body/Pet | Test body parameter(s) | +| [**testEchoBodyPetWithHttpInfo**](BodyApi.md#testEchoBodyPetWithHttpInfo) | **POST** /echo/body/Pet | Test body parameter(s) | + + + +## testEchoBodyPet + +> Pet testEchoBodyPet(pet) + +Test body parameter(s) + +Test body parameter(s) + +### 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.BodyApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://localhost:3000"); + + BodyApi apiInstance = new BodyApi(defaultClient); + Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store + try { + Pet result = apiInstance.testEchoBodyPet(pet); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling BodyApi#testEchoBodyPet"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +| Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store | [optional] | + +### Return type + +[**Pet**](Pet.md) + + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | Successful operation | - | + +## testEchoBodyPetWithHttpInfo + +> ApiResponse testEchoBodyPet testEchoBodyPetWithHttpInfo(pet) + +Test body parameter(s) + +Test body parameter(s) + +### Example + +```java +// Import classes: +import org.openapitools.client.ApiClient; +import org.openapitools.client.ApiException; +import org.openapitools.client.ApiResponse; +import org.openapitools.client.Configuration; +import org.openapitools.client.models.*; +import org.openapitools.client.api.BodyApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://localhost:3000"); + + BodyApi apiInstance = new BodyApi(defaultClient); + Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store + try { + ApiResponse response = apiInstance.testEchoBodyPetWithHttpInfo(pet); + System.out.println("Status code: " + response.getStatusCode()); + System.out.println("Response headers: " + response.getHeaders()); + System.out.println("Response body: " + response.getData()); + } catch (ApiException e) { + System.err.println("Exception when calling BodyApi#testEchoBodyPet"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Response headers: " + e.getResponseHeaders()); + System.err.println("Reason: " + e.getResponseBody()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +| Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store | [optional] | + +### Return type + +ApiResponse<[**Pet**](Pet.md)> + + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | Successful operation | - | + diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/BodyApi.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/BodyApi.java new file mode 100644 index 00000000000..45c5b8e6e28 --- /dev/null +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/BodyApi.java @@ -0,0 +1,150 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.api; + +import org.openapitools.client.ApiClient; +import org.openapitools.client.ApiException; +import org.openapitools.client.ApiResponse; +import org.openapitools.client.Pair; + +import org.openapitools.client.model.Pet; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Duration; + +import java.util.ArrayList; +import java.util.StringJoiner; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Consumer; + +@javax.annotation.processing.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class BodyApi { + private final HttpClient memberVarHttpClient; + private final ObjectMapper memberVarObjectMapper; + private final String memberVarBaseUri; + private final Consumer memberVarInterceptor; + private final Duration memberVarReadTimeout; + private final Consumer> memberVarResponseInterceptor; + private final Consumer> memberVarAsyncResponseInterceptor; + + public BodyApi() { + this(new ApiClient()); + } + + public BodyApi(ApiClient apiClient) { + memberVarHttpClient = apiClient.getHttpClient(); + memberVarObjectMapper = apiClient.getObjectMapper(); + memberVarBaseUri = apiClient.getBaseUri(); + memberVarInterceptor = apiClient.getRequestInterceptor(); + memberVarReadTimeout = apiClient.getReadTimeout(); + memberVarResponseInterceptor = apiClient.getResponseInterceptor(); + memberVarAsyncResponseInterceptor = apiClient.getAsyncResponseInterceptor(); + } + + protected ApiException getApiException(String operationId, HttpResponse response) throws IOException { + String body = response.body() == null ? null : new String(response.body().readAllBytes()); + String message = formatExceptionMessage(operationId, response.statusCode(), body); + return new ApiException(response.statusCode(), message, response.headers(), body); + } + + private String formatExceptionMessage(String operationId, int statusCode, String body) { + if (body == null || body.isEmpty()) { + body = "[no body]"; + } + return operationId + " call failed with: " + statusCode + " - " + body; + } + + /** + * Test body parameter(s) + * Test body parameter(s) + * @param pet Pet object that needs to be added to the store (optional) + * @return Pet + * @throws ApiException if fails to make API call + */ + public Pet testEchoBodyPet(Pet pet) throws ApiException { + ApiResponse localVarResponse = testEchoBodyPetWithHttpInfo(pet); + return localVarResponse.getData(); + } + + /** + * Test body parameter(s) + * Test body parameter(s) + * @param pet Pet object that needs to be added to the store (optional) + * @return ApiResponse<Pet> + * @throws ApiException if fails to make API call + */ + public ApiResponse testEchoBodyPetWithHttpInfo(Pet pet) throws ApiException { + HttpRequest.Builder localVarRequestBuilder = testEchoBodyPetRequestBuilder(pet); + try { + HttpResponse localVarResponse = memberVarHttpClient.send( + localVarRequestBuilder.build(), + HttpResponse.BodyHandlers.ofInputStream()); + if (memberVarResponseInterceptor != null) { + memberVarResponseInterceptor.accept(localVarResponse); + } + try { + if (localVarResponse.statusCode()/ 100 != 2) { + throw getApiException("testEchoBodyPet", localVarResponse); + } + return new ApiResponse( + localVarResponse.statusCode(), + localVarResponse.headers().map(), + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream + ); + } finally { + } + } catch (IOException e) { + throw new ApiException(e); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new ApiException(e); + } + } + + private HttpRequest.Builder testEchoBodyPetRequestBuilder(Pet pet) throws ApiException { + + HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder(); + + String localVarPath = "/echo/body/Pet"; + + localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath)); + + localVarRequestBuilder.header("Content-Type", "application/json"); + localVarRequestBuilder.header("Accept", "application/json"); + + try { + byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(pet); + localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); + } catch (IOException e) { + throw new ApiException(e); + } + if (memberVarReadTimeout != null) { + localVarRequestBuilder.timeout(memberVarReadTimeout); + } + if (memberVarInterceptor != null) { + memberVarInterceptor.accept(localVarRequestBuilder); + } + return localVarRequestBuilder; + } +} diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/PathApi.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/PathApi.java index dacf46dd260..911b0389b0f 100644 --- a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/PathApi.java +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/PathApi.java @@ -108,10 +108,9 @@ public class PathApi { throw getApiException("testsPathStringPathStringIntegerPathInteger", localVarResponse); } // for plain text response - InputStream responseBody = localVarResponse.body(); if (localVarResponse.headers().map().containsKey("Content-Type") && "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { - java.util.Scanner s = new java.util.Scanner(responseBody).useDelimiter("\\A"); + java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( localVarResponse.statusCode(), diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/QueryApi.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/QueryApi.java index 406ee3b8fad..07add30bb3b 100644 --- a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/QueryApi.java +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/QueryApi.java @@ -112,10 +112,9 @@ public class QueryApi { throw getApiException("testQueryIntegerBooleanString", localVarResponse); } // for plain text response - InputStream responseBody = localVarResponse.body(); if (localVarResponse.headers().map().containsKey("Content-Type") && "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { - java.util.Scanner s = new java.util.Scanner(responseBody).useDelimiter("\\A"); + java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( localVarResponse.statusCode(), @@ -199,10 +198,9 @@ public class QueryApi { throw getApiException("testQueryStyleFormExplodeTrueArrayString", localVarResponse); } // for plain text response - InputStream responseBody = localVarResponse.body(); if (localVarResponse.headers().map().containsKey("Content-Type") && "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { - java.util.Scanner s = new java.util.Scanner(responseBody).useDelimiter("\\A"); + java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( localVarResponse.statusCode(), @@ -284,10 +282,9 @@ public class QueryApi { throw getApiException("testQueryStyleFormExplodeTrueObject", localVarResponse); } // for plain text response - InputStream responseBody = localVarResponse.body(); if (localVarResponse.headers().map().containsKey("Content-Type") && "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { - java.util.Scanner s = new java.util.Scanner(responseBody).useDelimiter("\\A"); + java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( localVarResponse.statusCode(), diff --git a/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/CustomTest.java b/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/CustomTest.java index affbfae04a4..fb3e2cd4861 100644 --- a/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/CustomTest.java +++ b/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/CustomTest.java @@ -15,10 +15,8 @@ package org.openapitools.client; import org.junit.Assert; import org.openapitools.client.ApiException; -import org.openapitools.client.api.QueryApi; -import org.openapitools.client.model.Category; -import org.openapitools.client.model.Pet; -import org.openapitools.client.model.TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter; +import org.openapitools.client.api.*; +import org.openapitools.client.model.*; import org.junit.Test; import org.junit.Ignore; @@ -31,8 +29,31 @@ import java.util.*; public class CustomTest { private final QueryApi api = new QueryApi(); + private final BodyApi bodyApi = new BodyApi(); + /** + * Test body parameter(s) + *

+ * Test body parameter(s) + * + * @throws ApiException if the Api call fails + */ + @Test + public void testEchoBodyPet() throws ApiException { + Pet queryObject = new Pet().id(12345L).name("Hello World"). + photoUrls(Arrays.asList(new String[]{"http://a.com", "http://b.com"})).category(new Category().id(987L).name("new category")); + + Pet p = bodyApi.testEchoBodyPet(queryObject); + Assert.assertNotNull(p); + Assert.assertEquals("Hello World", p.getName()); + Assert.assertEquals(Long.valueOf(12345L), p.getId()); + + // response is empty body + Pet p2 = bodyApi.testEchoBodyPet(null); + Assert.assertNull(p2); + } + /** * Test query parameter(s) *

diff --git a/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/api/BodyApiTest.java b/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/api/BodyApiTest.java new file mode 100644 index 00000000000..fc14326e06a --- /dev/null +++ b/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/api/BodyApiTest.java @@ -0,0 +1,54 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.org + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.api; + +import org.openapitools.client.ApiException; +import org.openapitools.client.model.Pet; +import org.junit.Test; +import org.junit.Ignore; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +/** + * API tests for BodyApi + */ +@Ignore +public class BodyApiTest { + + private final BodyApi api = new BodyApi(); + + + /** + * Test body parameter(s) + * + * Test body parameter(s) + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void testEchoBodyPetTest() throws ApiException { + Pet pet = null; + Pet response = + api.testEchoBodyPet(pet); + + // TODO: test validations + } + +} diff --git a/samples/client/others/typescript-axios/with-separate-models-and-api-inheritance/common.ts b/samples/client/others/typescript-axios/with-separate-models-and-api-inheritance/common.ts index 6c84026abcc..cb72c04287d 100644 --- a/samples/client/others/typescript-axios/with-separate-models-and-api-inheritance/common.ts +++ b/samples/client/others/typescript-axios/with-separate-models-and-api-inheritance/common.ts @@ -85,6 +85,7 @@ export const setOAuthToObject = async function (object: any, name: string, scope } function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void { + if (parameter == null) return; if (typeof parameter === "object") { if (Array.isArray(parameter)) { (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key)); diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/AnotherFakeApi.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/AnotherFakeApi.java index 3bff17c92d8..c09ed55d8a9 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/AnotherFakeApi.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/AnotherFakeApi.java @@ -106,11 +106,10 @@ public class AnotherFakeApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("call123testSpecialTags", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/DefaultApi.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/DefaultApi.java index 8b164954bc3..6744fdc7ffd 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/DefaultApi.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/DefaultApi.java @@ -104,11 +104,10 @@ public class DefaultApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("fooGet", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/FakeApi.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/FakeApi.java index 384d478bb3a..7f35d8b2e1e 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/FakeApi.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/FakeApi.java @@ -115,11 +115,10 @@ public class FakeApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("fakeHealthGet", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } @@ -279,11 +278,10 @@ public class FakeApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("fakeOuterBooleanSerialize", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } @@ -353,11 +351,10 @@ public class FakeApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("fakeOuterCompositeSerialize", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } @@ -427,11 +424,10 @@ public class FakeApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("fakeOuterNumberSerialize", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } @@ -501,11 +497,10 @@ public class FakeApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("fakeOuterStringSerialize", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } @@ -570,11 +565,10 @@ public class FakeApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("fakePropertyEnumIntegerSerialize", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } @@ -903,11 +897,10 @@ public class FakeApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("testClientModel", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/FakeClassnameTags123Api.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/FakeClassnameTags123Api.java index e6c8eab5338..f035fc38721 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/FakeClassnameTags123Api.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/FakeClassnameTags123Api.java @@ -106,11 +106,10 @@ public class FakeClassnameTags123Api { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("testClassname", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/PetApi.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/PetApi.java index c31d9a1a2c8..f9d23e700dc 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/PetApi.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/PetApi.java @@ -269,11 +269,10 @@ public class PetApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("findPetsByStatus", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse>( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference>() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference>() {}) // closes the InputStream ); } finally { } @@ -354,11 +353,10 @@ public class PetApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("findPetsByTags", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse>( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference>() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference>() {}) // closes the InputStream ); } finally { } @@ -435,11 +433,10 @@ public class PetApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("getPetById", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } @@ -671,11 +668,10 @@ public class PetApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("uploadFile", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } @@ -748,11 +744,10 @@ public class PetApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("uploadFileWithRequiredFile", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/StoreApi.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/StoreApi.java index c54ddcb284d..5e7412d3956 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/StoreApi.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/StoreApi.java @@ -179,11 +179,10 @@ public class StoreApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("getInventory", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse>( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference>() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference>() {}) // closes the InputStream ); } finally { } @@ -247,11 +246,10 @@ public class StoreApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("getOrderById", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } @@ -320,11 +318,10 @@ public class StoreApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("placeOrder", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/UserApi.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/UserApi.java index 00e46631746..f95345a81a9 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/UserApi.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/UserApi.java @@ -422,11 +422,10 @@ public class UserApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("getUserByName", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { } @@ -497,11 +496,10 @@ public class UserApi { if (localVarResponse.statusCode()/ 100 != 2) { throw getApiException("loginUser", localVarResponse); } - InputStream responseBody = localVarResponse.body(); return new ApiResponse( localVarResponse.statusCode(), localVarResponse.headers().map(), - responseBody == null || responseBody.available() < 1 ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference() {}) // closes the InputStream + localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream ); } finally { }