Skip to content

Commit 58dd030

Browse files
martin-mfgspraot
andauthored
[JAVA] use query parameter apikey if present (#19334)
* Fix #16362 * Update samples * Undo formatting changes * Revert whitespace changes in samples * make it work --------- Co-authored-by: Jason Boileau <jason@boileau.dk> Co-authored-by: Jason Boileau <spraot@users.noreply.github.com>
1 parent d55525f commit 58dd030

14 files changed

Lines changed: 56 additions & 84 deletions

File tree

  • modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson
  • samples/client
    • echo_api/java
      • okhttp-gson-user-defined-templates/src/main/java/org/openapitools/client
      • okhttp-gson/src/main/java/org/openapitools/client
    • others/java
      • okhttp-gson-oneOf/src/main/java/org/openapitools/client
      • okhttp-gson-streaming/src/main/java/org/openapitools/client
    • petstore/java
      • okhttp-gson-3.1/src/main/java/org/openapitools/client
      • okhttp-gson-awsv4signature/src/main/java/org/openapitools/client
      • okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client
      • okhttp-gson-group-parameter/src/main/java/org/openapitools/client
      • okhttp-gson-nullable-required/src/main/java/org/openapitools/client
      • okhttp-gson-parcelableModel/src/main/java/org/openapitools/client
      • okhttp-gson-swagger1/src/main/java/org/openapitools/client
      • okhttp-gson-swagger2/src/main/java/org/openapitools/client
      • okhttp-gson/src/main/java/org/openapitools/client

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,10 +1450,6 @@ public class ApiClient {
14501450
* @throws {{invokerPackage}}.ApiException If fail to serialize the request body object
14511451
*/
14521452
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
1453-
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
1454-
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
1455-
allQueryParams.addAll(collectionQueryParams);
1456-
14571453
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
14581454
14591455
// prepare HTTP request body
@@ -1481,10 +1477,12 @@ public class ApiClient {
14811477
reqBody = serialize(body, contentType);
14821478
}
14831479

1480+
List<Pair> updatedQueryParams = new ArrayList<>(queryParams);
1481+
14841482
// update parameters with authentication settings
1485-
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
1483+
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
14861484

1487-
final Request.Builder reqBuilder = new Request.Builder().url(url);
1485+
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
14881486
processHeaderParams(headerParams, reqBuilder);
14891487
processCookieParams(cookieParams, reqBuilder);
14901488

samples/client/echo_api/java/okhttp-gson-user-defined-templates/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,10 +1267,6 @@ public Call buildCall(String baseUrl, String path, String method, List<Pair> que
12671267
* @throws org.openapitools.client.ApiException If fail to serialize the request body object
12681268
*/
12691269
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
1270-
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
1271-
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
1272-
allQueryParams.addAll(collectionQueryParams);
1273-
12741270
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
12751271

12761272
// prepare HTTP request body
@@ -1298,10 +1294,12 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
12981294
reqBody = serialize(body, contentType);
12991295
}
13001296

1297+
List<Pair> updatedQueryParams = new ArrayList<>(queryParams);
1298+
13011299
// update parameters with authentication settings
1302-
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
1300+
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
13031301

1304-
final Request.Builder reqBuilder = new Request.Builder().url(url);
1302+
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
13051303
processHeaderParams(headerParams, reqBuilder);
13061304
processCookieParams(cookieParams, reqBuilder);
13071305

samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,10 +1197,6 @@ public Call buildCall(String baseUrl, String path, String method, List<Pair> que
11971197
* @throws org.openapitools.client.ApiException If fail to serialize the request body object
11981198
*/
11991199
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
1200-
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
1201-
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
1202-
allQueryParams.addAll(collectionQueryParams);
1203-
12041200
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
12051201

12061202
// prepare HTTP request body
@@ -1228,10 +1224,12 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
12281224
reqBody = serialize(body, contentType);
12291225
}
12301226

1227+
List<Pair> updatedQueryParams = new ArrayList<>(queryParams);
1228+
12311229
// update parameters with authentication settings
1232-
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
1230+
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
12331231

1234-
final Request.Builder reqBuilder = new Request.Builder().url(url);
1232+
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
12351233
processHeaderParams(headerParams, reqBuilder);
12361234
processCookieParams(cookieParams, reqBuilder);
12371235

samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,10 +1171,6 @@ public Call buildCall(String baseUrl, String path, String method, List<Pair> que
11711171
* @throws org.openapitools.client.ApiException If fail to serialize the request body object
11721172
*/
11731173
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
1174-
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
1175-
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
1176-
allQueryParams.addAll(collectionQueryParams);
1177-
11781174
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
11791175

11801176
// prepare HTTP request body
@@ -1202,10 +1198,12 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
12021198
reqBody = serialize(body, contentType);
12031199
}
12041200

1201+
List<Pair> updatedQueryParams = new ArrayList<>(queryParams);
1202+
12051203
// update parameters with authentication settings
1206-
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
1204+
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
12071205

1208-
final Request.Builder reqBuilder = new Request.Builder().url(url);
1206+
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
12091207
processHeaderParams(headerParams, reqBuilder);
12101208
processCookieParams(cookieParams, reqBuilder);
12111209

samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,10 +1194,6 @@ public Call buildCall(String baseUrl, String path, String method, List<Pair> que
11941194
* @throws org.openapitools.client.ApiException If fail to serialize the request body object
11951195
*/
11961196
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
1197-
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
1198-
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
1199-
allQueryParams.addAll(collectionQueryParams);
1200-
12011197
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
12021198

12031199
// prepare HTTP request body
@@ -1225,10 +1221,12 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
12251221
reqBody = serialize(body, contentType);
12261222
}
12271223

1224+
List<Pair> updatedQueryParams = new ArrayList<>(queryParams);
1225+
12281226
// update parameters with authentication settings
1229-
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
1227+
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
12301228

1231-
final Request.Builder reqBuilder = new Request.Builder().url(url);
1229+
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
12321230
processHeaderParams(headerParams, reqBuilder);
12331231
processCookieParams(cookieParams, reqBuilder);
12341232

samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,10 +1267,6 @@ public Call buildCall(String baseUrl, String path, String method, List<Pair> que
12671267
* @throws org.openapitools.client.ApiException If fail to serialize the request body object
12681268
*/
12691269
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
1270-
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
1271-
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
1272-
allQueryParams.addAll(collectionQueryParams);
1273-
12741270
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
12751271

12761272
// prepare HTTP request body
@@ -1298,10 +1294,12 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
12981294
reqBody = serialize(body, contentType);
12991295
}
13001296

1297+
List<Pair> updatedQueryParams = new ArrayList<>(queryParams);
1298+
13011299
// update parameters with authentication settings
1302-
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
1300+
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
13031301

1304-
final Request.Builder reqBuilder = new Request.Builder().url(url);
1302+
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
13051303
processHeaderParams(headerParams, reqBuilder);
13061304
processCookieParams(cookieParams, reqBuilder);
13071305

samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,10 +1287,6 @@ public Call buildCall(String baseUrl, String path, String method, List<Pair> que
12871287
* @throws org.openapitools.client.ApiException If fail to serialize the request body object
12881288
*/
12891289
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
1290-
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
1291-
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
1292-
allQueryParams.addAll(collectionQueryParams);
1293-
12941290
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
12951291

12961292
// prepare HTTP request body
@@ -1318,10 +1314,12 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
13181314
reqBody = serialize(body, contentType);
13191315
}
13201316

1317+
List<Pair> updatedQueryParams = new ArrayList<>(queryParams);
1318+
13211319
// update parameters with authentication settings
1322-
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
1320+
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
13231321

1324-
final Request.Builder reqBuilder = new Request.Builder().url(url);
1322+
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
13251323
processHeaderParams(headerParams, reqBuilder);
13261324
processCookieParams(cookieParams, reqBuilder);
13271325

samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,10 +1272,6 @@ public Call buildCall(String baseUrl, String path, String method, List<Pair> que
12721272
* @throws org.openapitools.client.ApiException If fail to serialize the request body object
12731273
*/
12741274
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
1275-
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
1276-
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
1277-
allQueryParams.addAll(collectionQueryParams);
1278-
12791275
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
12801276

12811277
// prepare HTTP request body
@@ -1303,10 +1299,12 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
13031299
reqBody = serialize(body, contentType);
13041300
}
13051301

1302+
List<Pair> updatedQueryParams = new ArrayList<>(queryParams);
1303+
13061304
// update parameters with authentication settings
1307-
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
1305+
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
13081306

1309-
final Request.Builder reqBuilder = new Request.Builder().url(url);
1307+
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
13101308
processHeaderParams(headerParams, reqBuilder);
13111309
processCookieParams(cookieParams, reqBuilder);
13121310

samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,10 +1267,6 @@ public Call buildCall(String baseUrl, String path, String method, List<Pair> que
12671267
* @throws org.openapitools.client.ApiException If fail to serialize the request body object
12681268
*/
12691269
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
1270-
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
1271-
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
1272-
allQueryParams.addAll(collectionQueryParams);
1273-
12741270
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
12751271

12761272
// prepare HTTP request body
@@ -1298,10 +1294,12 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
12981294
reqBody = serialize(body, contentType);
12991295
}
13001296

1297+
List<Pair> updatedQueryParams = new ArrayList<>(queryParams);
1298+
13011299
// update parameters with authentication settings
1302-
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
1300+
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
13031301

1304-
final Request.Builder reqBuilder = new Request.Builder().url(url);
1302+
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
13051303
processHeaderParams(headerParams, reqBuilder);
13061304
processCookieParams(cookieParams, reqBuilder);
13071305

samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,10 +1270,6 @@ public Call buildCall(String baseUrl, String path, String method, List<Pair> que
12701270
* @throws org.openapitools.client.ApiException If fail to serialize the request body object
12711271
*/
12721272
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
1273-
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
1274-
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
1275-
allQueryParams.addAll(collectionQueryParams);
1276-
12771273
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
12781274

12791275
// prepare HTTP request body
@@ -1301,10 +1297,12 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
13011297
reqBody = serialize(body, contentType);
13021298
}
13031299

1300+
List<Pair> updatedQueryParams = new ArrayList<>(queryParams);
1301+
13041302
// update parameters with authentication settings
1305-
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
1303+
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
13061304

1307-
final Request.Builder reqBuilder = new Request.Builder().url(url);
1305+
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
13081306
processHeaderParams(headerParams, reqBuilder);
13091307
processCookieParams(cookieParams, reqBuilder);
13101308

0 commit comments

Comments
 (0)