Skip to content

Commit e7f52fd

Browse files
[Rust] fix: add location prefix to prevent parameter name collisions when escaping parameter names
1 parent 777b7ee commit e7f52fd

File tree

42 files changed

+395
-379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+395
-379
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,29 @@ public void postProcessParameter(CodegenParameter parameter) {
631631
super.postProcessParameter(parameter);
632632
// in order to avoid name conflicts, we map parameters inside the functions
633633
String inFunctionIdentifier = "";
634+
String locationSuffix = "";
635+
636+
// Determine parameter location using the boolean flags in case of parameters with the same name but in different locations
637+
if (parameter.isPathParam) {
638+
locationSuffix = "path_";
639+
} else if (parameter.isQueryParam) {
640+
locationSuffix = "query_";
641+
} else if (parameter.isHeaderParam) {
642+
locationSuffix = "header_";
643+
} else if (parameter.isBodyParam) {
644+
locationSuffix = "body_";
645+
} else if (parameter.isCookieParam) {
646+
locationSuffix = "cookie_";
647+
} else if (parameter.isFormParam) {
648+
locationSuffix = "form_";
649+
}
634650
if (this.useSingleRequestParameter) {
635-
inFunctionIdentifier = "params." + parameter.paramName;
651+
inFunctionIdentifier = "params." + locationSuffix + parameter.paramName;
636652
} else {
637653
if (parameter.paramName.startsWith("r#")) {
638-
inFunctionIdentifier = "p_" + parameter.paramName.substring(2);
654+
inFunctionIdentifier = "p_" + locationSuffix + parameter.paramName.substring(2);
639655
} else {
640-
inFunctionIdentifier = "p_" + parameter.paramName;
656+
inFunctionIdentifier = "p_" + locationSuffix + parameter.paramName;
641657
}
642658
}
643659
if (!parameter.vendorExtensions.containsKey(this.VENDOR_EXTENSION_PARAM_IDENTIFIER)) { // allow to overwrite this value

samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ pub enum DemoColorGetError {
2525

2626
pub async fn demo_color_get(configuration: &configuration::Configuration, color: models::Color) -> Result<(), Error<DemoColorGetError>> {
2727
// add a prefix to parameters to efficiently prevent name collisions
28-
let p_color = color;
28+
let p_path_color = color;
2929

30-
let uri_str = format!("{}/demo/{color}", configuration.base_path, color=p_color.to_string());
30+
let uri_str = format!("{}/demo/{color}", configuration.base_path, color=p_path_color.to_string());
3131
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
3232

3333
if let Some(ref user_agent) = configuration.user_agent {

samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ pub enum GetStateError {
3232

3333
pub fn create_state(configuration: &configuration::Configuration, create_state_request: models::CreateStateRequest) -> Result<(), Error<CreateStateError>> {
3434
// add a prefix to parameters to efficiently prevent name collisions
35-
let p_create_state_request = create_state_request;
35+
let p_body_create_state_request = create_state_request;
3636

3737
let uri_str = format!("{}/state", configuration.base_path);
3838
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
3939

4040
if let Some(ref user_agent) = configuration.user_agent {
4141
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
4242
}
43-
req_builder = req_builder.json(&p_create_state_request);
43+
req_builder = req_builder.json(&p_body_create_state_request);
4444

4545
let req = req_builder.build()?;
4646
let resp = configuration.client.execute(req)?;

samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ pub fn root_get(configuration: &configuration::Configuration, ) -> Result<models
6666

6767
pub fn test(configuration: &configuration::Configuration, body: Option<serde_json::Value>) -> Result<(), Error<TestError>> {
6868
// add a prefix to parameters to efficiently prevent name collisions
69-
let p_body = body;
69+
let p_body_body = body;
7070

7171
let uri_str = format!("{}/", configuration.base_path);
7272
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
7373

7474
if let Some(ref user_agent) = configuration.user_agent {
7575
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
7676
}
77-
req_builder = req_builder.json(&p_body);
77+
req_builder = req_builder.json(&p_body_body);
7878

7979
let req = req_builder.build()?;
8080
let resp = configuration.client.execute(req)?;

samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ pub enum CreateBarError {
2525

2626
pub fn create_bar(configuration: &configuration::Configuration, bar_create: models::BarCreate) -> Result<models::Bar, Error<CreateBarError>> {
2727
// add a prefix to parameters to efficiently prevent name collisions
28-
let p_bar_create = bar_create;
28+
let p_body_bar_create = bar_create;
2929

3030
let uri_str = format!("{}/bar", configuration.base_path);
3131
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
3232

3333
if let Some(ref user_agent) = configuration.user_agent {
3434
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
3535
}
36-
req_builder = req_builder.json(&p_bar_create);
36+
req_builder = req_builder.json(&p_body_bar_create);
3737

3838
let req = req_builder.build()?;
3939
let resp = configuration.client.execute(req)?;

samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ pub enum GetAllFoosError {
3232

3333
pub fn create_foo(configuration: &configuration::Configuration, foo: Option<models::Foo>) -> Result<models::FooRefOrValue, Error<CreateFooError>> {
3434
// add a prefix to parameters to efficiently prevent name collisions
35-
let p_foo = foo;
35+
let p_body_foo = foo;
3636

3737
let uri_str = format!("{}/foo", configuration.base_path);
3838
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
3939

4040
if let Some(ref user_agent) = configuration.user_agent {
4141
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
4242
}
43-
req_builder = req_builder.json(&p_foo);
43+
req_builder = req_builder.json(&p_body_foo);
4444

4545
let req = req_builder.build()?;
4646
let resp = configuration.client.execute(req)?;

samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ pub enum GetParameterNameMappingError {
2525

2626
pub fn get_parameter_name_mapping(configuration: &configuration::Configuration, underscore_type: i64, r#type: &str, type_with_underscore: &str, dash_type: &str, http_debug_option: &str) -> Result<(), Error<GetParameterNameMappingError>> {
2727
// add a prefix to parameters to efficiently prevent name collisions
28-
let p_underscore_type = underscore_type;
29-
let p_type = r#type;
30-
let p_type_with_underscore = type_with_underscore;
31-
let p_dash_type = dash_type;
32-
let p_http_debug_option = http_debug_option;
28+
let p_header_underscore_type = underscore_type;
29+
let p_query_type = r#type;
30+
let p_header_type_with_underscore = type_with_underscore;
31+
let p_header_dash_type = dash_type;
32+
let p_query_http_debug_option = http_debug_option;
3333

3434
let uri_str = format!("{}/fake/parameter-name-mapping", configuration.base_path);
3535
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
3636

37-
req_builder = req_builder.query(&[("type", &p_type.to_string())]);
38-
req_builder = req_builder.query(&[("http_debug_option", &p_http_debug_option.to_string())]);
37+
req_builder = req_builder.query(&[("type", &p_query_type.to_string())]);
38+
req_builder = req_builder.query(&[("http_debug_option", &p_query_http_debug_option.to_string())]);
3939
if let Some(ref user_agent) = configuration.user_agent {
4040
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
4141
}
42-
req_builder = req_builder.header("_type", p_underscore_type.to_string());
43-
req_builder = req_builder.header("type_", p_type_with_underscore.to_string());
44-
req_builder = req_builder.header("-type", p_dash_type.to_string());
42+
req_builder = req_builder.header("_type", p_header_underscore_type.to_string());
43+
req_builder = req_builder.header("type_", p_header_type_with_underscore.to_string());
44+
req_builder = req_builder.header("-type", p_header_dash_type.to_string());
4545

4646
let req = req_builder.build()?;
4747
let resp = configuration.client.execute(req)?;

samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@ pub enum TestNullableRequiredParamError {
5050
///
5151
pub async fn test_nullable_required_param(configuration: &configuration::Configuration, params: TestNullableRequiredParamParams) -> Result<ResponseContent<TestNullableRequiredParamSuccess>, Error<TestNullableRequiredParamError>> {
5252

53-
let uri_str = format!("{}/fake/user/{user_name}", configuration.base_path, user_name=crate::apis::urlencode(params.user_name));
53+
let uri_str = format!("{}/fake/user/{user_name}", configuration.base_path, user_name=crate::apis::urlencode(params.path_user_name));
5454
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
5555

56-
if let Some(ref param_value) = params.content {
56+
if let Some(ref param_value) = params.query_content {
5757
req_builder = req_builder.query(&[("content", &param_value.to_string())]);
5858
}
59-
req_builder = req_builder.query(&[("anyType", &params.any_type.to_string())]);
59+
req_builder = req_builder.query(&[("anyType", &params.query_any_type.to_string())]);
6060
if let Some(ref user_agent) = configuration.user_agent {
6161
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
6262
}
63-
match params.dummy_required_nullable_param {
63+
match params.header_dummy_required_nullable_param {
6464
Some(param_value) => { req_builder = req_builder.header("dummy_required_nullable_param", param_value.to_string()); },
6565
None => { req_builder = req_builder.header("dummy_required_nullable_param", ""); },
6666
}
67-
if let Some(param_value) = params.uppercase {
67+
if let Some(param_value) = params.header_uppercase {
6868
req_builder = req_builder.header("UPPERCASE", param_value.to_string());
6969
}
7070

samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe
269269
if let Some(ref token) = configuration.oauth_access_token {
270270
req_builder = req_builder.bearer_auth(token.to_owned());
271271
};
272-
req_builder = req_builder.json(&params.pet);
272+
req_builder = req_builder.json(&params.body_pet);
273273

274274
let req = req_builder.build()?;
275275
let resp = configuration.client.execute(req).await?;
@@ -290,13 +290,13 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe
290290
///
291291
pub async fn delete_pet(configuration: &configuration::Configuration, params: DeletePetParams) -> Result<ResponseContent<DeletePetSuccess>, Error<DeletePetError>> {
292292

293-
let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id);
293+
let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.path_pet_id);
294294
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
295295

296296
if let Some(ref user_agent) = configuration.user_agent {
297297
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
298298
}
299-
if let Some(param_value) = params.api_key {
299+
if let Some(param_value) = params.header_api_key {
300300
req_builder = req_builder.header("api_key", param_value.to_string());
301301
}
302302
if let Some(ref token) = configuration.oauth_access_token {
@@ -326,10 +326,10 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p
326326
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
327327

328328
req_builder = match "csv" {
329-
"multi" => req_builder.query(&params.status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
330-
_ => req_builder.query(&[("status", &params.status.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
329+
"multi" => req_builder.query(&params.query_status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
330+
_ => req_builder.query(&[("status", &params.query_status.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
331331
};
332-
if let Some(ref param_value) = params.r#type {
332+
if let Some(ref param_value) = params.query_r#type {
333333
req_builder = match "csv" {
334334
"multi" => req_builder.query(&param_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
335335
_ => req_builder.query(&[("type", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
@@ -365,8 +365,8 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par
365365
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
366366

367367
req_builder = match "csv" {
368-
"multi" => req_builder.query(&params.tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
369-
_ => req_builder.query(&[("tags", &params.tags.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
368+
"multi" => req_builder.query(&params.query_tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
369+
_ => req_builder.query(&[("tags", &params.query_tags.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
370370
};
371371
if let Some(ref user_agent) = configuration.user_agent {
372372
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
@@ -394,7 +394,7 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par
394394
/// Returns a single pet
395395
pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: GetPetByIdParams) -> Result<ResponseContent<GetPetByIdSuccess>, Error<GetPetByIdError>> {
396396

397-
let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id);
397+
let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.path_pet_id);
398398
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
399399

400400
if let Some(ref user_agent) = configuration.user_agent {
@@ -431,7 +431,7 @@ pub async fn pets_explode_post(configuration: &configuration::Configuration, par
431431
let uri_str = format!("{}/pets/explode", configuration.base_path);
432432
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
433433

434-
if let Some(ref param_value) = params.page_explode {
434+
if let Some(ref param_value) = params.query_page_explode {
435435
req_builder = req_builder.query(&param_value);
436436
}
437437
if let Some(ref user_agent) = configuration.user_agent {
@@ -460,7 +460,7 @@ pub async fn pets_post(configuration: &configuration::Configuration, params: Pet
460460
let uri_str = format!("{}/pets", configuration.base_path);
461461
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
462462

463-
if let Some(ref param_value) = params.page {
463+
if let Some(ref param_value) = params.query_page {
464464
req_builder = req_builder.query(&[("page", &serde_json::to_string(param_value)?)]);
465465
}
466466
if let Some(ref user_agent) = configuration.user_agent {
@@ -495,7 +495,7 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up
495495
if let Some(ref token) = configuration.oauth_access_token {
496496
req_builder = req_builder.bearer_auth(token.to_owned());
497497
};
498-
req_builder = req_builder.json(&params.pet);
498+
req_builder = req_builder.json(&params.body_pet);
499499

500500
let req = req_builder.build()?;
501501
let resp = configuration.client.execute(req).await?;
@@ -516,7 +516,7 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up
516516
///
517517
pub async fn update_pet_with_form(configuration: &configuration::Configuration, params: UpdatePetWithFormParams) -> Result<ResponseContent<UpdatePetWithFormSuccess>, Error<UpdatePetWithFormError>> {
518518

519-
let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id);
519+
let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.path_pet_id);
520520
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
521521

522522
if let Some(ref user_agent) = configuration.user_agent {
@@ -526,10 +526,10 @@ pub async fn update_pet_with_form(configuration: &configuration::Configuration,
526526
req_builder = req_builder.bearer_auth(token.to_owned());
527527
};
528528
let mut multipart_form_params = std::collections::HashMap::new();
529-
if let Some(param_value) = params.name {
529+
if let Some(param_value) = params.form_name {
530530
multipart_form_params.insert("name", param_value.to_string());
531531
}
532-
if let Some(param_value) = params.status {
532+
if let Some(param_value) = params.form_status {
533533
multipart_form_params.insert("status", param_value.to_string());
534534
}
535535
req_builder = req_builder.form(&multipart_form_params);
@@ -553,7 +553,7 @@ pub async fn update_pet_with_form(configuration: &configuration::Configuration,
553553
///
554554
pub async fn upload_file(configuration: &configuration::Configuration, params: UploadFileParams) -> Result<ResponseContent<UploadFileSuccess>, Error<UploadFileError>> {
555555

556-
let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=params.pet_id);
556+
let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=params.path_pet_id);
557557
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
558558

559559
if let Some(ref user_agent) = configuration.user_agent {
@@ -563,7 +563,7 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U
563563
req_builder = req_builder.bearer_auth(token.to_owned());
564564
};
565565
let mut multipart_form = reqwest::multipart::Form::new();
566-
if let Some(param_value) = params.additional_metadata {
566+
if let Some(param_value) = params.form_additional_metadata {
567567
multipart_form = multipart_form.text("additionalMetadata", param_value.to_string());
568568
}
569569
// TODO: support file upload for 'file' parameter

samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub enum PlaceOrderError {
104104
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
105105
pub async fn delete_order(configuration: &configuration::Configuration, params: DeleteOrderParams) -> Result<ResponseContent<DeleteOrderSuccess>, Error<DeleteOrderError>> {
106106

107-
let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(params.order_id));
107+
let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(params.path_order_id));
108108
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
109109

110110
if let Some(ref user_agent) = configuration.user_agent {
@@ -164,7 +164,7 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu
164164
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
165165
pub async fn get_order_by_id(configuration: &configuration::Configuration, params: GetOrderByIdParams) -> Result<ResponseContent<GetOrderByIdSuccess>, Error<GetOrderByIdError>> {
166166

167-
let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=params.order_id);
167+
let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=params.path_order_id);
168168
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
169169

170170
if let Some(ref user_agent) = configuration.user_agent {
@@ -196,7 +196,7 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P
196196
if let Some(ref user_agent) = configuration.user_agent {
197197
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
198198
}
199-
req_builder = req_builder.json(&params.order);
199+
req_builder = req_builder.json(&params.body_order);
200200

201201
let req = req_builder.build()?;
202202
let resp = configuration.client.execute(req).await?;

0 commit comments

Comments
 (0)