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 4f79dddb9c6..9926c95ae1f 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 @@ -73,6 +73,12 @@ public class ApiClient { */ public ApiClient() { httpClient = new OkHttpClient(); + + {{#useGzipFeature}} + // Enable gzip request compression + httpClient.interceptors().add(new GzipRequestInterceptor()); + {{/useGzipFeature}} + verifyingSsl = true; json = new JSON(); @@ -835,6 +841,13 @@ public class ApiClient { if (returnType == null || response.code() == 204) { // returning null if the returnType is not defined, // or the status code is 204 (No Content) + if (response.body() != null) { + try { + response.body().close(); + } catch (IOException e) { + throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap()); + } + } return null; } else { return deserialize(response, returnType); diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache index f306525f6f4..5ee0a44b58b 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache @@ -132,7 +132,8 @@ public class JSON { */ public static class DateTimeTypeAdapter extends TypeAdapter { - private DateTimeFormatter formatter; + private final DateTimeFormatter parseFormatter = ISODateTimeFormat.dateOptionalTimeParser(); + private final DateTimeFormatter printFormatter = ISODateTimeFormat.dateTime(); public DateTimeTypeAdapter() { this(ISODateTimeFormat.dateTime().withOffsetParsed()); @@ -151,7 +152,7 @@ public class JSON { if (date == null) { out.nullValue(); } else { - out.value(formatter.print(date)); + out.value(printFormatter.print(date)); } } @@ -163,7 +164,7 @@ public class JSON { return null; default: String date = in.nextString(); - return formatter.parseDateTime(date); + return parseFormatter.parseDateTime(date); } } } 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 c960ab9195d..8410522b276 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 @@ -72,6 +72,8 @@ public class ApiClient { */ public ApiClient() { httpClient = new OkHttpClient(); + + verifyingSsl = true; json = new JSON(); @@ -820,6 +822,13 @@ public class ApiClient { if (returnType == null || response.code() == 204) { // returning null if the returnType is not defined, // or the status code is 204 (No Content) + if (response.body() != null) { + try { + response.body().close(); + } catch (IOException e) { + throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap()); + } + } return null; } else { return deserialize(response, returnType);