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;