From 16ac05dcdfb5023352813f20e81b95b0ef1a50d3 Mon Sep 17 00:00:00 2001 From: FlorianBruckner Date: Sun, 25 Aug 2019 12:02:36 +0200 Subject: [PATCH] Two tiny fixes for Java Vertx client (#3683) * two tiny fixes: 1.) ApiClient already defines and configures an objectMapper to not fail on unknown properties, but it is not used when parsing the response. The fix uses the pre-configured object mapper instead of the vertx default one 2.) When an operation has no response (or just ones without content), the accept array passed to ApiClient is emtpy. This makes the null check in ApiClient useless, as it still tries to set a null Accept header, which is refused with an NPE. Amend the check with .length > 0 to catch this case. * update generated client as required by contributor guidelines --- .../main/resources/Java/libraries/vertx/ApiClient.mustache | 4 ++-- .../src/main/java/org/openapitools/client/ApiClient.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache index 90f4cbcb33b..571a3e4e63f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache @@ -444,7 +444,7 @@ public class ApiClient { updateParamsForAuth(authNames, queryParams, headerParams); - if (accepts != null) { + if (accepts != null && accepts.length > 0) { headerParams.add(HttpHeaders.ACCEPT, selectHeaderAccept(accepts)); } @@ -579,7 +579,7 @@ public class ApiClient { return; } else { try { - resultContent = Json.mapper.readValue(httpResponse.bodyAsString(), returnType); + resultContent = this.objectMapper.readValue(httpResponse.bodyAsString(), returnType); result = Future.succeededFuture(resultContent); } catch (Exception e) { result = ApiException.fail(new DecodeException("Failed to decode:" + e.getMessage(), e)); diff --git a/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/ApiClient.java index 4555d9a142f..84bad01a4ed 100644 --- a/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/ApiClient.java @@ -440,7 +440,7 @@ public class ApiClient { updateParamsForAuth(authNames, queryParams, headerParams); - if (accepts != null) { + if (accepts != null && accepts.length > 0) { headerParams.add(HttpHeaders.ACCEPT, selectHeaderAccept(accepts)); } @@ -575,7 +575,7 @@ public class ApiClient { return; } else { try { - resultContent = Json.mapper.readValue(httpResponse.bodyAsString(), returnType); + resultContent = this.objectMapper.readValue(httpResponse.bodyAsString(), returnType); result = Future.succeededFuture(resultContent); } catch (Exception e) { result = ApiException.fail(new DecodeException("Failed to decode:" + e.getMessage(), e));