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`
This commit is contained in:
myz-dev
2024-05-06 06:24:33 +02:00
committed by GitHub
parent f145b8962d
commit b1fac19a75
10 changed files with 150 additions and 121 deletions

View File

@@ -92,7 +92,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(),
))
}
@@ -237,10 +237,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
let mut unused_elements = Vec::new();
let param_nested_response: Option<models::DummyPutRequest> = 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_nested_response) => param_nested_response,
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
@@ -547,10 +548,11 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
let mut unused_elements = Vec::new();
let param_value: Option<serde_json::Value> = 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_value) => param_value,
Err(e) => return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)