Skip to content

Commit

Permalink
Fix #18572 rust server: Silence clippy lints by refactoring (#18575)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
myz-dev authored May 6, 2024
1 parent f145b89 commit b1fac19
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
}
fn call(&mut self, target: Target) -> Self::Future {
futures::future::ok(Service::new(
future::ok(Service::new(
self.api_impl.clone(),
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,11 @@
let deserializer = &mut serde_json::Deserializer::from_slice(&body);
{{/x-consumes-json}}
{{^x-consumes-plain-text}}
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
};
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(param_{{{paramName}}}) => param_{{{paramName}}},
{{#required}}
Err(e) => return Ok(Response::builder()
Expand Down Expand Up @@ -421,10 +422,11 @@
Some("{{{contentType}}}") if param_{{{paramName}}}.is_none() => {
// Extract JSON part.
let deserializer = &mut serde_json::Deserializer::from_slice(part.body.as_slice());
let json_data: {{dataType}} = match serde_ignored::deserialize(deserializer, |path| {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in JSON part: {}", path);
unused_elements.push(path.to_string());
}) {
};
let json_data: {{dataType}} = match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(json_data) => json_data,
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
}

fn call(&mut self, target: Target) -> Self::Future {
futures::future::ok(Service::new(
future::ok(Service::new(
self.api_impl.clone(),
))
}
Expand Down Expand Up @@ -206,10 +206,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
Some("application/json") if param_object_field.is_none() => {
// Extract JSON part.
let deserializer = &mut serde_json::Deserializer::from_slice(part.body.as_slice());
let json_data: models::MultipartRequestObjectField = match serde_ignored::deserialize(deserializer, |path| {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in JSON part: {}", path);
unused_elements.push(path.to_string());
}) {
};
let json_data: models::MultipartRequestObjectField = match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(json_data) => json_data,
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
}

fn call(&mut self, target: Target) -> Self::Future {
futures::future::ok(Service::new(
future::ok(Service::new(
self.api_impl.clone(),
))
}
Expand Down Expand Up @@ -150,10 +150,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
let mut unused_elements = Vec::new();
let param_op_get_request: Option<models::OpGetRequest> = if !body.is_empty() {
let deserializer = &mut serde_json::Deserializer::from_slice(&body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
};
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(param_op_get_request) => param_op_get_request,
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
}

fn call(&mut self, target: Target) -> Self::Future {
futures::future::ok(Service::new(
future::ok(Service::new(
self.api_impl.clone(),
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
}

fn call(&mut self, target: Target) -> Self::Future {
futures::future::ok(Service::new(
future::ok(Service::new(
self.api_impl.clone(),
))
}
Expand Down Expand Up @@ -1269,10 +1269,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
let mut unused_elements = Vec::new();
let param_object_untyped_props: Option<models::ObjectUntypedProps> = if !body.is_empty() {
let deserializer = &mut serde_json::Deserializer::from_slice(&body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
};
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(param_object_untyped_props) => param_object_untyped_props,
Err(_) => None,
}
Expand Down Expand Up @@ -1368,10 +1369,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
let mut unused_elements = Vec::new();
let param_duplicate_xml_object: Option<models::DuplicateXmlObject> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
};
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(param_duplicate_xml_object) => param_duplicate_xml_object,
Err(_) => None,
}
Expand Down Expand Up @@ -1435,10 +1437,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
let mut unused_elements = Vec::new();
let param_another_xml_object: Option<models::AnotherXmlObject> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
};
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(param_another_xml_object) => param_another_xml_object,
Err(_) => None,
}
Expand Down Expand Up @@ -1513,10 +1516,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
let mut unused_elements = Vec::new();
let param_another_xml_array: Option<models::AnotherXmlArray> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
};
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(param_another_xml_array) => param_another_xml_array,
Err(_) => None,
}
Expand Down Expand Up @@ -1580,10 +1584,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
let mut unused_elements = Vec::new();
let param_xml_array: Option<models::XmlArray> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
};
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(param_xml_array) => param_xml_array,
Err(_) => None,
}
Expand Down Expand Up @@ -1647,10 +1652,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
let mut unused_elements = Vec::new();
let param_xml_object: Option<models::XmlObject> = if !body.is_empty() {
let deserializer = &mut serde_xml_rs::de::Deserializer::new_from_reader(&*body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
};
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(param_xml_object) => param_xml_object,
Err(_) => None,
}
Expand Down Expand Up @@ -1714,10 +1720,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
let mut unused_elements = Vec::new();
let param_object_param: Option<models::ObjectParam> = if !body.is_empty() {
let deserializer = &mut serde_json::Deserializer::from_slice(&body);
match serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
}) {
let handle_unknown_field = |path: serde_ignored::Path<'_>| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
};
match serde_ignored::deserialize(deserializer, handle_unknown_field) {
Ok(param_object_param) => param_object_param,
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
}

fn call(&mut self, target: Target) -> Self::Future {
futures::future::ok(Service::new(
future::ok(Service::new(
self.api_impl.clone(),
))
}
Expand Down
Loading

0 comments on commit b1fac19

Please sign in to comment.