Skip to content

Commit a1da4b7

Browse files
committed
Move setting of authentication parameters before generating target URL to consider API keys in URL parameters
1 parent 5f92de4 commit a1da4b7

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,27 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
12321232
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
12331233
WebTarget target = httpClient.target(targetURL);
12341234

1235+
// put all headers in one place
1236+
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
1237+
allHeaderParams.putAll(headerParams);
1238+
1239+
if (authNames != null) {
1240+
// update different parameters (e.g. headers) for authentication
1241+
updateParamsForAuth(
1242+
authNames,
1243+
queryParams,
1244+
allHeaderParams,
1245+
cookieParams,
1246+
{{#hasHttpSignatureMethods}}
1247+
serializeToString(body, formParams, contentType, isBodyNullable),
1248+
{{/hasHttpSignatureMethods}}
1249+
{{^hasHttpSignatureMethods}}
1250+
null,
1251+
{{/hasHttpSignatureMethods}}
1252+
method,
1253+
target.getUri());
1254+
}
1255+
12351256
if (queryParams != null) {
12361257
for (Pair queryParam : queryParams) {
12371258
if (queryParam.getValue() != null) {
@@ -1262,27 +1283,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
12621283

12631284
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
12641285

1265-
// put all headers in one place
1266-
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
1267-
allHeaderParams.putAll(headerParams);
1268-
1269-
if (authNames != null) {
1270-
// update different parameters (e.g. headers) for authentication
1271-
updateParamsForAuth(
1272-
authNames,
1273-
queryParams,
1274-
allHeaderParams,
1275-
cookieParams,
1276-
{{#hasHttpSignatureMethods}}
1277-
serializeToString(body, formParams, contentType, isBodyNullable),
1278-
{{/hasHttpSignatureMethods}}
1279-
{{^hasHttpSignatureMethods}}
1280-
null,
1281-
{{/hasHttpSignatureMethods}}
1282-
method,
1283-
target.getUri());
1284-
}
1285-
12861286
for (Entry<String, String> entry : allHeaderParams.entrySet()) {
12871287
String value = entry.getValue();
12881288
if (value != null) {
@@ -1507,4 +1507,4 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
15071507
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
15081508
}
15091509
}
1510-
}
1510+
}

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,27 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
12321232
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
12331233
WebTarget target = httpClient.target(targetURL);
12341234

1235+
// put all headers in one place
1236+
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
1237+
allHeaderParams.putAll(headerParams);
1238+
1239+
if (authNames != null) {
1240+
// update different parameters (e.g. headers) for authentication
1241+
updateParamsForAuth(
1242+
authNames,
1243+
queryParams,
1244+
allHeaderParams,
1245+
cookieParams,
1246+
{{#hasHttpSignatureMethods}}
1247+
serializeToString(body, formParams, contentType, isBodyNullable),
1248+
{{/hasHttpSignatureMethods}}
1249+
{{^hasHttpSignatureMethods}}
1250+
null,
1251+
{{/hasHttpSignatureMethods}}
1252+
method,
1253+
target.getUri());
1254+
}
1255+
12351256
if (queryParams != null) {
12361257
for (Pair queryParam : queryParams) {
12371258
if (queryParam.getValue() != null) {
@@ -1262,27 +1283,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
12621283

12631284
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
12641285

1265-
// put all headers in one place
1266-
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
1267-
allHeaderParams.putAll(headerParams);
1268-
1269-
if (authNames != null) {
1270-
// update different parameters (e.g. headers) for authentication
1271-
updateParamsForAuth(
1272-
authNames,
1273-
queryParams,
1274-
allHeaderParams,
1275-
cookieParams,
1276-
{{#hasHttpSignatureMethods}}
1277-
serializeToString(body, formParams, contentType, isBodyNullable),
1278-
{{/hasHttpSignatureMethods}}
1279-
{{^hasHttpSignatureMethods}}
1280-
null,
1281-
{{/hasHttpSignatureMethods}}
1282-
method,
1283-
target.getUri());
1284-
}
1285-
12861286
for (Entry<String, String> entry : allHeaderParams.entrySet()) {
12871287
String value = entry.getValue();
12881288
if (value != null) {
@@ -1507,4 +1507,4 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
15071507
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
15081508
}
15091509
}
1510-
}
1510+
}

0 commit comments

Comments
 (0)