[Java][Client] Add PATCH method support for jersey2 (#6197)

This commit is contained in:
Halil İbrahim Şener 2017-07-31 08:08:30 +03:00 committed by wing328
parent 443b0f142b
commit a6f981350e
12 changed files with 42 additions and 16 deletions

View File

@ -13,6 +13,7 @@ import javax.ws.rs.core.Response.Status;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
@ -695,7 +696,7 @@ public class ApiClient {
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
response = invocationBuilder.method("PATCH", entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}
@ -746,6 +747,7 @@ public class ApiClient {
clientConfig.register(MultiPartFeature.class);
clientConfig.register(json);
clientConfig.register(JacksonFeature.class);
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
if (debugging) {
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 */));
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);

View File

@ -16,9 +16,19 @@ To test class name in snake case
### Example
```java
// Import classes:
//import io.swagger.client.ApiClient;
//import io.swagger.client.ApiException;
//import io.swagger.client.Configuration;
//import io.swagger.client.auth.*;
//import io.swagger.client.api.FakeClassnameTags123Api;
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure API key authorization: api_key_query
ApiKeyAuth api_key_query = (ApiKeyAuth) defaultClient.getAuthentication("api_key_query");
api_key_query.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//api_key_query.setApiKeyPrefix("Token");
FakeClassnameTags123Api apiInstance = new FakeClassnameTags123Api();
Client body = new Client(); // Client | client model
@ -43,7 +53,7 @@ Name | Type | Description | Notes
### Authorization
No authorization required
[api_key_query](../README.md#api_key_query)
### HTTP request headers

View File

@ -247,7 +247,7 @@
</dependencies>
<properties>
<swagger-core-version>1.5.15</swagger-core-version>
<jersey-version>2.6</jersey-version>
<jersey-version>2.25.1</jersey-version>
<commons_io_version>2.5</commons_io_version>
<commons_lang3_version>3.6</commons_lang3_version>
<jackson-version>2.6.4</jackson-version>

View File

@ -13,6 +13,7 @@ import javax.ws.rs.core.Response.Status;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
@ -78,6 +79,7 @@ public class ApiClient {
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
authentications.put("http_basic_test", new HttpBasicAuth());
authentications.put("petstore_auth", new OAuth());
// Prevent the authentications from being modified.
@ -432,13 +434,12 @@ public class ApiClient {
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* @param mime MIME
* @return True if the MIME type is JSON
*/
public boolean isJsonMime(String mime) {
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json"));
}
/**
@ -684,7 +685,7 @@ public class ApiClient {
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
response = invocationBuilder.method("PATCH", entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}
@ -735,6 +736,7 @@ public class ApiClient {
clientConfig.register(MultiPartFeature.class);
clientConfig.register(json);
clientConfig.register(JacksonFeature.class);
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
if (debugging) {
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 */));
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);

View File

@ -70,7 +70,7 @@ public class FakeClassnameTags123Api {
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
String[] localVarAuthNames = new String[] { };
String[] localVarAuthNames = new String[] { "api_key_query" };
GenericType<Client> localVarReturnType = new GenericType<Client>() {};
return apiClient.invokeAPI(localVarPath, "PATCH", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);

View File

@ -39,7 +39,7 @@ public class Cat extends Animal {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean isDeclawed() {
public Boolean getDeclawed() {
return declawed;
}

View File

@ -181,7 +181,7 @@ public class Order {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean isComplete() {
public Boolean getComplete() {
return complete;
}

View File

@ -16,9 +16,19 @@ To test class name in snake case
### Example
```java
// Import classes:
//import io.swagger.client.ApiClient;
//import io.swagger.client.ApiException;
//import io.swagger.client.Configuration;
//import io.swagger.client.auth.*;
//import io.swagger.client.api.FakeClassnameTags123Api;
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure API key authorization: api_key_query
ApiKeyAuth api_key_query = (ApiKeyAuth) defaultClient.getAuthentication("api_key_query");
api_key_query.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//api_key_query.setApiKeyPrefix("Token");
FakeClassnameTags123Api apiInstance = new FakeClassnameTags123Api();
Client body = new Client(); // Client | client model
@ -43,7 +53,7 @@ Name | Type | Description | Notes
### Authorization
No authorization required
[api_key_query](../README.md#api_key_query)
### HTTP request headers

View File

@ -13,6 +13,7 @@ import javax.ws.rs.core.Response.Status;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
@ -79,6 +80,7 @@ public class ApiClient {
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
authentications.put("http_basic_test", new HttpBasicAuth());
authentications.put("petstore_auth", new OAuth());
// Prevent the authentications from being modified.
@ -433,13 +435,12 @@ public class ApiClient {
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* @param mime MIME
* @return True if the MIME type is JSON
*/
public boolean isJsonMime(String mime) {
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json"));
}
/**
@ -684,7 +685,7 @@ public class ApiClient {
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
response = invocationBuilder.method("PATCH", entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}
@ -735,6 +736,7 @@ public class ApiClient {
clientConfig.register(MultiPartFeature.class);
clientConfig.register(json);
clientConfig.register(JacksonFeature.class);
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
if (debugging) {
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 */));
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);

View File

@ -70,7 +70,7 @@ public class FakeClassnameTags123Api {
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
String[] localVarAuthNames = new String[] { };
String[] localVarAuthNames = new String[] { "api_key_query" };
GenericType<Client> localVarReturnType = new GenericType<Client>() {};
return apiClient.invokeAPI(localVarPath, "PATCH", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);

View File

@ -39,7 +39,7 @@ public class Cat extends Animal {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean isDeclawed() {
public Boolean getDeclawed() {
return declawed;
}

View File

@ -181,7 +181,7 @@ public class Order {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean isComplete() {
public Boolean getComplete() {
return complete;
}