Skip to content

Commit b1fac19

Browse files
authored
Fix #18572 rust server: Silence clippy lints by refactoring (#18575)
* refactor: move closure definition to own statement A clippy lint recommends not using a closure inside of a statement. The code generation used to produce code that triggered this warning, which caused the rust-server integration test to fail because clippy is configured to return lint violations as errors. For details for the lint see: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions * refactor: Remove unnecessary qualification A GitHub action test used to fail because of a clippy warning that was emitted due to not using an imported symbol but qualifying its use. A failed test can be seen here: https://github.com/OpenAPITools/openapi-generator/actions/runs/8958257509/job/24603984954?pr=18563 With the relevant error being: error: unnecessary qualification --> output/openapi-v3/src/client/callbacks.rs:88:9 | 88 | futures::future::ok(Service::new( This commit simply removes the qualification. * test: Update examples and run integration test. Updated examples by running `./bin/generate-samples.sh ./bin/configs/rust-server-*` The integration test with the following command passes: `mvn integration-test -f samples/server/petstore/rust-server/pom.xml`
1 parent f145b89 commit b1fac19

File tree

10 files changed

+150
-121
lines changed

10 files changed

+150
-121
lines changed

modules/openapi-generator/src/main/resources/rust-server/server-make-service.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
3131
}
3232
3333
fn call(&mut self, target: Target) -> Self::Future {
34-
futures::future::ok(Service::new(
34+
future::ok(Service::new(
3535
self.api_impl.clone(),
3636
))
3737
}

modules/openapi-generator/src/main/resources/rust-server/server-operation.mustache

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,11 @@
224224
let deserializer = &mut serde_json::Deserializer::from_slice(&body);
225225
{{/x-consumes-json}}
226226
{{^x-consumes-plain-text}}
227-
match serde_ignored::deserialize(deserializer, |path| {
228-
warn!("Ignoring unknown field in body: {}", path);
229-
unused_elements.push(path.to_string());
230-
}) {
227+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
228+
warn!("Ignoring unknown field in body: {}", path);
229+
unused_elements.push(path.to_string());
230+
};
231+
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
231232
Ok(param_{{{paramName}}}) => param_{{{paramName}}},
232233
{{#required}}
233234
Err(e) => return Ok(Response::builder()
@@ -421,10 +422,11 @@
421422
Some("{{{contentType}}}") if param_{{{paramName}}}.is_none() => {
422423
// Extract JSON part.
423424
let deserializer = &mut serde_json::Deserializer::from_slice(part.body.as_slice());
424-
let json_data: {{dataType}} = match serde_ignored::deserialize(deserializer, |path| {
425+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
425426
warn!("Ignoring unknown field in JSON part: {}", path);
426427
unused_elements.push(path.to_string());
427-
}) {
428+
};
429+
let json_data: {{dataType}} = match serde_ignored::deserialize(deserializer, handle_unknown_field) {
428430
Ok(json_data) => json_data,
429431
Err(e) => return Ok(Response::builder()
430432
.status(StatusCode::BAD_REQUEST)

samples/server/petstore/rust-server/output/multipart-v3/src/server/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
8181
}
8282

8383
fn call(&mut self, target: Target) -> Self::Future {
84-
futures::future::ok(Service::new(
84+
future::ok(Service::new(
8585
self.api_impl.clone(),
8686
))
8787
}
@@ -206,10 +206,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
206206
Some("application/json") if param_object_field.is_none() => {
207207
// Extract JSON part.
208208
let deserializer = &mut serde_json::Deserializer::from_slice(part.body.as_slice());
209-
let json_data: models::MultipartRequestObjectField = match serde_ignored::deserialize(deserializer, |path| {
209+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
210210
warn!("Ignoring unknown field in JSON part: {}", path);
211211
unused_elements.push(path.to_string());
212-
}) {
212+
};
213+
let json_data: models::MultipartRequestObjectField = match serde_ignored::deserialize(deserializer, handle_unknown_field) {
213214
Ok(json_data) => json_data,
214215
Err(e) => return Ok(Response::builder()
215216
.status(StatusCode::BAD_REQUEST)

samples/server/petstore/rust-server/output/no-example-v3/src/server/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
7070
}
7171

7272
fn call(&mut self, target: Target) -> Self::Future {
73-
futures::future::ok(Service::new(
73+
future::ok(Service::new(
7474
self.api_impl.clone(),
7575
))
7676
}
@@ -150,10 +150,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
150150
let mut unused_elements = Vec::new();
151151
let param_op_get_request: Option<models::OpGetRequest> = if !body.is_empty() {
152152
let deserializer = &mut serde_json::Deserializer::from_slice(&body);
153-
match serde_ignored::deserialize(deserializer, |path| {
154-
warn!("Ignoring unknown field in body: {}", path);
155-
unused_elements.push(path.to_string());
156-
}) {
153+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
154+
warn!("Ignoring unknown field in body: {}", path);
155+
unused_elements.push(path.to_string());
156+
};
157+
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
157158
Ok(param_op_get_request) => param_op_get_request,
158159
Err(e) => return Ok(Response::builder()
159160
.status(StatusCode::BAD_REQUEST)

samples/server/petstore/rust-server/output/openapi-v3/src/client/callbacks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
8585
}
8686

8787
fn call(&mut self, target: Target) -> Self::Future {
88-
futures::future::ok(Service::new(
88+
future::ok(Service::new(
8989
self.api_impl.clone(),
9090
))
9191
}

samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
155155
}
156156

157157
fn call(&mut self, target: Target) -> Self::Future {
158-
futures::future::ok(Service::new(
158+
future::ok(Service::new(
159159
self.api_impl.clone(),
160160
))
161161
}
@@ -1269,10 +1269,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
12691269
let mut unused_elements = Vec::new();
12701270
let param_object_untyped_props: Option<models::ObjectUntypedProps> = if !body.is_empty() {
12711271
let deserializer = &mut serde_json::Deserializer::from_slice(&body);
1272-
match serde_ignored::deserialize(deserializer, |path| {
1273-
warn!("Ignoring unknown field in body: {}", path);
1274-
unused_elements.push(path.to_string());
1275-
}) {
1272+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
1273+
warn!("Ignoring unknown field in body: {}", path);
1274+
unused_elements.push(path.to_string());
1275+
};
1276+
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
12761277
Ok(param_object_untyped_props) => param_object_untyped_props,
12771278
Err(_) => None,
12781279
}
@@ -1368,10 +1369,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
13681369
let mut unused_elements = Vec::new();
13691370
let param_duplicate_xml_object: Option<models::DuplicateXmlObject> = if !body.is_empty() {
13701371
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
1371-
match serde_ignored::deserialize(deserializer, |path| {
1372-
warn!("Ignoring unknown field in body: {}", path);
1373-
unused_elements.push(path.to_string());
1374-
}) {
1372+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
1373+
warn!("Ignoring unknown field in body: {}", path);
1374+
unused_elements.push(path.to_string());
1375+
};
1376+
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
13751377
Ok(param_duplicate_xml_object) => param_duplicate_xml_object,
13761378
Err(_) => None,
13771379
}
@@ -1435,10 +1437,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
14351437
let mut unused_elements = Vec::new();
14361438
let param_another_xml_object: Option<models::AnotherXmlObject> = if !body.is_empty() {
14371439
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
1438-
match serde_ignored::deserialize(deserializer, |path| {
1439-
warn!("Ignoring unknown field in body: {}", path);
1440-
unused_elements.push(path.to_string());
1441-
}) {
1440+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
1441+
warn!("Ignoring unknown field in body: {}", path);
1442+
unused_elements.push(path.to_string());
1443+
};
1444+
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
14421445
Ok(param_another_xml_object) => param_another_xml_object,
14431446
Err(_) => None,
14441447
}
@@ -1513,10 +1516,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
15131516
let mut unused_elements = Vec::new();
15141517
let param_another_xml_array: Option<models::AnotherXmlArray> = if !body.is_empty() {
15151518
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
1516-
match serde_ignored::deserialize(deserializer, |path| {
1517-
warn!("Ignoring unknown field in body: {}", path);
1518-
unused_elements.push(path.to_string());
1519-
}) {
1519+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
1520+
warn!("Ignoring unknown field in body: {}", path);
1521+
unused_elements.push(path.to_string());
1522+
};
1523+
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
15201524
Ok(param_another_xml_array) => param_another_xml_array,
15211525
Err(_) => None,
15221526
}
@@ -1580,10 +1584,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
15801584
let mut unused_elements = Vec::new();
15811585
let param_xml_array: Option<models::XmlArray> = if !body.is_empty() {
15821586
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
1583-
match serde_ignored::deserialize(deserializer, |path| {
1584-
warn!("Ignoring unknown field in body: {}", path);
1585-
unused_elements.push(path.to_string());
1586-
}) {
1587+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
1588+
warn!("Ignoring unknown field in body: {}", path);
1589+
unused_elements.push(path.to_string());
1590+
};
1591+
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
15871592
Ok(param_xml_array) => param_xml_array,
15881593
Err(_) => None,
15891594
}
@@ -1647,10 +1652,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
16471652
let mut unused_elements = Vec::new();
16481653
let param_xml_object: Option<models::XmlObject> = if !body.is_empty() {
16491654
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
1650-
match serde_ignored::deserialize(deserializer, |path| {
1651-
warn!("Ignoring unknown field in body: {}", path);
1652-
unused_elements.push(path.to_string());
1653-
}) {
1655+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
1656+
warn!("Ignoring unknown field in body: {}", path);
1657+
unused_elements.push(path.to_string());
1658+
};
1659+
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
16541660
Ok(param_xml_object) => param_xml_object,
16551661
Err(_) => None,
16561662
}
@@ -1714,10 +1720,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
17141720
let mut unused_elements = Vec::new();
17151721
let param_object_param: Option<models::ObjectParam> = if !body.is_empty() {
17161722
let deserializer = &mut serde_json::Deserializer::from_slice(&body);
1717-
match serde_ignored::deserialize(deserializer, |path| {
1718-
warn!("Ignoring unknown field in body: {}", path);
1719-
unused_elements.push(path.to_string());
1720-
}) {
1723+
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
1724+
warn!("Ignoring unknown field in body: {}", path);
1725+
unused_elements.push(path.to_string());
1726+
};
1727+
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
17211728
Ok(param_object_param) => param_object_param,
17221729
Err(e) => return Ok(Response::builder()
17231730
.status(StatusCode::BAD_REQUEST)

samples/server/petstore/rust-server/output/ops-v3/src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
178178
}
179179

180180
fn call(&mut self, target: Target) -> Self::Future {
181-
futures::future::ok(Service::new(
181+
future::ok(Service::new(
182182
self.api_impl.clone(),
183183
))
184184
}

0 commit comments

Comments
 (0)