mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-20 08:57:04 +00:00
[java-client][resteasy][jersey2][google-api-client][okhttp-json] several fixes to make sent requests more accurate (#3703)
This commit is contained in:
@@ -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;
|
||||
@@ -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}}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)) {
|
||||
@@ -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 */));
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user