From b87c927fc26120c8a36ef44b063cb5ffad2f76a7 Mon Sep 17 00:00:00 2001 From: Sebastien Rosset Date: Thu, 28 May 2020 06:35:16 -0700 Subject: [PATCH] [Java][jersey2] Fix RuntimeException when HTTP signature parameters are not configured (#6457) * Mustache template should use invokerPackage tag to generate import * fix runtime exception when HttpSignatureAuth is not set * fix runtime exception when HttpSignatureAuth is not set --- .../Java/libraries/jersey2/ApiClient.mustache | 14 +++++++++++--- .../java/org/openapitools/client/ApiClient.java | 12 +++++++++++- 2 files changed, 22 insertions(+), 4 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 362aee07d75d..8d12c42630d1 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 @@ -200,8 +200,6 @@ public class ApiClient { {{#isHttpSignature}} if (auth instanceof HttpSignatureAuth) { authentications.put("{{name}}", auth); - } else { - authentications.put("{{name}}", null); } {{/isHttpSignature}} {{/isBasic}} @@ -246,10 +244,20 @@ public class ApiClient { return this; } + /** + * Returns the base URL to the location where the OpenAPI document is being served. + * + * @return The base URL to the target host. + */ public String getBasePath() { return basePath; } + /** + * Sets the base URL to the location where the OpenAPI document is being served. + * + * @param basePath The base URL to the target host. + */ public ApiClient setBasePath(String basePath) { this.basePath = basePath; {{#hasOAuthMethods}} @@ -1281,7 +1289,7 @@ public class ApiClient { for (String authName : authNames) { Authentication auth = authentications.get(authName); if (auth == null) { - throw new RuntimeException("Authentication undefined: " + authName); + continue; } auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } 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 a6405acc7842..a4ebc69f5678 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 @@ -167,10 +167,20 @@ public ApiClient setHttpClient(Client httpClient) { return this; } + /** + * Returns the base URL to the location where the OpenAPI document is being served. + * + * @return The base URL to the target host. + */ public String getBasePath() { return basePath; } + /** + * Sets the base URL to the location where the OpenAPI document is being served. + * + * @param basePath The base URL to the target host. + */ public ApiClient setBasePath(String basePath) { this.basePath = basePath; setOauthBasePath(basePath); @@ -1183,7 +1193,7 @@ protected void updateParamsForAuth(String[] authNames, List queryParams, M for (String authName : authNames) { Authentication auth = authentications.get(authName); if (auth == null) { - throw new RuntimeException("Authentication undefined: " + authName); + continue; } auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); }