From 7aaa629ba25580035844867fdc480f96c477ec3d Mon Sep 17 00:00:00 2001 From: Charles Capps Date: Tue, 6 Mar 2018 11:30:14 -0800 Subject: [PATCH 1/4] Add overloaded method to take an InputStream for the request body, and fix a bug with collections --- .../libraries/google-api-client/api.mustache | 48 ++++++- .../io/swagger/client/api/AnotherFakeApi.java | 19 +++ .../java/io/swagger/client/api/FakeApi.java | 123 +++++++++++++++++- .../client/api/FakeClassnameTags123Api.java | 19 +++ .../java/io/swagger/client/api/PetApi.java | 67 +++++++++- .../java/io/swagger/client/api/StoreApi.java | 25 ++++ .../java/io/swagger/client/api/UserApi.java | 101 +++++++++++++- 7 files changed, 393 insertions(+), 9 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache index 87119b9c771..ba2c8c9b070 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache @@ -8,10 +8,13 @@ import {{invokerPackage}}.ApiClient; import com.fasterxml.jackson.core.type.TypeReference; import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpContent; +import com.google.api.client.http.InputStreamContent; import com.google.api.client.http.HttpMethods; import com.google.api.client.http.HttpResponse; +import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; +import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -91,7 +94,15 @@ public class {{classname}} { UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "{{{path}}}");{{#hasQueryParams}} {{#queryParams}} if ({{paramName}} != null) { - uriBuilder = uriBuilder.queryParam("{{baseName}}", {{paramName}}); + String key = "{{baseName}}"; + Object value = {{paramName}}; + if (value instanceof Collection) { + uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); + } else { + uriBuilder = uriBuilder.queryParam(key, value); + } }{{/queryParams}}{{/hasQueryParams}} String url = uriBuilder{{#hasPathParams}}.buildFromMap(uriVariables).toString();{{/hasPathParams}}{{^hasPathParams}}.build().toString();{{/hasPathParams}} @@ -99,7 +110,38 @@ public class {{classname}} { HttpContent content = {{#bodyParam}}{{paramName}} == null ? null : apiClient.new JacksonJsonHttpContent({{paramName}}){{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.{{httpMethod}}, genericUrl, content).execute(); - } + }{{#bodyParam}} + + public HttpResponse {{operationId}}ForHttpResponse({{#allParams}}{{#isBodyParam}}InputStream {{paramName}}{{/isBodyParam}}{{^isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws IOException { + {{#allParams}}{{#required}}// verify the required parameter '{{paramName}}' is set + if ({{paramName}} == null) { + throw new IllegalArgumentException("Missing the required parameter '{{paramName}}' when calling {{operationId}}"); + }{{/required}}{{/allParams}} + {{#hasPathParams}} + // create a map of path variables + final Map uriVariables = new HashMap();{{#pathParams}} + uriVariables.put("{{baseName}}", {{{paramName}}});{{/pathParams}} + {{/hasPathParams}} + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "{{{path}}}");{{#hasQueryParams}} + {{#queryParams}} + if ({{paramName}} != null) { + String key = "{{baseName}}"; + Object value = {{paramName}}; + if (value instanceof Collection) { + uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); + } else { + uriBuilder = uriBuilder.queryParam(key, value); + } + }{{/queryParams}}{{/hasQueryParams}} + + String url = uriBuilder{{#hasPathParams}}.buildFromMap(uriVariables).toString();{{/hasPathParams}}{{^hasPathParams}}.build().toString();{{/hasPathParams}} + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = {{#bodyParam}}{{paramName}} == null ? null : new InputStreamContent(Json.MEDIA_TYPE, {{paramName}}){{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.{{httpMethod}}, genericUrl, content).execute(); + }{{/bodyParam}} public HttpResponse {{operationId}}ForHttpResponse({{#bodyParam}}{{^required}}{{{dataType}}} {{paramName}}, {{/required}}{{/bodyParam}}{{#requiredParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}{{#hasRequiredParams}}, {{/hasRequiredParams}}Map params) throws IOException { {{#allParams}}{{#required}}// verify the required parameter '{{paramName}}' is set @@ -125,6 +167,8 @@ public class {{classname}} { if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java index 25bfbda3881..06d375418fc 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java @@ -7,10 +7,13 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpContent; +import com.google.api.client.http.InputStreamContent; import com.google.api.client.http.HttpMethods; import com.google.api.client.http.HttpResponse; +import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; +import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -81,6 +84,20 @@ public HttpResponse testSpecialTagsForHttpResponse(Client body) throws IOExcepti return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); } + public HttpResponse testSpecialTagsForHttpResponse(InputStream body) throws IOException { + // verify the required parameter 'body' is set + if (body == null) { + throw new IllegalArgumentException("Missing the required parameter 'body' when calling testSpecialTags"); + } + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/another-fake/dummy"); + + String url = uriBuilder.build().toString(); + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); + } + public HttpResponse testSpecialTagsForHttpResponse(Client body, Map params) throws IOException { // verify the required parameter 'body' is set if (body == null) { @@ -98,6 +115,8 @@ public HttpResponse testSpecialTagsForHttpResponse(Client body, Map params) throws IOException { UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/boolean"); @@ -93,6 +107,8 @@ public HttpResponse fakeOuterBooleanSerializeForHttpResponse(Boolean body, Map params) throws IOException { UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/composite"); @@ -158,6 +185,8 @@ public HttpResponse fakeOuterCompositeSerializeForHttpResponse(OuterComposite bo if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -209,6 +238,17 @@ public HttpResponse fakeOuterNumberSerializeForHttpResponse(BigDecimal body) thr return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } + public HttpResponse fakeOuterNumberSerializeForHttpResponse(InputStream body) throws IOException { + + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/number"); + + String url = uriBuilder.build().toString(); + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); + } + public HttpResponse fakeOuterNumberSerializeForHttpResponse(BigDecimal body, Map params) throws IOException { UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/number"); @@ -223,6 +263,8 @@ public HttpResponse fakeOuterNumberSerializeForHttpResponse(BigDecimal body, Map if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -274,6 +316,17 @@ public HttpResponse fakeOuterStringSerializeForHttpResponse(String body) throws return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } + public HttpResponse fakeOuterStringSerializeForHttpResponse(InputStream body) throws IOException { + + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/string"); + + String url = uriBuilder.build().toString(); + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); + } + public HttpResponse fakeOuterStringSerializeForHttpResponse(String body, Map params) throws IOException { UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/string"); @@ -288,6 +341,8 @@ public HttpResponse fakeOuterStringSerializeForHttpResponse(String body, Map params) throws IOException { // verify the required parameter 'body' is set if (body == null) { @@ -362,6 +431,8 @@ public HttpResponse testClientModelForHttpResponse(Client body, Map enumFormStrin UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake"); if (enumQueryStringArray != null) { - uriBuilder = uriBuilder.queryParam("enum_query_string_array", enumQueryStringArray); + String key = "enum_query_string_array"; + Object value = enumQueryStringArray; + if (value instanceof Collection) { + uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); + } else { + uriBuilder = uriBuilder.queryParam(key, value); + } } if (enumQueryString != null) { - uriBuilder = uriBuilder.queryParam("enum_query_string", enumQueryString); + String key = "enum_query_string"; + Object value = enumQueryString; + if (value instanceof Collection) { + uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); + } else { + uriBuilder = uriBuilder.queryParam(key, value); + } } if (enumQueryInteger != null) { - uriBuilder = uriBuilder.queryParam("enum_query_integer", enumQueryInteger); + String key = "enum_query_integer"; + Object value = enumQueryInteger; + if (value instanceof Collection) { + uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); + } else { + uriBuilder = uriBuilder.queryParam(key, value); + } } String url = uriBuilder.build().toString(); @@ -543,6 +640,8 @@ public HttpResponse testEnumParametersForHttpResponse(Map params if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -594,6 +693,20 @@ public HttpResponse testInlineAdditionalPropertiesForHttpResponse(Object param) return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } + public HttpResponse testInlineAdditionalPropertiesForHttpResponse(InputStream param) throws IOException { + // verify the required parameter 'param' is set + if (param == null) { + throw new IllegalArgumentException("Missing the required parameter 'param' when calling testInlineAdditionalProperties"); + } + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/inline-additionalProperties"); + + String url = uriBuilder.build().toString(); + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = param == null ? null : new InputStreamContent(Json.MEDIA_TYPE, param); + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); + } + public HttpResponse testInlineAdditionalPropertiesForHttpResponse(Object param, Map params) throws IOException { // verify the required parameter 'param' is set if (param == null) { @@ -611,6 +724,8 @@ public HttpResponse testInlineAdditionalPropertiesForHttpResponse(Object param, if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -687,6 +802,8 @@ public HttpResponse testJsonFormDataForHttpResponse(String param, String param2, if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java index ce9e8752e57..6d28e9e72a2 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java @@ -7,10 +7,13 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpContent; +import com.google.api.client.http.InputStreamContent; import com.google.api.client.http.HttpMethods; import com.google.api.client.http.HttpResponse; +import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; +import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -81,6 +84,20 @@ public HttpResponse testClassnameForHttpResponse(Client body) throws IOException return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); } + public HttpResponse testClassnameForHttpResponse(InputStream body) throws IOException { + // verify the required parameter 'body' is set + if (body == null) { + throw new IllegalArgumentException("Missing the required parameter 'body' when calling testClassname"); + } + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake_classname_test"); + + String url = uriBuilder.build().toString(); + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); + } + public HttpResponse testClassnameForHttpResponse(Client body, Map params) throws IOException { // verify the required parameter 'body' is set if (body == null) { @@ -98,6 +115,8 @@ public HttpResponse testClassnameForHttpResponse(Client body, Map params) throws IOException { // verify the required parameter 'body' is set if (body == null) { @@ -94,6 +111,8 @@ public HttpResponse addPetForHttpResponse(Pet body, Map params) if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -169,6 +188,8 @@ public HttpResponse deletePetForHttpResponse(Long petId, Map par if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -221,7 +242,15 @@ public HttpResponse findPetsByStatusForHttpResponse(List status) throws } UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/pet/findByStatus"); if (status != null) { - uriBuilder = uriBuilder.queryParam("status", status); + String key = "status"; + Object value = status; + if (value instanceof Collection) { + uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); + } else { + uriBuilder = uriBuilder.queryParam(key, value); + } } String url = uriBuilder.build().toString(); @@ -250,6 +279,8 @@ public HttpResponse findPetsByStatusForHttpResponse(List status, Map tags) throws IOEx } UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/pet/findByTags"); if (tags != null) { - uriBuilder = uriBuilder.queryParam("tags", tags); + String key = "tags"; + Object value = tags; + if (value instanceof Collection) { + uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); + } else { + uriBuilder = uriBuilder.queryParam(key, value); + } } String url = uriBuilder.build().toString(); @@ -331,6 +370,8 @@ public HttpResponse findPetsByTagsForHttpResponse(List tags, Map pa if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -470,6 +513,20 @@ public HttpResponse updatePetForHttpResponse(Pet body) throws IOException { return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); } + public HttpResponse updatePetForHttpResponse(InputStream body) throws IOException { + // verify the required parameter 'body' is set + if (body == null) { + throw new IllegalArgumentException("Missing the required parameter 'body' when calling updatePet"); + } + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/pet"); + + String url = uriBuilder.build().toString(); + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); + } + public HttpResponse updatePetForHttpResponse(Pet body, Map params) throws IOException { // verify the required parameter 'body' is set if (body == null) { @@ -487,6 +544,8 @@ public HttpResponse updatePetForHttpResponse(Pet body, Map param if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -563,6 +622,8 @@ public HttpResponse updatePetWithFormForHttpResponse(Long petId, Map pa if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java index a60a5837d90..26a440112a8 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java @@ -7,10 +7,13 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpContent; +import com.google.api.client.http.InputStreamContent; import com.google.api.client.http.HttpMethods; import com.google.api.client.http.HttpResponse; +import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; +import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -100,6 +103,8 @@ public HttpResponse deleteOrderForHttpResponse(String orderId, Map params) thro if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -250,6 +257,8 @@ public HttpResponse getOrderByIdForHttpResponse(Long orderId, Map params) throws IOException { // verify the required parameter 'body' is set if (body == null) { @@ -326,6 +349,8 @@ public HttpResponse placeOrderForHttpResponse(Order body, Map pa if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java index fcea0fd7ede..8275fae9771 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java @@ -7,10 +7,13 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpContent; +import com.google.api.client.http.InputStreamContent; import com.google.api.client.http.HttpMethods; import com.google.api.client.http.HttpResponse; +import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; +import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -75,6 +78,20 @@ public HttpResponse createUserForHttpResponse(User body) throws IOException { return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } + public HttpResponse createUserForHttpResponse(InputStream body) throws IOException { + // verify the required parameter 'body' is set + if (body == null) { + throw new IllegalArgumentException("Missing the required parameter 'body' when calling createUser"); + } + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/user"); + + String url = uriBuilder.build().toString(); + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); + } + public HttpResponse createUserForHttpResponse(User body, Map params) throws IOException { // verify the required parameter 'body' is set if (body == null) { @@ -92,6 +109,8 @@ public HttpResponse createUserForHttpResponse(User body, Map par if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -143,6 +162,20 @@ public HttpResponse createUsersWithArrayInputForHttpResponse(List body) th return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } + public HttpResponse createUsersWithArrayInputForHttpResponse(InputStream body) throws IOException { + // verify the required parameter 'body' is set + if (body == null) { + throw new IllegalArgumentException("Missing the required parameter 'body' when calling createUsersWithArrayInput"); + } + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/user/createWithArray"); + + String url = uriBuilder.build().toString(); + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); + } + public HttpResponse createUsersWithArrayInputForHttpResponse(List body, Map params) throws IOException { // verify the required parameter 'body' is set if (body == null) { @@ -160,6 +193,8 @@ public HttpResponse createUsersWithArrayInputForHttpResponse(List body, Ma if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -211,6 +246,20 @@ public HttpResponse createUsersWithListInputForHttpResponse(List body) thr return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } + public HttpResponse createUsersWithListInputForHttpResponse(InputStream body) throws IOException { + // verify the required parameter 'body' is set + if (body == null) { + throw new IllegalArgumentException("Missing the required parameter 'body' when calling createUsersWithListInput"); + } + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/user/createWithList"); + + String url = uriBuilder.build().toString(); + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); + } + public HttpResponse createUsersWithListInputForHttpResponse(List body, Map params) throws IOException { // verify the required parameter 'body' is set if (body == null) { @@ -228,6 +277,8 @@ public HttpResponse createUsersWithListInputForHttpResponse(List body, Map if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -304,6 +355,8 @@ public HttpResponse deleteUserForHttpResponse(String username, Map params) throws if (key != null && value != null) { if (value instanceof Collection) { uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray()); + } else if (value instanceof Object[]) { + uriBuilder = uriBuilder.queryParam(key, (Object[]) value); } else { uriBuilder = uriBuilder.queryParam(key, value); } @@ -602,6 +677,26 @@ public HttpResponse updateUserForHttpResponse(String username, User body) throws return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); } + public HttpResponse updateUserForHttpResponse(String username, InputStream body) throws IOException { + // verify the required parameter 'username' is set + if (username == null) { + throw new IllegalArgumentException("Missing the required parameter 'username' when calling updateUser"); + }// verify the required parameter 'body' is set + if (body == null) { + throw new IllegalArgumentException("Missing the required parameter 'body' when calling updateUser"); + } + // create a map of path variables + final Map uriVariables = new HashMap(); + uriVariables.put("username", username); + UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/user/{username}"); + + String url = uriBuilder.buildFromMap(uriVariables).toString(); + GenericUrl genericUrl = new GenericUrl(url); + + HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); + } + public HttpResponse updateUserForHttpResponse(String username, User body, Map params) throws IOException { // verify the required parameter 'username' is set if (username == null) { @@ -625,6 +720,8 @@ public HttpResponse updateUserForHttpResponse(String username, User body, Map Date: Tue, 6 Mar 2018 13:28:25 -0800 Subject: [PATCH 2/4] Use fully qualified name for InputStream to avoid potential conflicts --- .../Java/libraries/google-api-client/api.mustache | 3 +-- .../java/io/swagger/client/api/AnotherFakeApi.java | 3 +-- .../main/java/io/swagger/client/api/FakeApi.java | 13 ++++++------- .../swagger/client/api/FakeClassnameTags123Api.java | 3 +-- .../src/main/java/io/swagger/client/api/PetApi.java | 5 ++--- .../main/java/io/swagger/client/api/StoreApi.java | 3 +-- .../main/java/io/swagger/client/api/UserApi.java | 9 ++++----- 7 files changed, 16 insertions(+), 23 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache index ba2c8c9b070..201c6443da3 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache @@ -14,7 +14,6 @@ import com.google.api.client.http.HttpResponse; import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; -import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -112,7 +111,7 @@ public class {{classname}} { return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.{{httpMethod}}, genericUrl, content).execute(); }{{#bodyParam}} - public HttpResponse {{operationId}}ForHttpResponse({{#allParams}}{{#isBodyParam}}InputStream {{paramName}}{{/isBodyParam}}{{^isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws IOException { + public HttpResponse {{operationId}}ForHttpResponse({{#allParams}}{{#isBodyParam}}java.io.InputStream {{paramName}}{{/isBodyParam}}{{^isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws IOException { {{#allParams}}{{#required}}// verify the required parameter '{{paramName}}' is set if ({{paramName}} == null) { throw new IllegalArgumentException("Missing the required parameter '{{paramName}}' when calling {{operationId}}"); diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java index 06d375418fc..35e14044b2b 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java @@ -13,7 +13,6 @@ import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; -import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -84,7 +83,7 @@ public HttpResponse testSpecialTagsForHttpResponse(Client body) throws IOExcepti return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); } - public HttpResponse testSpecialTagsForHttpResponse(InputStream body) throws IOException { + public HttpResponse testSpecialTagsForHttpResponse(java.io.InputStream body) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling testSpecialTags"); diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeApi.java index 8652bfa6608..743d0ba6975 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeApi.java @@ -17,7 +17,6 @@ import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; -import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -82,7 +81,7 @@ public HttpResponse fakeOuterBooleanSerializeForHttpResponse(Boolean body) throw return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse fakeOuterBooleanSerializeForHttpResponse(InputStream body) throws IOException { + public HttpResponse fakeOuterBooleanSerializeForHttpResponse(java.io.InputStream body) throws IOException { UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/boolean"); @@ -160,7 +159,7 @@ public HttpResponse fakeOuterCompositeSerializeForHttpResponse(OuterComposite bo return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse fakeOuterCompositeSerializeForHttpResponse(InputStream body) throws IOException { + public HttpResponse fakeOuterCompositeSerializeForHttpResponse(java.io.InputStream body) throws IOException { UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/composite"); @@ -238,7 +237,7 @@ public HttpResponse fakeOuterNumberSerializeForHttpResponse(BigDecimal body) thr return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse fakeOuterNumberSerializeForHttpResponse(InputStream body) throws IOException { + public HttpResponse fakeOuterNumberSerializeForHttpResponse(java.io.InputStream body) throws IOException { UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/number"); @@ -316,7 +315,7 @@ public HttpResponse fakeOuterStringSerializeForHttpResponse(String body) throws return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse fakeOuterStringSerializeForHttpResponse(InputStream body) throws IOException { + public HttpResponse fakeOuterStringSerializeForHttpResponse(java.io.InputStream body) throws IOException { UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/string"); @@ -400,7 +399,7 @@ public HttpResponse testClientModelForHttpResponse(Client body) throws IOExcepti return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); } - public HttpResponse testClientModelForHttpResponse(InputStream body) throws IOException { + public HttpResponse testClientModelForHttpResponse(java.io.InputStream body) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling testClientModel"); @@ -693,7 +692,7 @@ public HttpResponse testInlineAdditionalPropertiesForHttpResponse(Object param) return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse testInlineAdditionalPropertiesForHttpResponse(InputStream param) throws IOException { + public HttpResponse testInlineAdditionalPropertiesForHttpResponse(java.io.InputStream param) throws IOException { // verify the required parameter 'param' is set if (param == null) { throw new IllegalArgumentException("Missing the required parameter 'param' when calling testInlineAdditionalProperties"); diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java index 6d28e9e72a2..addf1a0087b 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java @@ -13,7 +13,6 @@ import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; -import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -84,7 +83,7 @@ public HttpResponse testClassnameForHttpResponse(Client body) throws IOException return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); } - public HttpResponse testClassnameForHttpResponse(InputStream body) throws IOException { + public HttpResponse testClassnameForHttpResponse(java.io.InputStream body) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling testClassname"); diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/PetApi.java index e7588c2b3a3..443a90f4f90 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/PetApi.java @@ -15,7 +15,6 @@ import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; -import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -80,7 +79,7 @@ public HttpResponse addPetForHttpResponse(Pet body) throws IOException { return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse addPetForHttpResponse(InputStream body) throws IOException { + public HttpResponse addPetForHttpResponse(java.io.InputStream body) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling addPet"); @@ -513,7 +512,7 @@ public HttpResponse updatePetForHttpResponse(Pet body) throws IOException { return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); } - public HttpResponse updatePetForHttpResponse(InputStream body) throws IOException { + public HttpResponse updatePetForHttpResponse(java.io.InputStream body) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling updatePet"); diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java index 26a440112a8..5c65677f9ba 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java @@ -13,7 +13,6 @@ import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; -import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -318,7 +317,7 @@ public HttpResponse placeOrderForHttpResponse(Order body) throws IOException { return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse placeOrderForHttpResponse(InputStream body) throws IOException { + public HttpResponse placeOrderForHttpResponse(java.io.InputStream body) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling placeOrder"); diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java index 8275fae9771..faf7d15eda4 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java @@ -13,7 +13,6 @@ import com.google.api.client.json.Json; import javax.ws.rs.core.UriBuilder; -import java.io.InputStream; import java.io.IOException; import java.util.Collection; import java.util.HashMap; @@ -78,7 +77,7 @@ public HttpResponse createUserForHttpResponse(User body) throws IOException { return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse createUserForHttpResponse(InputStream body) throws IOException { + public HttpResponse createUserForHttpResponse(java.io.InputStream body) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling createUser"); @@ -162,7 +161,7 @@ public HttpResponse createUsersWithArrayInputForHttpResponse(List body) th return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse createUsersWithArrayInputForHttpResponse(InputStream body) throws IOException { + public HttpResponse createUsersWithArrayInputForHttpResponse(java.io.InputStream body) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling createUsersWithArrayInput"); @@ -246,7 +245,7 @@ public HttpResponse createUsersWithListInputForHttpResponse(List body) thr return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse createUsersWithListInputForHttpResponse(InputStream body) throws IOException { + public HttpResponse createUsersWithListInputForHttpResponse(java.io.InputStream body) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling createUsersWithListInput"); @@ -677,7 +676,7 @@ public HttpResponse updateUserForHttpResponse(String username, User body) throws return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); } - public HttpResponse updateUserForHttpResponse(String username, InputStream body) throws IOException { + public HttpResponse updateUserForHttpResponse(String username, java.io.InputStream body) throws IOException { // verify the required parameter 'username' is set if (username == null) { throw new IllegalArgumentException("Missing the required parameter 'username' when calling updateUser"); From 1a9b1972b48f0868fef668cefee1b47dd86b229c Mon Sep 17 00:00:00 2001 From: Charles Capps Date: Tue, 6 Mar 2018 16:00:18 -0800 Subject: [PATCH 3/4] Add support for Input Stream choosing content type, and fix a bug --- .../libraries/google-api-client/api.mustache | 10 +-- .../io/swagger/client/api/AnotherFakeApi.java | 10 +-- .../java/io/swagger/client/api/FakeApi.java | 72 +++++++++++-------- .../client/api/FakeClassnameTags123Api.java | 10 +-- .../java/io/swagger/client/api/PetApi.java | 44 ++++++------ .../java/io/swagger/client/api/StoreApi.java | 22 +++--- .../java/io/swagger/client/api/UserApi.java | 56 ++++++++------- 7 files changed, 128 insertions(+), 96 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache index 201c6443da3..56011b24d2a 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache @@ -107,11 +107,11 @@ public class {{classname}} { String url = uriBuilder{{#hasPathParams}}.buildFromMap(uriVariables).toString();{{/hasPathParams}}{{^hasPathParams}}.build().toString();{{/hasPathParams}} GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = {{#bodyParam}}{{paramName}} == null ? null : apiClient.new JacksonJsonHttpContent({{paramName}}){{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; + HttpContent content = apiClient.new JacksonJsonHttpContent({{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.{{httpMethod}}, genericUrl, content).execute(); }{{#bodyParam}} - public HttpResponse {{operationId}}ForHttpResponse({{#allParams}}{{#isBodyParam}}java.io.InputStream {{paramName}}{{/isBodyParam}}{{^isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws IOException { + public HttpResponse {{operationId}}ForHttpResponse({{#allParams}}{{#isBodyParam}}java.io.InputStream {{paramName}}{{/isBodyParam}}{{^isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}}, String mediaType) throws IOException { {{#allParams}}{{#required}}// verify the required parameter '{{paramName}}' is set if ({{paramName}} == null) { throw new IllegalArgumentException("Missing the required parameter '{{paramName}}' when calling {{operationId}}"); @@ -138,7 +138,9 @@ public class {{classname}} { String url = uriBuilder{{#hasPathParams}}.buildFromMap(uriVariables).toString();{{/hasPathParams}}{{^hasPathParams}}.build().toString();{{/hasPathParams}} GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = {{#bodyParam}}{{paramName}} == null ? null : new InputStreamContent(Json.MEDIA_TYPE, {{paramName}}){{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; + HttpContent content = {{#bodyParam}}{{paramName}} == null ? + apiClient.new JacksonJsonHttpContent(null) : + new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, {{paramName}}){{/bodyParam}}; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.{{httpMethod}}, genericUrl, content).execute(); }{{/bodyParam}} @@ -177,7 +179,7 @@ public class {{classname}} { String url = uriBuilder{{#hasPathParams}}.buildFromMap(uriVariables).toString();{{/hasPathParams}}{{^hasPathParams}}.build().toString();{{/hasPathParams}} GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = {{#bodyParam}}{{paramName}} == null ? null : apiClient.new JacksonJsonHttpContent({{paramName}}){{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; + HttpContent content = apiClient.new JacksonJsonHttpContent({{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.{{httpMethod}}, genericUrl, content).execute(); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java index 35e14044b2b..ac669657974 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/AnotherFakeApi.java @@ -79,11 +79,11 @@ public HttpResponse testSpecialTagsForHttpResponse(Client body) throws IOExcepti String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); } - public HttpResponse testSpecialTagsForHttpResponse(java.io.InputStream body) throws IOException { + public HttpResponse testSpecialTagsForHttpResponse(java.io.InputStream body, String mediaType) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling testSpecialTags"); @@ -93,7 +93,9 @@ public HttpResponse testSpecialTagsForHttpResponse(java.io.InputStream body) thr String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + HttpContent content = body == null ? + apiClient.new JacksonJsonHttpContent(null) : + new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); } @@ -125,7 +127,7 @@ public HttpResponse testSpecialTagsForHttpResponse(Client body, Map enumFormStrin String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -650,7 +660,7 @@ public HttpResponse testEnumParametersForHttpResponse(Map params String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -688,11 +698,11 @@ public HttpResponse testInlineAdditionalPropertiesForHttpResponse(Object param) String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = param == null ? null : apiClient.new JacksonJsonHttpContent(param); + HttpContent content = apiClient.new JacksonJsonHttpContent(param); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse testInlineAdditionalPropertiesForHttpResponse(java.io.InputStream param) throws IOException { + public HttpResponse testInlineAdditionalPropertiesForHttpResponse(java.io.InputStream param, String mediaType) throws IOException { // verify the required parameter 'param' is set if (param == null) { throw new IllegalArgumentException("Missing the required parameter 'param' when calling testInlineAdditionalProperties"); @@ -702,7 +712,9 @@ public HttpResponse testInlineAdditionalPropertiesForHttpResponse(java.io.InputS String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = param == null ? null : new InputStreamContent(Json.MEDIA_TYPE, param); + HttpContent content = param == null ? + apiClient.new JacksonJsonHttpContent(null) : + new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, param); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } @@ -734,7 +746,7 @@ public HttpResponse testInlineAdditionalPropertiesForHttpResponse(Object param, String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = param == null ? null : apiClient.new JacksonJsonHttpContent(param); + HttpContent content = apiClient.new JacksonJsonHttpContent(param); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } @@ -777,7 +789,7 @@ public HttpResponse testJsonFormDataForHttpResponse(String param, String param2) String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -812,7 +824,7 @@ public HttpResponse testJsonFormDataForHttpResponse(String param, String param2, String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java index addf1a0087b..a0fa9bdbb35 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java @@ -79,11 +79,11 @@ public HttpResponse testClassnameForHttpResponse(Client body) throws IOException String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); } - public HttpResponse testClassnameForHttpResponse(java.io.InputStream body) throws IOException { + public HttpResponse testClassnameForHttpResponse(java.io.InputStream body, String mediaType) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling testClassname"); @@ -93,7 +93,9 @@ public HttpResponse testClassnameForHttpResponse(java.io.InputStream body) throw String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + HttpContent content = body == null ? + apiClient.new JacksonJsonHttpContent(null) : + new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute(); } @@ -125,7 +127,7 @@ public HttpResponse testClassnameForHttpResponse(Client body, Map params) String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } @@ -163,7 +165,7 @@ public HttpResponse deletePetForHttpResponse(Long petId, String apiKey) throws I String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.DELETE, genericUrl, content).execute(); } @@ -198,7 +200,7 @@ public HttpResponse deletePetForHttpResponse(Long petId, Map par String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.DELETE, genericUrl, content).execute(); } @@ -255,7 +257,7 @@ public HttpResponse findPetsByStatusForHttpResponse(List status) throws String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -289,7 +291,7 @@ public HttpResponse findPetsByStatusForHttpResponse(List status, Map tags) throws IOEx String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -380,7 +382,7 @@ public HttpResponse findPetsByTagsForHttpResponse(List tags, Map pa String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -508,11 +510,11 @@ public HttpResponse updatePetForHttpResponse(Pet body) throws IOException { String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); } - public HttpResponse updatePetForHttpResponse(java.io.InputStream body) throws IOException { + public HttpResponse updatePetForHttpResponse(java.io.InputStream body, String mediaType) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling updatePet"); @@ -522,7 +524,9 @@ public HttpResponse updatePetForHttpResponse(java.io.InputStream body) throws IO String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + HttpContent content = body == null ? + apiClient.new JacksonJsonHttpContent(null) : + new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); } @@ -554,7 +558,7 @@ public HttpResponse updatePetForHttpResponse(Pet body, Map param String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); } @@ -597,7 +601,7 @@ public HttpResponse updatePetWithFormForHttpResponse(Long petId, String name, St String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } @@ -632,7 +636,7 @@ public HttpResponse updatePetWithFormForHttpResponse(Long petId, Map pa String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java index 5c65677f9ba..18eb9117477 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java @@ -78,7 +78,7 @@ public HttpResponse deleteOrderForHttpResponse(String orderId) throws IOExceptio String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.DELETE, genericUrl, content).execute(); } @@ -113,7 +113,7 @@ public HttpResponse deleteOrderForHttpResponse(String orderId, Map params) thro String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -232,7 +232,7 @@ public HttpResponse getOrderByIdForHttpResponse(Long orderId) throws IOException String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -267,7 +267,7 @@ public HttpResponse getOrderByIdForHttpResponse(Long orderId, Map pa String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java index faf7d15eda4..db7206c41ee 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/UserApi.java @@ -73,11 +73,11 @@ public HttpResponse createUserForHttpResponse(User body) throws IOException { String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse createUserForHttpResponse(java.io.InputStream body) throws IOException { + public HttpResponse createUserForHttpResponse(java.io.InputStream body, String mediaType) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling createUser"); @@ -87,7 +87,9 @@ public HttpResponse createUserForHttpResponse(java.io.InputStream body) throws I String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + HttpContent content = body == null ? + apiClient.new JacksonJsonHttpContent(null) : + new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } @@ -119,7 +121,7 @@ public HttpResponse createUserForHttpResponse(User body, Map par String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } @@ -157,11 +159,11 @@ public HttpResponse createUsersWithArrayInputForHttpResponse(List body) th String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse createUsersWithArrayInputForHttpResponse(java.io.InputStream body) throws IOException { + public HttpResponse createUsersWithArrayInputForHttpResponse(java.io.InputStream body, String mediaType) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling createUsersWithArrayInput"); @@ -171,7 +173,9 @@ public HttpResponse createUsersWithArrayInputForHttpResponse(java.io.InputStream String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + HttpContent content = body == null ? + apiClient.new JacksonJsonHttpContent(null) : + new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } @@ -203,7 +207,7 @@ public HttpResponse createUsersWithArrayInputForHttpResponse(List body, Ma String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } @@ -241,11 +245,11 @@ public HttpResponse createUsersWithListInputForHttpResponse(List body) thr String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } - public HttpResponse createUsersWithListInputForHttpResponse(java.io.InputStream body) throws IOException { + public HttpResponse createUsersWithListInputForHttpResponse(java.io.InputStream body, String mediaType) throws IOException { // verify the required parameter 'body' is set if (body == null) { throw new IllegalArgumentException("Missing the required parameter 'body' when calling createUsersWithListInput"); @@ -255,7 +259,9 @@ public HttpResponse createUsersWithListInputForHttpResponse(java.io.InputStream String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + HttpContent content = body == null ? + apiClient.new JacksonJsonHttpContent(null) : + new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } @@ -287,7 +293,7 @@ public HttpResponse createUsersWithListInputForHttpResponse(List body, Map String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute(); } @@ -330,7 +336,7 @@ public HttpResponse deleteUserForHttpResponse(String username) throws IOExceptio String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.DELETE, genericUrl, content).execute(); } @@ -365,7 +371,7 @@ public HttpResponse deleteUserForHttpResponse(String username, Map params) throws String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = null; + HttpContent content = apiClient.new JacksonJsonHttpContent(null); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -672,11 +678,11 @@ public HttpResponse updateUserForHttpResponse(String username, User body) throws String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : apiClient.new JacksonJsonHttpContent(body); + HttpContent content = apiClient.new JacksonJsonHttpContent(body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); } - public HttpResponse updateUserForHttpResponse(String username, java.io.InputStream body) throws IOException { + public HttpResponse updateUserForHttpResponse(String username, java.io.InputStream body, String mediaType) throws IOException { // verify the required parameter 'username' is set if (username == null) { throw new IllegalArgumentException("Missing the required parameter 'username' when calling updateUser"); @@ -692,7 +698,9 @@ public HttpResponse updateUserForHttpResponse(String username, java.io.InputStre String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = body == null ? null : new InputStreamContent(Json.MEDIA_TYPE, body); + HttpContent content = body == null ? + apiClient.new JacksonJsonHttpContent(null) : + new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body); return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute(); } @@ -730,7 +738,7 @@ public HttpResponse updateUserForHttpResponse(String username, User body, Map Date: Tue, 6 Mar 2018 17:25:23 -0800 Subject: [PATCH 4/4] Ensure GET requests send an empty request body! --- .../libraries/google-api-client/api.mustache | 4 ++-- .../main/java/io/swagger/client/api/FakeApi.java | 8 ++++---- .../main/java/io/swagger/client/api/PetApi.java | 16 ++++++++-------- .../java/io/swagger/client/api/StoreApi.java | 12 ++++++------ .../main/java/io/swagger/client/api/UserApi.java | 16 ++++++++-------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache index 56011b24d2a..46ecf3af355 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/google-api-client/api.mustache @@ -107,7 +107,7 @@ public class {{classname}} { String url = uriBuilder{{#hasPathParams}}.buildFromMap(uriVariables).toString();{{/hasPathParams}}{{^hasPathParams}}.build().toString();{{/hasPathParams}} GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent({{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}); + HttpContent content = {{#isBodyAllowed}}apiClient.new JacksonJsonHttpContent({{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}){{/isBodyAllowed}}{{^isBodyAllowed}}null{{/isBodyAllowed}}; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.{{httpMethod}}, genericUrl, content).execute(); }{{#bodyParam}} @@ -179,7 +179,7 @@ public class {{classname}} { String url = uriBuilder{{#hasPathParams}}.buildFromMap(uriVariables).toString();{{/hasPathParams}}{{^hasPathParams}}.build().toString();{{/hasPathParams}} GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent({{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}); + HttpContent content = {{#isBodyAllowed}}apiClient.new JacksonJsonHttpContent({{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}){{/isBodyAllowed}}{{^isBodyAllowed}}null{{/isBodyAllowed}}; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.{{httpMethod}}, genericUrl, content).execute(); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeApi.java index 8f49e9cb2f2..013833c1181 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/FakeApi.java @@ -631,7 +631,7 @@ public HttpResponse testEnumParametersForHttpResponse(List enumFormStrin String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -660,7 +660,7 @@ public HttpResponse testEnumParametersForHttpResponse(Map params String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -789,7 +789,7 @@ public HttpResponse testJsonFormDataForHttpResponse(String param, String param2) String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -824,7 +824,7 @@ public HttpResponse testJsonFormDataForHttpResponse(String param, String param2, String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/PetApi.java index 364e399eeda..bf870700694 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/PetApi.java @@ -165,7 +165,7 @@ public HttpResponse deletePetForHttpResponse(Long petId, String apiKey) throws I String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.DELETE, genericUrl, content).execute(); } @@ -200,7 +200,7 @@ public HttpResponse deletePetForHttpResponse(Long petId, Map par String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.DELETE, genericUrl, content).execute(); } @@ -257,7 +257,7 @@ public HttpResponse findPetsByStatusForHttpResponse(List status) throws String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -291,7 +291,7 @@ public HttpResponse findPetsByStatusForHttpResponse(List status, Map tags) throws IOEx String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -382,7 +382,7 @@ public HttpResponse findPetsByTagsForHttpResponse(List tags, Map pa String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } diff --git a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java index 18eb9117477..dc407a874f1 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/io/swagger/client/api/StoreApi.java @@ -78,7 +78,7 @@ public HttpResponse deleteOrderForHttpResponse(String orderId) throws IOExceptio String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.DELETE, genericUrl, content).execute(); } @@ -113,7 +113,7 @@ public HttpResponse deleteOrderForHttpResponse(String orderId, Map params) thro String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -232,7 +232,7 @@ public HttpResponse getOrderByIdForHttpResponse(Long orderId) throws IOException String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); } @@ -267,7 +267,7 @@ public HttpResponse getOrderByIdForHttpResponse(Long orderId, Map params) throws String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); - HttpContent content = apiClient.new JacksonJsonHttpContent(null); + HttpContent content = null; return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute(); }