Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java][client][resteasy][jersey2][google-api-client][okhttp-json] several fixes to make sent requests more accurate #3703

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {{invokerPackage}}.ApiClient;
{{/imports}}

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.http.EmptyContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpContent;
import com.google.api.client.http.InputStreamContent;
Expand Down Expand Up @@ -107,7 +108,7 @@ public class {{classname}} {
String localVarUrl = uriBuilder{{#hasPathParams}}.buildFromMap(uriVariables).toString();{{/hasPathParams}}{{^hasPathParams}}.build().toString();{{/hasPathParams}}
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = {{#isBodyAllowed}}apiClient.new JacksonJsonHttpContent({{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}){{/isBodyAllowed}}{{^isBodyAllowed}}null{{/isBodyAllowed}};
HttpContent content = {{#isBodyAllowed}}{{#bodyParam}}apiClient.new JacksonJsonHttpContent({{paramName}}){{/bodyParam}}{{^bodyParam}}new EmptyContent(){{/bodyParam}}{{/isBodyAllowed}}{{^isBodyAllowed}}null{{/isBodyAllowed}};
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.{{httpMethod}}, genericUrl, content).execute();
}{{#bodyParam}}

Expand Down Expand Up @@ -179,7 +180,7 @@ public class {{classname}} {
String localVarUrl = uriBuilder{{#hasPathParams}}.buildFromMap(uriVariables).toString();{{/hasPathParams}}{{^hasPathParams}}.build().toString();{{/hasPathParams}}
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = {{#isBodyAllowed}}apiClient.new JacksonJsonHttpContent({{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}){{/isBodyAllowed}}{{^isBodyAllowed}}null{{/isBodyAllowed}};
HttpContent content = {{#isBodyAllowed}}{{#bodyParam}}apiClient.new JacksonJsonHttpContent({{paramName}}){{/bodyParam}}{{^bodyParam}}new EmptyContent(){{/bodyParam}}{{/isBodyAllowed}}{{^isBodyAllowed}}null{{/isBodyAllowed}};
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.{{httpMethod}}, genericUrl, content).execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ public class ApiClient {
}
}

Entity<?> entity = serialize(body, formParams, contentType);
Entity<?> entity = (body == null) ? Entity.json("") : serialize(body, formParams, contentType);

Response response = null;

Expand All @@ -716,7 +716,7 @@ public class ApiClient {
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
response = invocationBuilder.method("DELETE", entity);
} else if ("PATCH".equals(method)) {
response = invocationBuilder.method("PATCH", entity);
} else if ("HEAD".equals(method)) {
Expand Down Expand Up @@ -776,6 +776,8 @@ public class ApiClient {
clientConfig.register(json);
clientConfig.register(JacksonFeature.class);
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
// turn off compliance validation to be able to send payloads with DELETE calls
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
if (debugging) {
{{^supportJava6}}
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
Expand All @@ -786,6 +788,9 @@ public class ApiClient {
{{#supportJava6}}
clientConfig.register(new LoggingFilter(java.util.logging.Logger.getLogger(LoggingFilter.class.getName()), true));
{{/supportJava6}}
} else {
// suppress warnings for payloads with DELETE calls:
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
}
performAdditionalClientConfiguration(clientConfig);
return ClientBuilder.newClient(clientConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class {{classname}} {
@Deprecated
{{/isDeprecated}}
public ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{operationId}}WithHttpInfo({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}new Object(){{/bodyParam}};
Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class {{classname}} {
@Deprecated
{{/isDeprecated}}
public{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}private{{/vendorExtensions.x-group-parameters}} okhttp3.Call {{operationId}}Call({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback _callback) throws ApiException {
Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}new Object(){{/bodyParam}};
Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};

// create path and map variables
String localVarPath = "{{{path}}}"{{#pathParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,9 @@ public class ApiClient {
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
response = invocationBuilder.method("DELETE", entity);
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
response = invocationBuilder.method("PATCH", entity);
} else if ("HEAD".equals(method)) {
response = invocationBuilder.head();
} else if ("OPTIONS".equals(method)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class {{classname}} {
@Deprecated
{{/isDeprecated}}
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}new Object(){{/bodyParam}};
Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.openapitools.client.model.Client;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.http.EmptyContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpContent;
import com.google.api.client.http.InputStreamContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.openapitools.client.model.XmlItem;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.http.EmptyContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpContent;
import com.google.api.client.http.InputStreamContent;
Expand Down Expand Up @@ -807,7 +808,7 @@ public HttpResponse testEndpointParametersForHttpResponse(BigDecimal number, Dou
String localVarUrl = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpContent content = new EmptyContent();
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}

Expand Down Expand Up @@ -848,7 +849,7 @@ public HttpResponse testEndpointParametersForHttpResponse(BigDecimal number, Dou
String localVarUrl = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpContent content = new EmptyContent();
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}

Expand Down Expand Up @@ -1362,7 +1363,7 @@ public HttpResponse testQueryParameterCollectionFormatForHttpResponse(List<Strin
String localVarUrl = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpContent content = new EmptyContent();
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute();
}

Expand Down Expand Up @@ -1416,7 +1417,7 @@ public HttpResponse testQueryParameterCollectionFormatForHttpResponse(List<Strin
String localVarUrl = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpContent content = new EmptyContent();
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.openapitools.client.model.Client;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.http.EmptyContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpContent;
import com.google.api.client.http.InputStreamContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.openapitools.client.model.Pet;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.http.EmptyContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpContent;
import com.google.api.client.http.InputStreamContent;
Expand Down Expand Up @@ -599,7 +600,7 @@ public HttpResponse updatePetWithFormForHttpResponse(Long petId, String name, St
String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpContent content = new EmptyContent();
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}

Expand Down Expand Up @@ -634,7 +635,7 @@ public HttpResponse updatePetWithFormForHttpResponse(Long petId, Map<String, Obj
String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpContent content = new EmptyContent();
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}

Expand Down Expand Up @@ -681,7 +682,7 @@ public HttpResponse uploadFileForHttpResponse(Long petId, String additionalMetad
String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpContent content = new EmptyContent();
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}

Expand Down Expand Up @@ -716,7 +717,7 @@ public HttpResponse uploadFileForHttpResponse(Long petId, Map<String, Object> pa
String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpContent content = new EmptyContent();
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}

Expand Down Expand Up @@ -767,7 +768,7 @@ public HttpResponse uploadFileWithRequiredFileForHttpResponse(Long petId, File r
String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpContent content = new EmptyContent();
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}

Expand Down Expand Up @@ -805,7 +806,7 @@ public HttpResponse uploadFileWithRequiredFileForHttpResponse(Long petId, File r
String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(localVarUrl);

HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpContent content = new EmptyContent();
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.openapitools.client.model.Order;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.http.EmptyContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpContent;
import com.google.api.client.http.InputStreamContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.openapitools.client.model.User;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.http.EmptyContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpContent;
import com.google.api.client.http.InputStreamContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
}
}

Entity<?> entity = serialize(body, formParams, contentType);
Entity<?> entity = (body == null) ? Entity.json("") : serialize(body, formParams, contentType);

Response response = null;

Expand All @@ -700,7 +700,7 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
response = invocationBuilder.method("DELETE", entity);
} else if ("PATCH".equals(method)) {
response = invocationBuilder.method("PATCH", entity);
} else if ("HEAD".equals(method)) {
Expand Down Expand Up @@ -760,8 +760,13 @@ protected Client buildHttpClient(boolean debugging) {
clientConfig.register(json);
clientConfig.register(JacksonFeature.class);
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
// turn off compliance validation to be able to send payloads with DELETE calls
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
if (debugging) {
clientConfig.register(new LoggingFilter(java.util.logging.Logger.getLogger(LoggingFilter.class.getName()), true));
} else {
// suppress warnings for payloads with DELETE calls:
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
}
performAdditionalClientConfiguration(clientConfig);
return ClientBuilder.newClient(clientConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public void testEndpointParameters(BigDecimal number, Double _double, String pat
</table>
*/
public ApiResponse<Void> testEndpointParametersWithHttpInfo(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, File binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'number' is set
if (number == null) {
Expand Down Expand Up @@ -705,7 +705,7 @@ public void testEnumParameters(List<String> enumHeaderStringArray, String enumHe
</table>
*/
public ApiResponse<Void> testEnumParametersWithHttpInfo(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<String> enumFormStringArray, String enumFormString) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// create path and map variables
String localVarPath = "/fake";
Expand Down Expand Up @@ -784,7 +784,7 @@ public void testGroupParameters(Integer requiredStringGroup, Boolean requiredBoo
</table>
*/
public ApiResponse<Void> testGroupParametersWithHttpInfo(Integer requiredStringGroup, Boolean requiredBooleanGroup, Long requiredInt64Group, Integer stringGroup, Boolean booleanGroup, Long int64Group) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'requiredStringGroup' is set
if (requiredStringGroup == null) {
Expand Down Expand Up @@ -928,7 +928,7 @@ public void testJsonFormData(String param, String param2) throws ApiException {
</table>
*/
public ApiResponse<Void> testJsonFormDataWithHttpInfo(String param, String param2) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'param' is set
if (param == null) {
Expand Down Expand Up @@ -1007,7 +1007,7 @@ public void testQueryParameterCollectionFormat(List<String> pipe, List<String> i
</table>
*/
public ApiResponse<Void> testQueryParameterCollectionFormatWithHttpInfo(List<String> pipe, List<String> ioutil, List<String> http, List<String> url, List<String> context) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'pipe' is set
if (pipe == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void deletePet(Long petId, String apiKey) throws ApiException {
</table>
*/
public ApiResponse<Void> deletePetWithHttpInfo(Long petId, String apiKey) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'petId' is set
if (petId == null) {
Expand Down Expand Up @@ -201,7 +201,7 @@ public List<Pet> findPetsByStatus(List<String> status) throws ApiException {
</table>
*/
public ApiResponse<List<Pet>> findPetsByStatusWithHttpInfo(List<String> status) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'status' is set
if (status == null) {
Expand Down Expand Up @@ -270,7 +270,7 @@ public List<Pet> findPetsByTags(List<String> tags) throws ApiException {
*/
@Deprecated
public ApiResponse<List<Pet>> findPetsByTagsWithHttpInfo(List<String> tags) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'tags' is set
if (tags == null) {
Expand Down Expand Up @@ -337,7 +337,7 @@ public Pet getPetById(Long petId) throws ApiException {
</table>
*/
public ApiResponse<Pet> getPetByIdWithHttpInfo(Long petId) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'petId' is set
if (petId == null) {
Expand Down Expand Up @@ -472,7 +472,7 @@ public void updatePetWithForm(Long petId, String name, String status) throws Api
</table>
*/
public ApiResponse<Void> updatePetWithFormWithHttpInfo(Long petId, String name, String status) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'petId' is set
if (petId == null) {
Expand Down Expand Up @@ -543,7 +543,7 @@ public ModelApiResponse uploadFile(Long petId, String additionalMetadata, File f
</table>
*/
public ApiResponse<ModelApiResponse> uploadFileWithHttpInfo(Long petId, String additionalMetadata, File file) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'petId' is set
if (petId == null) {
Expand Down Expand Up @@ -614,7 +614,7 @@ public ModelApiResponse uploadFileWithRequiredFile(Long petId, File requiredFile
</table>
*/
public ApiResponse<ModelApiResponse> uploadFileWithRequiredFileWithHttpInfo(Long petId, File requiredFile, String additionalMetadata) throws ApiException {
Object localVarPostBody = new Object();
Object localVarPostBody = null;

// verify the required parameter 'petId' is set
if (petId == null) {
Expand Down
Loading