[Java] MIME type "*/*" default to JSON (#6188)

* update java petstore

* minor fix to docstring

* roll back resttemplate with xml petstore due to errors

* minor fix to resttemplate isjson check
This commit is contained in:
wing328 2017-07-27 11:36:29 +08:00 committed by GitHub
parent 44e7b5dd3f
commit 927055a681
54 changed files with 89 additions and 55 deletions

View File

@ -438,12 +438,13 @@ 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.equalsIgnoreCase("application/json-patch+json"));
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}
/**

View File

@ -571,12 +571,13 @@ public class ApiClient {
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* @param mime MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public boolean isJsonMime(String mime) {
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json"));
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}
/**

View File

@ -377,9 +377,13 @@ public class ApiClient {
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* @param mime MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public boolean isJsonMime(String mime) {
return mime != null && mime.matches("(?i)application\\/json(;.*)?");
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}
/**

View File

@ -424,6 +424,11 @@ public class ApiClient {
* @return boolean true if the MediaType represents JSON, false otherwise
*/
public boolean isJsonMime(String mediaType) {
// "* / *" is default to JSON
if ("*/*".equals(mediaType)) {
return true;
}
try {
return isJsonMime(MediaType.parseMediaType(mediaType));
} catch (InvalidMediaTypeException e) {

0
samples/client/petstore/java/feign/gradlew vendored Executable file → Normal file
View File

View File

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

View File

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

0
samples/client/petstore/java/jersey1/gradlew vendored Executable file → Normal file
View File

View File

@ -512,10 +512,10 @@ public class ApiClient {
*
* @param contentTypes The Content-Type array to select from
* @return The Content-Type header to use. If the given array is empty,
* JSON will be used.
* or matches "any", JSON will be used.
*/
public String selectHeaderContentType(String[] contentTypes) {
if (contentTypes.length == 0) {
if (contentTypes.length == 0 || contentTypes[0].equals("*/*")) {
return "application/json";
}
for (String contentType : contentTypes) {

View File

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

View File

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

0
samples/client/petstore/java/jersey2-java6/gradlew vendored Executable file → Normal file
View File

View File

@ -432,12 +432,13 @@ 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.equalsIgnoreCase("application/json-patch+json"));
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}
/**

View File

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

View File

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

0
samples/client/petstore/java/jersey2-java8/gradlew vendored Executable file → Normal file
View File

View File

@ -13,8 +13,8 @@ import javax.ws.rs.core.Response.Status;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.filter.LoggingFilter;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.MultiPart;
@ -51,21 +51,21 @@ import io.swagger.client.auth.OAuth;
public class ApiClient {
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private String basePath = "http://petstore.swagger.io:80/v2";
private boolean debugging = false;
private int connectionTimeout = 0;
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
protected String basePath = "http://petstore.swagger.io:80/v2";
protected boolean debugging = false;
protected int connectionTimeout = 0;
private Client httpClient;
private JSON json;
private String tempFolderPath = null;
protected Client httpClient;
protected JSON json;
protected String tempFolderPath = null;
private Map<String, Authentication> authentications;
protected Map<String, Authentication> authentications;
private int statusCode;
private Map<String, List<String>> responseHeaders;
protected int statusCode;
protected Map<String, List<String>> responseHeaders;
private DateFormat dateFormat;
protected DateFormat dateFormat;
public ApiClient() {
json = new JSON();
@ -433,12 +433,13 @@ 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.equalsIgnoreCase("application/json-patch+json"));
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}
/**
@ -729,18 +730,26 @@ public class ApiClient {
* @param debugging Debug setting
* @return Client
*/
private Client buildHttpClient(boolean debugging) {
protected Client buildHttpClient(boolean debugging) {
final ClientConfig clientConfig = new ClientConfig();
clientConfig.register(MultiPartFeature.class);
clientConfig.register(json);
clientConfig.register(JacksonFeature.class);
if (debugging) {
clientConfig.register(new LoggingFilter(java.util.logging.Logger.getLogger(LoggingFilter.class.getName()), true));
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);
// Set logger to ALL
java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME).setLevel(java.util.logging.Level.ALL);
}
performAdditionalClientConfiguration(clientConfig);
return ClientBuilder.newClient(clientConfig);
}
private Map<String, List<String>> buildResponseHeaders(Response response) {
protected void performAdditionalClientConfiguration(ClientConfig clientConfig) {
// No-op extension point
}
protected Map<String, List<String>> buildResponseHeaders(Response response) {
Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
for (Entry<String, List<Object>> entry: response.getHeaders().entrySet()) {
List<Object> values = entry.getValue();
@ -758,7 +767,7 @@ public class ApiClient {
*
* @param authNames The authentications to apply
*/
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
for (String authName : authNames) {
Authentication auth = authentications.get(authName);
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);

View File

@ -168,6 +168,7 @@ public class PetApi {
* @param tags Tags to filter by (required)
* @return List&lt;Pet&gt;
* @throws ApiException if fails to make API call
* @Deprecated
*/
public List<Pet> findPetsByTags(List<String> tags) throws ApiException {
Object localVarPostBody = null;

View File

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

View File

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

0
samples/client/petstore/java/jersey2/gradlew vendored Executable file → Normal file
View File

View File

@ -433,12 +433,13 @@ 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.equalsIgnoreCase("application/json-patch+json"));
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}
/**

View File

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

View File

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

0
samples/client/petstore/java/okhttp-gson-parcelableModel/gradlew vendored Executable file → Normal file
View File

View File

@ -552,12 +552,13 @@ public class ApiClient {
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* @param mime MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public boolean isJsonMime(String mime) {
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json"));
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}
/**

View File

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

View File

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

0
samples/client/petstore/java/okhttp-gson/gradlew vendored Executable file → Normal file
View File

View File

@ -552,12 +552,13 @@ public class ApiClient {
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* @param mime MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public boolean isJsonMime(String mime) {
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json"));
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}
/**

0
samples/client/petstore/java/resteasy/gradlew vendored Executable file → Normal file
View File

View File

@ -377,9 +377,13 @@ public class ApiClient {
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* @param mime MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public boolean isJsonMime(String mime) {
return mime != null && mime.matches("(?i)application\\/json(;.*)?");
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}
/**

View File

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

View File

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

View File

@ -1 +1 @@
2.2.3-SNAPSHOT
2.3.0-SNAPSHOT

0
samples/client/petstore/java/resttemplate/gradlew vendored Executable file → Normal file
View File

View File

@ -411,6 +411,11 @@ public class ApiClient {
* @return boolean true if the MediaType represents JSON, false otherwise
*/
public boolean isJsonMime(String mediaType) {
// "* / *" is default to JSON
if ("*/*".equals(mediaType)) {
return true;
}
try {
return isJsonMime(MediaType.parseMediaType(mediaType));
} catch (InvalidMediaTypeException e) {
@ -645,4 +650,4 @@ public class ApiClient {
return builder.toString();
}
}
}
}

View File

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

View File

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

0
samples/client/petstore/java/retrofit/gradlew vendored Executable file → Normal file
View File

View File

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

View File

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

0
samples/client/petstore/java/retrofit2-play24/gradlew vendored Executable file → Normal file
View File

View File

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

View File

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

0
samples/client/petstore/java/retrofit2/gradlew vendored Executable file → Normal file
View File

View File

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

View File

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

0
samples/client/petstore/java/retrofit2rx/gradlew vendored Executable file → Normal file
View File

View File

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

View File

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

0
samples/client/petstore/java/retrofit2rx2/gradlew vendored Executable file → Normal file
View File

View File

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

View File

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