From 66948e6570446eb71933cb6ae6ed7184f23d950c Mon Sep 17 00:00:00 2001 From: Slavek Kabrda Date: Sun, 17 May 2020 17:44:54 +0200 Subject: [PATCH] [Java][jersey2] Allow setting serverIndex to null (#6321) --- .../resources/Java/libraries/jersey2/ApiClient.mustache | 6 ++++-- .../src/main/java/org/openapitools/client/ApiClient.java | 6 ++++-- .../src/main/java/org/openapitools/client/ApiClient.java | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index 87f6c5f1016..41db79fc8e5 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -251,7 +251,9 @@ public class ApiClient { } private void updateBasePath() { - setBasePath(servers.get(serverIndex).URL(serverVariables)); + if (serverIndex != null) { + setBasePath(servers.get(serverIndex).URL(serverVariables)); + } } {{#hasOAuthMethods}} @@ -1030,7 +1032,7 @@ public class ApiClient { // Not using `.target(targetURL).path(path)` below, // to support (constant) query string in `path`, e.g. "/posts?draft=1" String targetURL; - if (operationServers.containsKey(operation)) { + if (serverIndex != null && operationServers.containsKey(operation)) { Integer index = operationServerIndex.containsKey(operation) ? operationServerIndex.get(operation) : serverIndex; Map variables = operationServerVariables.containsKey(operation) ? operationServerVariables.get(operation) : serverVariables; diff --git a/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/ApiClient.java index 2da5dacd44d..36afb9066fb 100644 --- a/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/ApiClient.java @@ -168,7 +168,9 @@ public class ApiClient { } private void updateBasePath() { - setBasePath(servers.get(serverIndex).URL(serverVariables)); + if (serverIndex != null) { + setBasePath(servers.get(serverIndex).URL(serverVariables)); + } } private void setOauthBasePath(String basePath) { @@ -937,7 +939,7 @@ public class ApiClient { // Not using `.target(targetURL).path(path)` below, // to support (constant) query string in `path`, e.g. "/posts?draft=1" String targetURL; - if (operationServers.containsKey(operation)) { + if (serverIndex != null && operationServers.containsKey(operation)) { Integer index = operationServerIndex.containsKey(operation) ? operationServerIndex.get(operation) : serverIndex; Map variables = operationServerVariables.containsKey(operation) ? operationServerVariables.get(operation) : serverVariables; diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index 2da5dacd44d..36afb9066fb 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -168,7 +168,9 @@ public class ApiClient { } private void updateBasePath() { - setBasePath(servers.get(serverIndex).URL(serverVariables)); + if (serverIndex != null) { + setBasePath(servers.get(serverIndex).URL(serverVariables)); + } } private void setOauthBasePath(String basePath) { @@ -937,7 +939,7 @@ public class ApiClient { // Not using `.target(targetURL).path(path)` below, // to support (constant) query string in `path`, e.g. "/posts?draft=1" String targetURL; - if (operationServers.containsKey(operation)) { + if (serverIndex != null && operationServers.containsKey(operation)) { Integer index = operationServerIndex.containsKey(operation) ? operationServerIndex.get(operation) : serverIndex; Map variables = operationServerVariables.containsKey(operation) ? operationServerVariables.get(operation) : serverVariables;