Skip to content

Commit 16ac05d

Browse files
FlorianBrucknerwing328
authored andcommitted
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
1 parent 859df23 commit 16ac05d

File tree

2 files changed

+4
-4
lines changed
  • modules/openapi-generator/src/main/resources/Java/libraries/vertx
  • samples/client/petstore/java/vertx/src/main/java/org/openapitools/client

2 files changed

+4
-4
lines changed

modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ public class ApiClient {
444444
445445
updateParamsForAuth(authNames, queryParams, headerParams);
446446
447-
if (accepts != null) {
447+
if (accepts != null && accepts.length > 0) {
448448
headerParams.add(HttpHeaders.ACCEPT, selectHeaderAccept(accepts));
449449
}
450450

@@ -579,7 +579,7 @@ public class ApiClient {
579579
return;
580580
} else {
581581
try {
582-
resultContent = Json.mapper.readValue(httpResponse.bodyAsString(), returnType);
582+
resultContent = this.objectMapper.readValue(httpResponse.bodyAsString(), returnType);
583583
result = Future.succeededFuture(resultContent);
584584
} catch (Exception e) {
585585
result = ApiException.fail(new DecodeException("Failed to decode:" + e.getMessage(), e));

samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/ApiClient.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ public <T> void invokeAPI(String path, String method, List<Pair> queryParams, Ob
440440

441441
updateParamsForAuth(authNames, queryParams, headerParams);
442442

443-
if (accepts != null) {
443+
if (accepts != null && accepts.length > 0) {
444444
headerParams.add(HttpHeaders.ACCEPT, selectHeaderAccept(accepts));
445445
}
446446

@@ -575,7 +575,7 @@ protected <T> Handler<AsyncResult<HttpResponse<Buffer>>> buildResponseHandler(Ty
575575
return;
576576
} else {
577577
try {
578-
resultContent = Json.mapper.readValue(httpResponse.bodyAsString(), returnType);
578+
resultContent = this.objectMapper.readValue(httpResponse.bodyAsString(), returnType);
579579
result = Future.succeededFuture(resultContent);
580580
} catch (Exception e) {
581581
result = ApiException.fail(new DecodeException("Failed to decode:" + e.getMessage(), e));

0 commit comments

Comments
 (0)