@@ -132,7 +132,7 @@ impl HttpClient {
132
132
133
133
// Add query parameters with proper URL encoding
134
134
if !extracted_params. query . is_empty ( ) {
135
- Self :: add_query_parameters ( & mut url, & extracted_params. query , tool_metadata ) ;
135
+ Self :: add_query_parameters ( & mut url, & extracted_params. query ) ;
136
136
}
137
137
138
138
info ! ( "Final URL: {}" , url) ;
@@ -154,12 +154,12 @@ impl HttpClient {
154
154
155
155
// Add request-specific headers (these override default headers)
156
156
if !extracted_params. headers . is_empty ( ) {
157
- request = Self :: add_headers ( request, & extracted_params. headers , tool_metadata ) ;
157
+ request = Self :: add_headers ( request, & extracted_params. headers ) ;
158
158
}
159
159
160
160
// Add cookies
161
161
if !extracted_params. cookies . is_empty ( ) {
162
- request = Self :: add_cookies ( request, & extracted_params. cookies , tool_metadata ) ;
162
+ request = Self :: add_cookies ( request, & extracted_params. cookies ) ;
163
163
}
164
164
165
165
// Add request body if present
@@ -369,24 +369,12 @@ impl HttpClient {
369
369
}
370
370
371
371
/// Add query parameters to the request using proper URL encoding
372
- fn add_query_parameters (
373
- url : & mut Url ,
374
- query_params : & HashMap < String , QueryParameter > ,
375
- tool_metadata : & ToolMetadata ,
376
- ) {
372
+ fn add_query_parameters ( url : & mut Url , query_params : & HashMap < String , QueryParameter > ) {
377
373
{
378
374
let mut query_pairs = url. query_pairs_mut ( ) ;
379
375
for ( key, query_param) in query_params {
380
- // Skip empty optional array parameters
381
- if tool_metadata. should_omit_empty_array_parameter ( key, & query_param. value ) {
382
- continue ;
383
- }
384
376
if let Value :: Array ( arr) = & query_param. value {
385
- if arr. is_empty ( ) {
386
- // For empty arrays that should be included (required or with defaults),
387
- // add the parameter with an empty value
388
- query_pairs. append_pair ( key, "" ) ;
389
- } else if query_param. explode {
377
+ if query_param. explode {
390
378
// explode=true: Handle array parameters - add each value as a separate query parameter
391
379
for item in arr {
392
380
let item_str = match item {
@@ -437,13 +425,8 @@ impl HttpClient {
437
425
fn add_headers (
438
426
mut request : RequestBuilder ,
439
427
headers : & HashMap < String , Value > ,
440
- tool_metadata : & ToolMetadata ,
441
428
) -> RequestBuilder {
442
429
for ( key, value) in headers {
443
- // Skip empty optional array parameters
444
- if tool_metadata. should_omit_empty_array_parameter ( key, value) {
445
- continue ;
446
- }
447
430
let value_str = match value {
448
431
Value :: String ( s) => s. clone ( ) ,
449
432
Value :: Number ( n) => n. to_string ( ) ,
@@ -459,15 +442,10 @@ impl HttpClient {
459
442
fn add_cookies (
460
443
mut request : RequestBuilder ,
461
444
cookies : & HashMap < String , Value > ,
462
- tool_metadata : & ToolMetadata ,
463
445
) -> RequestBuilder {
464
446
if !cookies. is_empty ( ) {
465
447
let cookie_header = cookies
466
448
. iter ( )
467
- . filter ( |( key, value) | {
468
- // Skip empty optional array parameters
469
- !tool_metadata. should_omit_empty_array_parameter ( key, value)
470
- } )
471
449
. map ( |( key, value) | {
472
450
let value_str = match value {
473
451
Value :: String ( s) => s. clone ( ) ,
@@ -480,9 +458,7 @@ impl HttpClient {
480
458
. collect :: < Vec < _ > > ( )
481
459
. join ( "; " ) ;
482
460
483
- if !cookie_header. is_empty ( ) {
484
- request = request. header ( header:: COOKIE , cookie_header) ;
485
- }
461
+ request = request. header ( header:: COOKIE , cookie_header) ;
486
462
}
487
463
request
488
464
}
@@ -925,7 +901,7 @@ mod tests {
925
901
} ;
926
902
927
903
let mut url = client. build_url ( & tool_metadata, & extracted_params) . unwrap ( ) ;
928
- HttpClient :: add_query_parameters ( & mut url, & extracted_params. query , & tool_metadata ) ;
904
+ HttpClient :: add_query_parameters ( & mut url, & extracted_params. query ) ;
929
905
930
906
let url_string = url. to_string ( ) ;
931
907
@@ -973,7 +949,7 @@ mod tests {
973
949
} ;
974
950
975
951
let mut url = client. build_url ( & tool_metadata, & extracted_params) . unwrap ( ) ;
976
- HttpClient :: add_query_parameters ( & mut url, & extracted_params. query , & tool_metadata ) ;
952
+ HttpClient :: add_query_parameters ( & mut url, & extracted_params. query ) ;
977
953
978
954
let url_string = url. to_string ( ) ;
979
955
@@ -1093,11 +1069,7 @@ mod tests {
1093
1069
let mut url_exploded = client
1094
1070
. build_url ( & tool_metadata, & extracted_params_exploded)
1095
1071
. unwrap ( ) ;
1096
- HttpClient :: add_query_parameters (
1097
- & mut url_exploded,
1098
- & extracted_params_exploded. query ,
1099
- & tool_metadata,
1100
- ) ;
1072
+ HttpClient :: add_query_parameters ( & mut url_exploded, & extracted_params_exploded. query ) ;
1101
1073
let url_exploded_string = url_exploded. to_string ( ) ;
1102
1074
1103
1075
// Test explode=false (should generate comma-separated values)
@@ -1122,7 +1094,6 @@ mod tests {
1122
1094
HttpClient :: add_query_parameters (
1123
1095
& mut url_not_exploded,
1124
1096
& extracted_params_not_exploded. query ,
1125
- & tool_metadata,
1126
1097
) ;
1127
1098
let url_not_exploded_string = url_not_exploded. to_string ( ) ;
1128
1099
@@ -1139,192 +1110,4 @@ mod tests {
1139
1110
println ! ( "Exploded URL: {url_exploded_string}" ) ;
1140
1111
println ! ( "Non-exploded URL: {url_not_exploded_string}" ) ;
1141
1112
}
1142
-
1143
- #[ test]
1144
- fn test_omit_empty_optional_array_query_parameters ( ) {
1145
- let base_url = Url :: parse ( "https://api.example.com" ) . unwrap ( ) ;
1146
- let client = HttpClient :: new ( ) . with_base_url ( base_url) . unwrap ( ) ;
1147
-
1148
- // Create tool metadata with optional and required array parameters
1149
- let tool_metadata = crate :: ToolMetadata {
1150
- name : "test" . to_string ( ) ,
1151
- title : None ,
1152
- description : "test" . to_string ( ) ,
1153
- parameters : json ! ( {
1154
- "type" : "object" ,
1155
- "properties" : {
1156
- "optional_array" : { "type" : "array" , "items" : { "type" : "string" } } ,
1157
- "required_array" : { "type" : "array" , "items" : { "type" : "string" } } ,
1158
- "optional_with_default" : {
1159
- "type" : "array" ,
1160
- "items" : { "type" : "string" } ,
1161
- "default" : [ "default" ]
1162
- } ,
1163
- "optional_string" : { "type" : "string" }
1164
- } ,
1165
- "required" : [ "required_array" ]
1166
- } ) ,
1167
- output_schema : None ,
1168
- method : "GET" . to_string ( ) ,
1169
- path : "/test" . to_string ( ) ,
1170
- } ;
1171
-
1172
- let mut query_params = HashMap :: new ( ) ;
1173
- query_params. insert (
1174
- "optional_array" . to_string ( ) ,
1175
- QueryParameter :: new ( json ! ( [ ] ) , true ) ,
1176
- ) ; // Empty optional array - should be omitted
1177
- query_params. insert (
1178
- "required_array" . to_string ( ) ,
1179
- QueryParameter :: new ( json ! ( [ ] ) , true ) ,
1180
- ) ; // Empty required array - should be included
1181
- query_params. insert (
1182
- "optional_with_default" . to_string ( ) ,
1183
- QueryParameter :: new ( json ! ( [ ] ) , true ) ,
1184
- ) ; // Empty optional with default - should be included
1185
- query_params. insert (
1186
- "optional_string" . to_string ( ) ,
1187
- QueryParameter :: new ( json ! ( "" ) , true ) ,
1188
- ) ; // Empty string - should be included (not array)
1189
-
1190
- let extracted_params = ExtractedParameters {
1191
- path : HashMap :: new ( ) ,
1192
- query : query_params,
1193
- headers : HashMap :: new ( ) ,
1194
- cookies : HashMap :: new ( ) ,
1195
- body : HashMap :: new ( ) ,
1196
- config : crate :: tool_generator:: RequestConfig :: default ( ) ,
1197
- } ;
1198
-
1199
- let mut url = client. build_url ( & tool_metadata, & extracted_params) . unwrap ( ) ;
1200
- HttpClient :: add_query_parameters ( & mut url, & extracted_params. query , & tool_metadata) ;
1201
-
1202
- let url_string = url. to_string ( ) ;
1203
- // Verify empty optional array is omitted
1204
- assert ! ( !url_string. contains( "optional_array" ) ) ;
1205
-
1206
- // Verify empty required array is included
1207
- assert ! ( url_string. contains( "required_array" ) ) ;
1208
-
1209
- // Verify empty optional with default is included
1210
- assert ! ( url_string. contains( "optional_with_default" ) ) ;
1211
-
1212
- // Verify empty string is included (not an array)
1213
- assert ! ( url_string. contains( "optional_string" ) ) ;
1214
- }
1215
-
1216
- #[ test]
1217
- fn test_omit_empty_optional_array_headers ( ) {
1218
- let tool_metadata = crate :: ToolMetadata {
1219
- name : "test" . to_string ( ) ,
1220
- title : None ,
1221
- description : "test" . to_string ( ) ,
1222
- parameters : json ! ( {
1223
- "type" : "object" ,
1224
- "properties" : {
1225
- "x-optional-array" : { "type" : "array" , "items" : { "type" : "string" } } ,
1226
- "x-required-array" : { "type" : "array" , "items" : { "type" : "string" } } ,
1227
- "x-optional-string" : { "type" : "string" }
1228
- } ,
1229
- "required" : [ "x-required-array" ]
1230
- } ) ,
1231
- output_schema : None ,
1232
- method : "GET" . to_string ( ) ,
1233
- path : "/test" . to_string ( ) ,
1234
- } ;
1235
-
1236
- let mut headers = HashMap :: new ( ) ;
1237
- headers. insert ( "x-optional-array" . to_string ( ) , json ! ( [ ] ) ) ; // Should be omitted
1238
- headers. insert ( "x-required-array" . to_string ( ) , json ! ( [ ] ) ) ; // Should be included
1239
- headers. insert ( "x-optional-string" . to_string ( ) , json ! ( "value" ) ) ; // Should be included
1240
-
1241
- let request = HttpClient :: new ( )
1242
- . client
1243
- . request ( reqwest:: Method :: GET , "https://api.example.com" ) ;
1244
- let request = HttpClient :: add_headers ( request, & headers, & tool_metadata) ;
1245
-
1246
- // We can't easily inspect the headers without sending the request,
1247
- // but we can verify the function doesn't panic and returns a valid RequestBuilder
1248
- assert ! ( request. build( ) . is_ok( ) ) ;
1249
- }
1250
-
1251
- #[ test]
1252
- fn test_omit_empty_optional_array_cookies ( ) {
1253
- let tool_metadata = crate :: ToolMetadata {
1254
- name : "test" . to_string ( ) ,
1255
- title : None ,
1256
- description : "test" . to_string ( ) ,
1257
- parameters : json ! ( {
1258
- "type" : "object" ,
1259
- "properties" : {
1260
- "optional_array_cookie" : { "type" : "array" , "items" : { "type" : "string" } } ,
1261
- "required_array_cookie" : { "type" : "array" , "items" : { "type" : "string" } } ,
1262
- "optional_string_cookie" : { "type" : "string" }
1263
- } ,
1264
- "required" : [ "required_array_cookie" ]
1265
- } ) ,
1266
- output_schema : None ,
1267
- method : "GET" . to_string ( ) ,
1268
- path : "/test" . to_string ( ) ,
1269
- } ;
1270
-
1271
- let mut cookies = HashMap :: new ( ) ;
1272
- cookies. insert ( "optional_array_cookie" . to_string ( ) , json ! ( [ ] ) ) ; // Should be omitted
1273
- cookies. insert ( "required_array_cookie" . to_string ( ) , json ! ( [ ] ) ) ; // Should be included
1274
- cookies. insert ( "optional_string_cookie" . to_string ( ) , json ! ( "value" ) ) ; // Should be included
1275
-
1276
- let request = HttpClient :: new ( )
1277
- . client
1278
- . request ( reqwest:: Method :: GET , "https://api.example.com" ) ;
1279
- let request = HttpClient :: add_cookies ( request, & cookies, & tool_metadata) ;
1280
-
1281
- // Verify the function doesn't panic and returns a valid RequestBuilder
1282
- assert ! ( request. build( ) . is_ok( ) ) ;
1283
- }
1284
-
1285
- #[ test]
1286
- fn test_non_empty_optional_arrays_are_included ( ) {
1287
- let base_url = Url :: parse ( "https://api.example.com" ) . unwrap ( ) ;
1288
- let client = HttpClient :: new ( ) . with_base_url ( base_url) . unwrap ( ) ;
1289
-
1290
- let tool_metadata = crate :: ToolMetadata {
1291
- name : "test" . to_string ( ) ,
1292
- title : None ,
1293
- description : "test" . to_string ( ) ,
1294
- parameters : json ! ( {
1295
- "type" : "object" ,
1296
- "properties" : {
1297
- "optional_array" : { "type" : "array" , "items" : { "type" : "string" } }
1298
- } ,
1299
- "required" : [ ]
1300
- } ) ,
1301
- output_schema : None ,
1302
- method : "GET" . to_string ( ) ,
1303
- path : "/test" . to_string ( ) ,
1304
- } ;
1305
-
1306
- let mut query_params = HashMap :: new ( ) ;
1307
- query_params. insert (
1308
- "optional_array" . to_string ( ) ,
1309
- QueryParameter :: new ( json ! ( [ "value1" , "value2" ] ) , true ) ,
1310
- ) ; // Non-empty optional array - should be included
1311
-
1312
- let extracted_params = ExtractedParameters {
1313
- path : HashMap :: new ( ) ,
1314
- query : query_params,
1315
- headers : HashMap :: new ( ) ,
1316
- cookies : HashMap :: new ( ) ,
1317
- body : HashMap :: new ( ) ,
1318
- config : crate :: tool_generator:: RequestConfig :: default ( ) ,
1319
- } ;
1320
-
1321
- let mut url = client. build_url ( & tool_metadata, & extracted_params) . unwrap ( ) ;
1322
- HttpClient :: add_query_parameters ( & mut url, & extracted_params. query , & tool_metadata) ;
1323
-
1324
- let url_string = url. to_string ( ) ;
1325
-
1326
- // Verify non-empty optional array is included
1327
- assert ! ( url_string. contains( "optional_array=value1" ) ) ;
1328
- assert ! ( url_string. contains( "optional_array=value2" ) ) ;
1329
- }
1330
1113
}
0 commit comments