Skip to content

Commit b87c927

Browse files
[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
1 parent 2712bbd commit b87c927

File tree

2 files changed

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

2 files changed

+22
-4
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ public class ApiClient {
200200
{{#isHttpSignature}}
201201
if (auth instanceof HttpSignatureAuth) {
202202
authentications.put("{{name}}", auth);
203-
} else {
204-
authentications.put("{{name}}", null);
205203
}
206204
{{/isHttpSignature}}
207205
{{/isBasic}}
@@ -246,10 +244,20 @@ public class ApiClient {
246244
return this;
247245
}
248246

247+
/**
248+
* Returns the base URL to the location where the OpenAPI document is being served.
249+
*
250+
* @return The base URL to the target host.
251+
*/
249252
public String getBasePath() {
250253
return basePath;
251254
}
252255

256+
/**
257+
* Sets the base URL to the location where the OpenAPI document is being served.
258+
*
259+
* @param basePath The base URL to the target host.
260+
*/
253261
public ApiClient setBasePath(String basePath) {
254262
this.basePath = basePath;
255263
{{#hasOAuthMethods}}
@@ -1281,7 +1289,7 @@ public class ApiClient {
12811289
for (String authName : authNames) {
12821290
Authentication auth = authentications.get(authName);
12831291
if (auth == null) {
1284-
throw new RuntimeException("Authentication undefined: " + authName);
1292+
continue;
12851293
}
12861294
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
12871295
}

samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,20 @@ public ApiClient setHttpClient(Client httpClient) {
167167
return this;
168168
}
169169

170+
/**
171+
* Returns the base URL to the location where the OpenAPI document is being served.
172+
*
173+
* @return The base URL to the target host.
174+
*/
170175
public String getBasePath() {
171176
return basePath;
172177
}
173178

179+
/**
180+
* Sets the base URL to the location where the OpenAPI document is being served.
181+
*
182+
* @param basePath The base URL to the target host.
183+
*/
174184
public ApiClient setBasePath(String basePath) {
175185
this.basePath = basePath;
176186
setOauthBasePath(basePath);
@@ -1183,7 +1193,7 @@ protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, M
11831193
for (String authName : authNames) {
11841194
Authentication auth = authentications.get(authName);
11851195
if (auth == null) {
1186-
throw new RuntimeException("Authentication undefined: " + authName);
1196+
continue;
11871197
}
11881198
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
11891199
}

0 commit comments

Comments
 (0)