From 8ca92405d66d90622cf04fa54df4fb211d88eaa6 Mon Sep 17 00:00:00 2001 From: David Harrigan Date: Fri, 24 Mar 2017 10:23:00 -0400 Subject: [PATCH 1/6] [#5172] Allow vendor json media types --- .../main/resources/Java/ApiClient.mustache | 4 ++- .../Java/libraries/jersey2/ApiClient.mustache | 6 +++-- .../libraries/okhttp-gson/ApiClient.mustache | 9 ++++--- .../java/io/swagger/client/ApiClient.java | 4 ++- .../java/io/swagger/client/ApiClientTest.java | 27 ++++++++++++------- .../java/io/swagger/client/ApiClientTest.java | 27 ++++++++++++------- .../java/io/swagger/client/ApiClientTest.java | 27 ++++++++++++------- .../java/io/swagger/client/ApiClient.java | 9 ++++--- .../java/io/swagger/client/ApiClientTest.java | 27 ++++++++++++------- 9 files changed, 92 insertions(+), 48 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache index be339eca404..8c2f4577520 100644 --- a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache @@ -458,11 +458,13 @@ public class ApiClient { * application/json * application/json; charset=UTF8 * APPLICATION/JSON + * application/vnd.company+json * @param mime MIME * @return True if MIME type is boolean */ 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); } /** diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index 5eecde91664..7dc53e8abc5 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -436,11 +436,13 @@ public class ApiClient { * application/json * application/json; charset=UTF8 * APPLICATION/JSON + * application/vnd.company+json * @param mime MIME - * @return True if the MIME type is JSON + * @return True if MIME type is boolean */ 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); } /** diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache index b119a5e35ef..659516358c7 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache @@ -720,12 +720,13 @@ public class ApiClient { * application/json * application/json; charset=UTF8 * APPLICATION/JSON - * - * @param mime MIME (Multipurpose Internet Mail Extensions) - * @return True if the given MIME is JSON, false otherwise. + * application/vnd.company+json + * @param mime MIME + * @return True if MIME type is boolean */ 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); } /** diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java index 90f05be0078..b9a6fbba9b0 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java @@ -459,11 +459,13 @@ public List parameterToPairs(String collectionFormat, String name, Object * application/json * application/json; charset=UTF8 * APPLICATION/JSON + * application/vnd.company+json * @param mime MIME * @return True if MIME type is boolean */ 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); } /** diff --git a/samples/client/petstore/java/jersey1/src/test/java/io/swagger/client/ApiClientTest.java b/samples/client/petstore/java/jersey1/src/test/java/io/swagger/client/ApiClientTest.java index 19b55257d0c..eb1bd1164ff 100644 --- a/samples/client/petstore/java/jersey1/src/test/java/io/swagger/client/ApiClientTest.java +++ b/samples/client/petstore/java/jersey1/src/test/java/io/swagger/client/ApiClientTest.java @@ -40,15 +40,24 @@ public void testParseAndFormatDate() { @Test public void testIsJsonMime() { - assertFalse(apiClient.isJsonMime(null)); - assertFalse(apiClient.isJsonMime("")); - assertFalse(apiClient.isJsonMime("text/plain")); - assertFalse(apiClient.isJsonMime("application/xml")); - assertFalse(apiClient.isJsonMime("application/jsonp")); - - assertTrue(apiClient.isJsonMime("application/json")); - assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); - assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + assertFalse(apiClient.isJsonMime(null)); + assertFalse(apiClient.isJsonMime("")); + assertFalse(apiClient.isJsonMime("text/plain")); + assertFalse(apiClient.isJsonMime("application/xml")); + assertFalse(apiClient.isJsonMime("application/jsonp")); + assertFalse(apiClient.isJsonMime("example/json")); + assertFalse(apiClient.isJsonMime("example/foo+bar+jsonx")); + assertFalse(apiClient.isJsonMime("example/foo+bar+xjson")); + + assertTrue(apiClient.isJsonMime("application/json")); + assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); + assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + + assertTrue(apiClient.isJsonMime("application/json\t")); + assertTrue(apiClient.isJsonMime("example/foo+bar+json")); + assertTrue(apiClient.isJsonMime("example/foo+json;x;y")); + assertTrue(apiClient.isJsonMime("example/foo+json\t;")); + assertTrue(apiClient.isJsonMime("Example/fOO+JSON")); } @Test diff --git a/samples/client/petstore/java/jersey2-java8/src/test/java/io/swagger/client/ApiClientTest.java b/samples/client/petstore/java/jersey2-java8/src/test/java/io/swagger/client/ApiClientTest.java index 19b55257d0c..eb1bd1164ff 100644 --- a/samples/client/petstore/java/jersey2-java8/src/test/java/io/swagger/client/ApiClientTest.java +++ b/samples/client/petstore/java/jersey2-java8/src/test/java/io/swagger/client/ApiClientTest.java @@ -40,15 +40,24 @@ public void testParseAndFormatDate() { @Test public void testIsJsonMime() { - assertFalse(apiClient.isJsonMime(null)); - assertFalse(apiClient.isJsonMime("")); - assertFalse(apiClient.isJsonMime("text/plain")); - assertFalse(apiClient.isJsonMime("application/xml")); - assertFalse(apiClient.isJsonMime("application/jsonp")); - - assertTrue(apiClient.isJsonMime("application/json")); - assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); - assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + assertFalse(apiClient.isJsonMime(null)); + assertFalse(apiClient.isJsonMime("")); + assertFalse(apiClient.isJsonMime("text/plain")); + assertFalse(apiClient.isJsonMime("application/xml")); + assertFalse(apiClient.isJsonMime("application/jsonp")); + assertFalse(apiClient.isJsonMime("example/json")); + assertFalse(apiClient.isJsonMime("example/foo+bar+jsonx")); + assertFalse(apiClient.isJsonMime("example/foo+bar+xjson")); + + assertTrue(apiClient.isJsonMime("application/json")); + assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); + assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + + assertTrue(apiClient.isJsonMime("application/json\t")); + assertTrue(apiClient.isJsonMime("example/foo+bar+json")); + assertTrue(apiClient.isJsonMime("example/foo+json;x;y")); + assertTrue(apiClient.isJsonMime("example/foo+json\t;")); + assertTrue(apiClient.isJsonMime("Example/fOO+JSON")); } @Test diff --git a/samples/client/petstore/java/jersey2/src/test/java/io/swagger/client/ApiClientTest.java b/samples/client/petstore/java/jersey2/src/test/java/io/swagger/client/ApiClientTest.java index 19b55257d0c..eb1bd1164ff 100644 --- a/samples/client/petstore/java/jersey2/src/test/java/io/swagger/client/ApiClientTest.java +++ b/samples/client/petstore/java/jersey2/src/test/java/io/swagger/client/ApiClientTest.java @@ -40,15 +40,24 @@ public void testParseAndFormatDate() { @Test public void testIsJsonMime() { - assertFalse(apiClient.isJsonMime(null)); - assertFalse(apiClient.isJsonMime("")); - assertFalse(apiClient.isJsonMime("text/plain")); - assertFalse(apiClient.isJsonMime("application/xml")); - assertFalse(apiClient.isJsonMime("application/jsonp")); - - assertTrue(apiClient.isJsonMime("application/json")); - assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); - assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + assertFalse(apiClient.isJsonMime(null)); + assertFalse(apiClient.isJsonMime("")); + assertFalse(apiClient.isJsonMime("text/plain")); + assertFalse(apiClient.isJsonMime("application/xml")); + assertFalse(apiClient.isJsonMime("application/jsonp")); + assertFalse(apiClient.isJsonMime("example/json")); + assertFalse(apiClient.isJsonMime("example/foo+bar+jsonx")); + assertFalse(apiClient.isJsonMime("example/foo+bar+xjson")); + + assertTrue(apiClient.isJsonMime("application/json")); + assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); + assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + + assertTrue(apiClient.isJsonMime("application/json\t")); + assertTrue(apiClient.isJsonMime("example/foo+bar+json")); + assertTrue(apiClient.isJsonMime("example/foo+json;x;y")); + assertTrue(apiClient.isJsonMime("example/foo+json\t;")); + assertTrue(apiClient.isJsonMime("Example/fOO+JSON")); } @Test diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java index bc13f2113d7..29dffb29534 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -727,12 +727,13 @@ public String sanitizeFilename(String filename) { * application/json * application/json; charset=UTF8 * APPLICATION/JSON - * - * @param mime MIME (Multipurpose Internet Mail Extensions) - * @return True if the given MIME is JSON, false otherwise. + * application/vnd.company+json + * @param mime MIME + * @return True if MIME type is boolean */ 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); } /** diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java index 5345e2a1646..77ee5d87d3e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java @@ -79,15 +79,24 @@ public void testParseAndFormatDate() { @Test public void testIsJsonMime() { - assertFalse(apiClient.isJsonMime(null)); - assertFalse(apiClient.isJsonMime("")); - assertFalse(apiClient.isJsonMime("text/plain")); - assertFalse(apiClient.isJsonMime("application/xml")); - assertFalse(apiClient.isJsonMime("application/jsonp")); - - assertTrue(apiClient.isJsonMime("application/json")); - assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); - assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + assertFalse(apiClient.isJsonMime(null)); + assertFalse(apiClient.isJsonMime("")); + assertFalse(apiClient.isJsonMime("text/plain")); + assertFalse(apiClient.isJsonMime("application/xml")); + assertFalse(apiClient.isJsonMime("application/jsonp")); + assertFalse(apiClient.isJsonMime("example/json")); + assertFalse(apiClient.isJsonMime("example/foo+bar+jsonx")); + assertFalse(apiClient.isJsonMime("example/foo+bar+xjson")); + + assertTrue(apiClient.isJsonMime("application/json")); + assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); + assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + + assertTrue(apiClient.isJsonMime("application/json\t")); + assertTrue(apiClient.isJsonMime("example/foo+bar+json")); + assertTrue(apiClient.isJsonMime("example/foo+json;x;y")); + assertTrue(apiClient.isJsonMime("example/foo+json\t;")); + assertTrue(apiClient.isJsonMime("Example/fOO+JSON")); } @Test From 02639bd1efd822ab3ed141037ad0c8ff1dfdceb2 Mon Sep 17 00:00:00 2001 From: David Harrigan Date: Fri, 24 Mar 2017 11:58:55 -0400 Subject: [PATCH 2/6] Revert unnecessary diffs --- .../main/resources/Java/libraries/jersey2/ApiClient.mustache | 2 +- .../resources/Java/libraries/okhttp-gson/ApiClient.mustache | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index 7dc53e8abc5..d44d724454e 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -438,7 +438,7 @@ public class ApiClient { * APPLICATION/JSON * application/vnd.company+json * @param mime MIME - * @return True if MIME type is boolean + * @return True if the MIME type is JSON */ public boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache index 659516358c7..537179fd079 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache @@ -721,8 +721,8 @@ public class ApiClient { * application/json; charset=UTF8 * APPLICATION/JSON * application/vnd.company+json - * @param mime MIME - * @return True if MIME type is boolean + * @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]*(;.*)?$"; From f3367630348f5e81847caaecd5e5cc890b6d7054 Mon Sep 17 00:00:00 2001 From: David Harrigan Date: Fri, 24 Mar 2017 11:59:52 -0400 Subject: [PATCH 3/6] Update petstore sample --- .../java/okhttp-gson/pom.xml | 63 +++- .../java/io/swagger/client/ApiClient.java | 6 +- .../client/GzipRequestInterceptor.java | 81 +++++ .../java/io/swagger/client/api/FakeApi.java | 319 +++++++++--------- .../io/swagger/client/model/ModelReturn.java | 2 +- .../java/io/swagger/client/ApiClient.java | 4 +- 6 files changed, 311 insertions(+), 164 deletions(-) create mode 100644 samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/GzipRequestInterceptor.java diff --git a/samples/client/petstore-security-test/java/okhttp-gson/pom.xml b/samples/client/petstore-security-test/java/okhttp-gson/pom.xml index be07768b92e..9ab87a8691c 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/pom.xml +++ b/samples/client/petstore-security-test/java/okhttp-gson/pom.xml @@ -6,8 +6,10 @@ jar swagger-petstore-okhttp-gson 1.0.0 + https://github.com/swagger-api/swagger-codegen + Swagger Java - scm:git:git@github.com:swagger-api/swagger-mustache.git + scm:git:git@github.com:swagger-api/swagger-codegen.git scm:git:git@github.com:swagger-api/swagger-codegen.git https://github.com/swagger-api/swagger-codegen @@ -22,7 +24,16 @@ repo - + + + + Swagger + apiteam@swagger.io + Swagger + http://swagger.io + + + @@ -108,9 +119,55 @@ org.apache.maven.plugins maven-javadoc-plugin 2.10.4 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + sign-artifacts + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + + + + io.swagger @@ -149,7 +206,7 @@ 1.7 ${java.version} ${java.version} - 1.5.9 + 1.5.12 2.7.5 2.6.2 2.9.3 diff --git a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java index 6a443dd2a9f..fcc2693df50 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -139,6 +139,7 @@ public class ApiClient { public ApiClient() { httpClient = new OkHttpClient(); + verifyingSsl = true; json = new JSON(this); @@ -725,12 +726,13 @@ public String sanitizeFilename(String filename) { * 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); } /** diff --git a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/GzipRequestInterceptor.java b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/GzipRequestInterceptor.java new file mode 100644 index 00000000000..179abb3a540 --- /dev/null +++ b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/GzipRequestInterceptor.java @@ -0,0 +1,81 @@ +/* + * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- + * + * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +package io.swagger.client; + +import com.squareup.okhttp.*; +import okio.Buffer; +import okio.BufferedSink; +import okio.GzipSink; +import okio.Okio; + +import java.io.IOException; + +/** + * Encodes request bodies using gzip. + * + * Taken from https://github.com/square/okhttp/issues/350 + */ +class GzipRequestInterceptor implements Interceptor { + @Override public Response intercept(Chain chain) throws IOException { + Request originalRequest = chain.request(); + if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) { + return chain.proceed(originalRequest); + } + + Request compressedRequest = originalRequest.newBuilder() + .header("Content-Encoding", "gzip") + .method(originalRequest.method(), forceContentLength(gzip(originalRequest.body()))) + .build(); + return chain.proceed(compressedRequest); + } + + private RequestBody forceContentLength(final RequestBody requestBody) throws IOException { + final Buffer buffer = new Buffer(); + requestBody.writeTo(buffer); + return new RequestBody() { + @Override + public MediaType contentType() { + return requestBody.contentType(); + } + + @Override + public long contentLength() { + return buffer.size(); + } + + @Override + public void writeTo(BufferedSink sink) throws IOException { + sink.write(buffer.snapshot()); + } + }; + } + + private RequestBody gzip(final RequestBody body) { + return new RequestBody() { + @Override public MediaType contentType() { + return body.contentType(); + } + + @Override public long contentLength() { + return -1; // We don't know the compressed length in advance! + } + + @Override public void writeTo(BufferedSink sink) throws IOException { + BufferedSink gzipSink = Okio.buffer(new GzipSink(sink)); + body.writeTo(gzipSink); + gzipSink.close(); + } + }; + } +} \ No newline at end of file diff --git a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java index 8a4e08dc244..40a7942e682 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java @@ -9,159 +9,166 @@ * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ - - -package io.swagger.client.api; - -import io.swagger.client.ApiCallback; -import io.swagger.client.ApiClient; -import io.swagger.client.ApiException; -import io.swagger.client.ApiResponse; -import io.swagger.client.Configuration; -import io.swagger.client.Pair; -import io.swagger.client.ProgressRequestBody; -import io.swagger.client.ProgressResponseBody; - -import com.google.gson.reflect.TypeToken; - -import java.io.IOException; - - - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class FakeApi { - private ApiClient apiClient; - - public FakeApi() { - this(Configuration.getDefaultApiClient()); - } - - public FakeApi(ApiClient apiClient) { - this.apiClient = apiClient; - } - - public ApiClient getApiClient() { - return apiClient; - } - - public void setApiClient(ApiClient apiClient) { - this.apiClient = apiClient; - } - - /* Build call for testCodeInjectEndRnNR */ - private com.squareup.okhttp.Call testCodeInjectEndRnNRCall(String testCodeInjectEndRnNR, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/fake".replaceAll("\\{format\\}","json"); - - List localVarQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - if (testCodeInjectEndRnNR != null) - localVarFormParams.put("test code inject */ ' " =end -- \r\n \n \r", testCodeInjectEndRnNR); - - final String[] localVarAccepts = { - "application/json", "*_/ ' =end -- " - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json", "*_/ ' =end -- " - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { }; - return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call testCodeInjectEndRnNRValidateBeforeCall(String testCodeInjectEndRnNR, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - - com.squareup.okhttp.Call call = testCodeInjectEndRnNRCall(testCodeInjectEndRnNR, progressListener, progressRequestListener); - return call; - - - - - - } - - /** - * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r - * - * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public void testCodeInjectEndRnNR(String testCodeInjectEndRnNR) throws ApiException { - testCodeInjectEndRnNRWithHttpInfo(testCodeInjectEndRnNR); - } - - /** - * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r - * - * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) - * @return ApiResponse<Void> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse testCodeInjectEndRnNRWithHttpInfo(String testCodeInjectEndRnNR) throws ApiException { - com.squareup.okhttp.Call call = testCodeInjectEndRnNRValidateBeforeCall(testCodeInjectEndRnNR, null, null); - return apiClient.execute(call); - } - - /** - * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (asynchronously) - * - * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call testCodeInjectEndRnNRAsync(String testCodeInjectEndRnNR, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = testCodeInjectEndRnNRValidateBeforeCall(testCodeInjectEndRnNR, progressListener, progressRequestListener); - apiClient.executeAsync(call, callback); - return call; - } -} + + +package io.swagger.client.api; + +import io.swagger.client.ApiCallback; +import io.swagger.client.ApiClient; +import io.swagger.client.ApiException; +import io.swagger.client.ApiResponse; +import io.swagger.client.Configuration; +import io.swagger.client.Pair; +import io.swagger.client.ProgressRequestBody; +import io.swagger.client.ProgressResponseBody; + +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; + + + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class FakeApi { + private ApiClient apiClient; + + public FakeApi() { + this(Configuration.getDefaultApiClient()); + } + + public FakeApi(ApiClient apiClient) { + this.apiClient = apiClient; + } + + public ApiClient getApiClient() { + return apiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.apiClient = apiClient; + } + + /** + * Build call for testCodeInjectEndRnNR + * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) + * @param progressListener Progress listener + * @param progressRequestListener Progress request listener + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + */ + public com.squareup.okhttp.Call testCodeInjectEndRnNRCall(String testCodeInjectEndRnNR, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/fake"; + + List localVarQueryParams = new ArrayList(); + + Map localVarHeaderParams = new HashMap(); + + Map localVarFormParams = new HashMap(); + if (testCodeInjectEndRnNR != null) + localVarFormParams.put("test code inject */ ' " =end -- \r\n \n \r", testCodeInjectEndRnNR); + + final String[] localVarAccepts = { + "application/json", "*_/ ' =end -- " + }; + final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); + + final String[] localVarContentTypes = { + "application/json", "*_/ ' =end -- " + }; + final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); + localVarHeaderParams.put("Content-Type", localVarContentType); + + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { + @Override + public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { + com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + + String[] localVarAuthNames = new String[] { }; + return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); + } + + @SuppressWarnings("rawtypes") + private com.squareup.okhttp.Call testCodeInjectEndRnNRValidateBeforeCall(String testCodeInjectEndRnNR, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + + + com.squareup.okhttp.Call call = testCodeInjectEndRnNRCall(testCodeInjectEndRnNR, progressListener, progressRequestListener); + return call; + + + + + + } + + /** + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * + * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public void testCodeInjectEndRnNR(String testCodeInjectEndRnNR) throws ApiException { + testCodeInjectEndRnNRWithHttpInfo(testCodeInjectEndRnNR); + } + + /** + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * + * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) + * @return ApiResponse<Void> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse testCodeInjectEndRnNRWithHttpInfo(String testCodeInjectEndRnNR) throws ApiException { + com.squareup.okhttp.Call call = testCodeInjectEndRnNRValidateBeforeCall(testCodeInjectEndRnNR, null, null); + return apiClient.execute(call); + } + + /** + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (asynchronously) + * + * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + */ + public com.squareup.okhttp.Call testCodeInjectEndRnNRAsync(String testCodeInjectEndRnNR, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if (callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + com.squareup.okhttp.Call call = testCodeInjectEndRnNRValidateBeforeCall(testCodeInjectEndRnNR, progressListener, progressRequestListener); + apiClient.executeAsync(call, callback); + return call; + } +} diff --git a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/model/ModelReturn.java b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/model/ModelReturn.java index 7e26fef904c..55a24114ddd 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/model/ModelReturn.java +++ b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/model/ModelReturn.java @@ -36,7 +36,7 @@ public ModelReturn _return(Integer _return) { * property description *_/ ' \" =end -- \\r\\n \\n \\r * @return _return **/ - @ApiModelProperty(example = "null", value = "property description *_/ ' \" =end -- \\r\\n \\n \\r") + @ApiModelProperty(value = "property description *_/ ' \" =end -- \\r\\n \\n \\r") public Integer getReturn() { return _return; } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java index 29dffb29534..665a697cfa8 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -728,8 +728,8 @@ public String sanitizeFilename(String filename) { * application/json; charset=UTF8 * APPLICATION/JSON * application/vnd.company+json - * @param mime MIME - * @return True if MIME type is boolean + * @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]*(;.*)?$"; From dfbd661976f5b4234b8564c539cf438b7331410f Mon Sep 17 00:00:00 2001 From: David Harrigan Date: Mon, 27 Mar 2017 20:03:46 -0400 Subject: [PATCH 4/6] Didn't run mvn after some edits --- .../src/main/java/io/swagger/client/ApiClient.java | 4 +++- samples/client/petstore/java/jersey2/hello.txt | 1 + .../jersey2/src/main/java/io/swagger/client/ApiClient.java | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 samples/client/petstore/java/jersey2/hello.txt diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java index 3e2dab9ee91..236e46f2a37 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java @@ -431,11 +431,13 @@ public List parameterToPairs(String collectionFormat, String name, Object * application/json * application/json; charset=UTF8 * APPLICATION/JSON + * application/vnd.company+json * @param mime MIME * @return True if the MIME type is JSON */ 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); } /** diff --git a/samples/client/petstore/java/jersey2/hello.txt b/samples/client/petstore/java/jersey2/hello.txt new file mode 100644 index 00000000000..6769dd60bdf --- /dev/null +++ b/samples/client/petstore/java/jersey2/hello.txt @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java index 3e2dab9ee91..236e46f2a37 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java @@ -431,11 +431,13 @@ public List parameterToPairs(String collectionFormat, String name, Object * application/json * application/json; charset=UTF8 * APPLICATION/JSON + * application/vnd.company+json * @param mime MIME * @return True if the MIME type is JSON */ 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); } /** From 49e73a245da6e29ede6ccd7f0c10fbda8942b658 Mon Sep 17 00:00:00 2001 From: David Harrigan Date: Wed, 29 Mar 2017 13:03:56 -0400 Subject: [PATCH 5/6] Rerun ' ./bin/java-petstore-all.sh' and './bin/security/java-petstore-okhttp-gson.sh' --- .../feign/src/main/java/io/swagger/client/ApiClient.java | 2 +- samples/client/petstore/java/jersey1/docs/FakeApi.md | 2 +- samples/client/petstore/java/jersey1/docs/PetApi.md | 2 +- samples/client/petstore/java/jersey1/docs/StoreApi.md | 2 +- samples/client/petstore/java/jersey1/docs/UserApi.md | 2 +- .../jersey1/src/main/java/io/swagger/client/ApiClient.java | 2 +- samples/client/petstore/java/jersey2-java6/docs/FakeApi.md | 2 +- samples/client/petstore/java/jersey2-java6/docs/PetApi.md | 2 +- samples/client/petstore/java/jersey2-java6/docs/StoreApi.md | 2 +- samples/client/petstore/java/jersey2-java6/docs/UserApi.md | 2 +- .../src/main/java/io/swagger/client/ApiClient.java | 6 ++++-- samples/client/petstore/java/jersey2-java8/docs/FakeApi.md | 2 +- samples/client/petstore/java/jersey2-java8/docs/PetApi.md | 2 +- samples/client/petstore/java/jersey2-java8/docs/StoreApi.md | 2 +- samples/client/petstore/java/jersey2-java8/docs/UserApi.md | 2 +- .../src/main/java/io/swagger/client/ApiClient.java | 2 +- samples/client/petstore/java/jersey2/docs/FakeApi.md | 2 +- samples/client/petstore/java/jersey2/docs/PetApi.md | 2 +- samples/client/petstore/java/jersey2/docs/StoreApi.md | 2 +- samples/client/petstore/java/jersey2/docs/UserApi.md | 2 +- samples/client/petstore/java/jersey2/hello.txt | 1 - .../jersey2/src/main/java/io/swagger/client/ApiClient.java | 2 +- samples/client/petstore/java/okhttp-gson/docs/FakeApi.md | 2 +- samples/client/petstore/java/okhttp-gson/docs/PetApi.md | 2 +- samples/client/petstore/java/okhttp-gson/docs/StoreApi.md | 2 +- samples/client/petstore/java/okhttp-gson/docs/UserApi.md | 2 +- .../src/main/java/io/swagger/client/ApiClient.java | 4 ++-- .../retrofit/src/main/java/io/swagger/client/ApiClient.java | 2 +- 28 files changed, 31 insertions(+), 30 deletions(-) delete mode 100644 samples/client/petstore/java/jersey2/hello.txt diff --git a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java index 51483828c52..53341e3d771 100644 --- a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java @@ -25,7 +25,7 @@ public class ApiClient { public interface Api {} protected ObjectMapper objectMapper; - private String basePath = "http://petstore.swagger.io/v2"; + private String basePath = "http://petstore.swagger.io:80/v2"; private Map apiAuthorizations; private Feign.Builder feignBuilder; diff --git a/samples/client/petstore/java/jersey1/docs/FakeApi.md b/samples/client/petstore/java/jersey1/docs/FakeApi.md index 4deb6e1d851..f4a6d1c0eb3 100644 --- a/samples/client/petstore/java/jersey1/docs/FakeApi.md +++ b/samples/client/petstore/java/jersey1/docs/FakeApi.md @@ -1,6 +1,6 @@ # FakeApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey1/docs/PetApi.md b/samples/client/petstore/java/jersey1/docs/PetApi.md index 3b5f84043e3..b5fa395947d 100644 --- a/samples/client/petstore/java/jersey1/docs/PetApi.md +++ b/samples/client/petstore/java/jersey1/docs/PetApi.md @@ -1,6 +1,6 @@ # PetApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey1/docs/StoreApi.md b/samples/client/petstore/java/jersey1/docs/StoreApi.md index 0b30791725a..a2547a1483e 100644 --- a/samples/client/petstore/java/jersey1/docs/StoreApi.md +++ b/samples/client/petstore/java/jersey1/docs/StoreApi.md @@ -1,6 +1,6 @@ # StoreApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey1/docs/UserApi.md b/samples/client/petstore/java/jersey1/docs/UserApi.md index 8cdc15992ee..2e6987951c8 100644 --- a/samples/client/petstore/java/jersey1/docs/UserApi.md +++ b/samples/client/petstore/java/jersey1/docs/UserApi.md @@ -1,6 +1,6 @@ # UserApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java index b9a6fbba9b0..8307cdf5ffc 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java @@ -56,7 +56,7 @@ public class ApiClient { private Map defaultHeaderMap = new HashMap(); - private String basePath = "http://petstore.swagger.io/v2"; + private String basePath = "http://petstore.swagger.io:80/v2"; private boolean debugging = false; private int connectionTimeout = 0; diff --git a/samples/client/petstore/java/jersey2-java6/docs/FakeApi.md b/samples/client/petstore/java/jersey2-java6/docs/FakeApi.md index 4deb6e1d851..f4a6d1c0eb3 100644 --- a/samples/client/petstore/java/jersey2-java6/docs/FakeApi.md +++ b/samples/client/petstore/java/jersey2-java6/docs/FakeApi.md @@ -1,6 +1,6 @@ # FakeApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2-java6/docs/PetApi.md b/samples/client/petstore/java/jersey2-java6/docs/PetApi.md index 3b5f84043e3..b5fa395947d 100644 --- a/samples/client/petstore/java/jersey2-java6/docs/PetApi.md +++ b/samples/client/petstore/java/jersey2-java6/docs/PetApi.md @@ -1,6 +1,6 @@ # PetApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2-java6/docs/StoreApi.md b/samples/client/petstore/java/jersey2-java6/docs/StoreApi.md index 0b30791725a..a2547a1483e 100644 --- a/samples/client/petstore/java/jersey2-java6/docs/StoreApi.md +++ b/samples/client/petstore/java/jersey2-java6/docs/StoreApi.md @@ -1,6 +1,6 @@ # StoreApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2-java6/docs/UserApi.md b/samples/client/petstore/java/jersey2-java6/docs/UserApi.md index 8cdc15992ee..2e6987951c8 100644 --- a/samples/client/petstore/java/jersey2-java6/docs/UserApi.md +++ b/samples/client/petstore/java/jersey2-java6/docs/UserApi.md @@ -1,6 +1,6 @@ # UserApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiClient.java index 999d343919d..31c5d60d626 100644 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiClient.java @@ -51,7 +51,7 @@ public class ApiClient { private Map defaultHeaderMap = new HashMap(); - private String basePath = "http://petstore.swagger.io/v2"; + private String basePath = "http://petstore.swagger.io:80/v2"; private boolean debugging = false; private int connectionTimeout = 0; @@ -431,11 +431,13 @@ public List parameterToPairs(String collectionFormat, String name, Object * application/json * application/json; charset=UTF8 * APPLICATION/JSON + * application/vnd.company+json * @param mime MIME * @return True if the MIME type is JSON */ 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); } /** diff --git a/samples/client/petstore/java/jersey2-java8/docs/FakeApi.md b/samples/client/petstore/java/jersey2-java8/docs/FakeApi.md index 0e370b3862f..01dcb19a054 100644 --- a/samples/client/petstore/java/jersey2-java8/docs/FakeApi.md +++ b/samples/client/petstore/java/jersey2-java8/docs/FakeApi.md @@ -1,6 +1,6 @@ # FakeApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2-java8/docs/PetApi.md b/samples/client/petstore/java/jersey2-java8/docs/PetApi.md index 3b5f84043e3..b5fa395947d 100644 --- a/samples/client/petstore/java/jersey2-java8/docs/PetApi.md +++ b/samples/client/petstore/java/jersey2-java8/docs/PetApi.md @@ -1,6 +1,6 @@ # PetApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2-java8/docs/StoreApi.md b/samples/client/petstore/java/jersey2-java8/docs/StoreApi.md index 0b30791725a..a2547a1483e 100644 --- a/samples/client/petstore/java/jersey2-java8/docs/StoreApi.md +++ b/samples/client/petstore/java/jersey2-java8/docs/StoreApi.md @@ -1,6 +1,6 @@ # StoreApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2-java8/docs/UserApi.md b/samples/client/petstore/java/jersey2-java8/docs/UserApi.md index 8cdc15992ee..2e6987951c8 100644 --- a/samples/client/petstore/java/jersey2-java8/docs/UserApi.md +++ b/samples/client/petstore/java/jersey2-java8/docs/UserApi.md @@ -1,6 +1,6 @@ # UserApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java index 236e46f2a37..2878363c980 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java @@ -51,7 +51,7 @@ public class ApiClient { private Map defaultHeaderMap = new HashMap(); - private String basePath = "http://petstore.swagger.io/v2"; + private String basePath = "http://petstore.swagger.io:80/v2"; private boolean debugging = false; private int connectionTimeout = 0; diff --git a/samples/client/petstore/java/jersey2/docs/FakeApi.md b/samples/client/petstore/java/jersey2/docs/FakeApi.md index 4deb6e1d851..f4a6d1c0eb3 100644 --- a/samples/client/petstore/java/jersey2/docs/FakeApi.md +++ b/samples/client/petstore/java/jersey2/docs/FakeApi.md @@ -1,6 +1,6 @@ # FakeApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2/docs/PetApi.md b/samples/client/petstore/java/jersey2/docs/PetApi.md index 3b5f84043e3..b5fa395947d 100644 --- a/samples/client/petstore/java/jersey2/docs/PetApi.md +++ b/samples/client/petstore/java/jersey2/docs/PetApi.md @@ -1,6 +1,6 @@ # PetApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2/docs/StoreApi.md b/samples/client/petstore/java/jersey2/docs/StoreApi.md index 0b30791725a..a2547a1483e 100644 --- a/samples/client/petstore/java/jersey2/docs/StoreApi.md +++ b/samples/client/petstore/java/jersey2/docs/StoreApi.md @@ -1,6 +1,6 @@ # StoreApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2/docs/UserApi.md b/samples/client/petstore/java/jersey2/docs/UserApi.md index 8cdc15992ee..2e6987951c8 100644 --- a/samples/client/petstore/java/jersey2/docs/UserApi.md +++ b/samples/client/petstore/java/jersey2/docs/UserApi.md @@ -1,6 +1,6 @@ # UserApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/jersey2/hello.txt b/samples/client/petstore/java/jersey2/hello.txt deleted file mode 100644 index 6769dd60bdf..00000000000 --- a/samples/client/petstore/java/jersey2/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello world! \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java index 236e46f2a37..2878363c980 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java @@ -51,7 +51,7 @@ public class ApiClient { private Map defaultHeaderMap = new HashMap(); - private String basePath = "http://petstore.swagger.io/v2"; + private String basePath = "http://petstore.swagger.io:80/v2"; private boolean debugging = false; private int connectionTimeout = 0; diff --git a/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md b/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md index 4deb6e1d851..f4a6d1c0eb3 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md +++ b/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md @@ -1,6 +1,6 @@ # FakeApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/okhttp-gson/docs/PetApi.md b/samples/client/petstore/java/okhttp-gson/docs/PetApi.md index 3b5f84043e3..b5fa395947d 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/PetApi.md +++ b/samples/client/petstore/java/okhttp-gson/docs/PetApi.md @@ -1,6 +1,6 @@ # PetApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/okhttp-gson/docs/StoreApi.md b/samples/client/petstore/java/okhttp-gson/docs/StoreApi.md index 0b30791725a..a2547a1483e 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/StoreApi.md +++ b/samples/client/petstore/java/okhttp-gson/docs/StoreApi.md @@ -1,6 +1,6 @@ # StoreApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/okhttp-gson/docs/UserApi.md b/samples/client/petstore/java/okhttp-gson/docs/UserApi.md index 8cdc15992ee..2e6987951c8 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/UserApi.md +++ b/samples/client/petstore/java/okhttp-gson/docs/UserApi.md @@ -1,6 +1,6 @@ # UserApi -All URIs are relative to *http://petstore.swagger.io/v2* +All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java index 665a697cfa8..c39625501fc 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -112,7 +112,7 @@ public class ApiClient { */ public static final String LENIENT_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; - private String basePath = "http://petstore.swagger.io/v2"; + private String basePath = "http://petstore.swagger.io:80/v2"; private boolean lenientOnJson = false; private boolean debugging = false; private Map defaultHeaderMap = new HashMap(); @@ -181,7 +181,7 @@ public String getBasePath() { /** * Set base path * - * @param basePath Base path of the URL (e.g http://petstore.swagger.io/v2 + * @param basePath Base path of the URL (e.g http://petstore.swagger.io:80/v2 * @return An instance of OkHttpClient */ public ApiClient setBasePath(String basePath) { diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java index 250c8f9550a..5cb5a55060c 100644 --- a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java @@ -126,7 +126,7 @@ public void createDefaultAdapter() { adapterBuilder = new RestAdapter .Builder() - .setEndpoint("http://petstore.swagger.io/v2") + .setEndpoint("http://petstore.swagger.io:80/v2") .setClient(new OkClient(okClient)) .setConverter(new GsonConverterWrapper(gson)); } From 3e8121124ce749c6a75698717cf14a72545c4144 Mon Sep 17 00:00:00 2001 From: David Harrigan Date: Wed, 29 Mar 2017 14:15:41 -0400 Subject: [PATCH 6/6] Added more realistic test cases for isJsonMime --- .../jersey1/src/test/java/io/swagger/client/ApiClientTest.java | 2 ++ .../src/test/java/io/swagger/client/ApiClientTest.java | 2 ++ .../jersey2/src/test/java/io/swagger/client/ApiClientTest.java | 2 ++ .../src/test/java/io/swagger/client/ApiClientTest.java | 2 ++ 4 files changed, 8 insertions(+) diff --git a/samples/client/petstore/java/jersey1/src/test/java/io/swagger/client/ApiClientTest.java b/samples/client/petstore/java/jersey1/src/test/java/io/swagger/client/ApiClientTest.java index eb1bd1164ff..c8824547303 100644 --- a/samples/client/petstore/java/jersey1/src/test/java/io/swagger/client/ApiClientTest.java +++ b/samples/client/petstore/java/jersey1/src/test/java/io/swagger/client/ApiClientTest.java @@ -53,6 +53,8 @@ public void testIsJsonMime() { assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + assertTrue(apiClient.isJsonMime("application/problem+json")); + assertTrue(apiClient.isJsonMime("APPLICATION/PROBLEM+JSON")); assertTrue(apiClient.isJsonMime("application/json\t")); assertTrue(apiClient.isJsonMime("example/foo+bar+json")); assertTrue(apiClient.isJsonMime("example/foo+json;x;y")); diff --git a/samples/client/petstore/java/jersey2-java8/src/test/java/io/swagger/client/ApiClientTest.java b/samples/client/petstore/java/jersey2-java8/src/test/java/io/swagger/client/ApiClientTest.java index eb1bd1164ff..c8824547303 100644 --- a/samples/client/petstore/java/jersey2-java8/src/test/java/io/swagger/client/ApiClientTest.java +++ b/samples/client/petstore/java/jersey2-java8/src/test/java/io/swagger/client/ApiClientTest.java @@ -53,6 +53,8 @@ public void testIsJsonMime() { assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + assertTrue(apiClient.isJsonMime("application/problem+json")); + assertTrue(apiClient.isJsonMime("APPLICATION/PROBLEM+JSON")); assertTrue(apiClient.isJsonMime("application/json\t")); assertTrue(apiClient.isJsonMime("example/foo+bar+json")); assertTrue(apiClient.isJsonMime("example/foo+json;x;y")); diff --git a/samples/client/petstore/java/jersey2/src/test/java/io/swagger/client/ApiClientTest.java b/samples/client/petstore/java/jersey2/src/test/java/io/swagger/client/ApiClientTest.java index eb1bd1164ff..c8824547303 100644 --- a/samples/client/petstore/java/jersey2/src/test/java/io/swagger/client/ApiClientTest.java +++ b/samples/client/petstore/java/jersey2/src/test/java/io/swagger/client/ApiClientTest.java @@ -53,6 +53,8 @@ public void testIsJsonMime() { assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + assertTrue(apiClient.isJsonMime("application/problem+json")); + assertTrue(apiClient.isJsonMime("APPLICATION/PROBLEM+JSON")); assertTrue(apiClient.isJsonMime("application/json\t")); assertTrue(apiClient.isJsonMime("example/foo+bar+json")); assertTrue(apiClient.isJsonMime("example/foo+json;x;y")); diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java index 77ee5d87d3e..bec38b44d98 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/ApiClientTest.java @@ -92,6 +92,8 @@ public void testIsJsonMime() { assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + assertTrue(apiClient.isJsonMime("application/problem+json")); + assertTrue(apiClient.isJsonMime("APPLICATION/PROBLEM+JSON")); assertTrue(apiClient.isJsonMime("application/json\t")); assertTrue(apiClient.isJsonMime("example/foo+bar+json")); assertTrue(apiClient.isJsonMime("example/foo+json;x;y"));