diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java index a05432b90031..f54e4936fe3f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java @@ -568,6 +568,7 @@ public class RustServerCodegen extends AbstractRustCodegen implements CodegenCon // basePath on the front. for (CodegenParameter param : op.pathParams) { // Replace {baseName} with (?P[^/?#]*) for regex + // TODO: Sanitize baseName to avoid using '-' (see clippy::invalid_regex) String paramSearch = "{" + param.baseName + "}"; String paramReplace = "(?P<" + param.baseName + ">[^/?#]*)"; diff --git a/modules/openapi-generator/src/main/resources/rust-server/client-callbacks.mustache b/modules/openapi-generator/src/main/resources/rust-server/client-callbacks.mustache index bafd04b1b771..44e16903d948 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/client-callbacks.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/client-callbacks.mustache @@ -49,7 +49,7 @@ pub struct ApiRequestParser; impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Option<&'static str> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); - match request.method() { + match *request.method() { {{#apiInfo}} {{#apis}} {{#operations}} @@ -58,7 +58,7 @@ impl RequestParser for ApiRequestParser { {{#urls}} {{#requests}} // {{{operationId}}} - {{{httpMethod}}} {{{path}}} - &hyper::Method::{{{vendorExtensions.x-http-method}}} if path.matched(paths::ID_{{{vendorExtensions.x-path-id}}}) => Some("{{{operationId}}}"), + hyper::Method::{{{vendorExtensions.x-http-method}}} if path.matched(paths::ID_{{{vendorExtensions.x-path-id}}}) => Some("{{{operationId}}}"), {{/requests}} {{/urls}} {{/callbacks}} diff --git a/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache b/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache index ca566860288f..a93adb61e0db 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache @@ -49,7 +49,7 @@ ¶m_{{{paramName}}}.iter().map(ToString::to_string).collect::>().join(",")); {{/isArray}} {{^isArray}} - ¶m_{{{paramName}}}.to_string()); + ¶m_{{{paramName}}}{{^isString}}.to_string(){{/isString}}); {{/isArray}} {{/x-consumes-json}} {{/vendorExtensions}} @@ -60,10 +60,8 @@ {{#authMethods}} {{#isApiKey}} {{#isKeyInQuery}} - if let Some(auth_data) = (context as &dyn Has>).get().as_ref() { - if let AuthData::ApiKey(ref api_key) = *auth_data { - query_string.append_pair("{{keyParamName}}", api_key); - } + if let Some(AuthData::ApiKey(ref api_key)) = (context as &dyn Has>).get().as_ref() { + query_string.append_pair("{{keyParamName}}", api_key); } {{/isKeyInQuery}} {{/isApiKey}} @@ -187,8 +185,8 @@ // no such boundary is used. let mut boundary = generate_boundary(); for b in boundary.iter_mut() { - if b == &('/' as u8) { - *b = '=' as u8; + if b == &(b'/') { + *b = b'='; } } @@ -257,7 +255,7 @@ {{/x-consumes-plain-text}} {{#required}} {{#x-consumes-xml}} - let body = param_{{{paramName}}}.to_xml(); + let body = param_{{{paramName}}}.as_xml(); {{/x-consumes-xml}} {{#x-consumes-json}} let body = serde_json::to_string(¶m_{{{paramName}}}).expect("impossible to fail to serialize"); @@ -266,7 +264,7 @@ {{^required}} let body = param_{{{paramName}}}.map(|ref body| { {{#x-consumes-xml}} - body.to_xml() + body.as_xml() {{/x-consumes-xml}} {{#x-consumes-json}} serde_json::to_string(body).expect("impossible to fail to serialize") @@ -305,8 +303,10 @@ }); {{#hasAuthMethods}} + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { {{#authMethods}} {{#isBasicBasic}} @@ -364,6 +364,7 @@ {{/required}} request.headers_mut().append( HeaderName::from_static("{{{nameInLowerCase}}}"), + #[allow(clippy::redundant_clone)] match header::IntoHeaderValue(param_{{{paramName}}}.clone()).try_into() { Ok(header) => header, Err(e) => { @@ -398,12 +399,11 @@ return Err(ApiError(format!("Invalid response header {{baseName}} for response {{code}} - {}", e))); }, }; - let response_{{{name}}} = response_{{{name}}}.0; {{#required}} - response_{{{name}}} + response_{{{name}}}.0 {{/required}} {{^required}} - Some(response_{{{name}}}) + Some(response_{{{name}}}.0) {{/required}} }, {{#required}} @@ -450,7 +450,7 @@ {{#headers}} {{#-first}} { - body: body, + body, {{/-first}} {{{name}}}: response_{{name}}, {{#-last}} diff --git a/modules/openapi-generator/src/main/resources/rust-server/context.mustache b/modules/openapi-generator/src/main/resources/rust-server/context.mustache index f3e1c5e130ac..4ec03e0d2e49 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/context.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/context.mustache @@ -110,7 +110,7 @@ impl Service> for AddContext(&headers) { + if let Some(basic) = swagger::auth::from_headers::(headers) { let auth_data = AuthData::Basic(basic); let context = context.push(Some(auth_data)); let context = context.push(None::); @@ -123,7 +123,7 @@ impl Service> for AddContext(&headers) { + if let Some(bearer) = swagger::auth::from_headers::(headers) { let auth_data = AuthData::Bearer(bearer); let context = context.push(Some(auth_data)); let context = context.push(None::); @@ -137,7 +137,7 @@ impl Service> for AddContext(&headers) { + if let Some(bearer) = swagger::auth::from_headers::(headers) { let auth_data = AuthData::Bearer(bearer); let context = context.push(Some(auth_data)); let context = context.push(None::); @@ -151,7 +151,7 @@ impl Service> for AddContext); @@ -165,7 +165,7 @@ impl Service> for AddContext::new( service diff --git a/modules/openapi-generator/src/main/resources/rust-server/lib.mustache b/modules/openapi-generator/src/main/resources/rust-server/lib.mustache index 7603c82c6ccd..c642b08a65fa 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/lib.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/lib.mustache @@ -1,5 +1,6 @@ #![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] -#![allow(unused_imports)] +#![allow(unused_imports, unused_attributes)] +#![allow(clippy::derive_partial_eq_without_eq, clippy::blacklisted_name)] use async_trait::async_trait; use futures::Stream; @@ -26,6 +27,7 @@ pub const API_VERSION: &str = "{{{.}}}"; {{/apiInfo}} /// API #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait Api { fn poll_ready(&self, _cx: &mut Context) -> Poll>> { Poll::Ready(Ok(())) @@ -53,6 +55,7 @@ pub trait Api { /// API where `Context` isn't passed on every API call #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait ApiNoContext { fn poll_ready(&self, _cx: &mut Context) -> Poll>>; @@ -223,7 +226,7 @@ pub trait CallbackApiNoContext { pub trait CallbackContextWrapperExt where Self: Sized { /// Binds this API to a context. - fn with_context(self: Self, context: C) -> ContextWrapper; + fn with_context(self, context: C) -> ContextWrapper; } impl + Send + Sync, C: Clone + Send + Sync> CallbackContextWrapperExt for T { diff --git a/modules/openapi-generator/src/main/resources/rust-server/models.mustache b/modules/openapi-generator/src/main/resources/rust-server/models.mustache index b31967003805..30be5a54f35f 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/models.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/models.mustache @@ -33,7 +33,7 @@ impl std::fmt::Display for {{{classname}}} { match *self { {{#allowableValues}} {{#enumVars}} - {{{classname}}}::{{{name}}} => write!(f, "{}", {{{value}}}), + {{{classname}}}::{{{name}}} => write!(f, {{{value}}}), {{/enumVars}} {{/allowableValues}} } @@ -189,7 +189,7 @@ impl<'a> std::iter::IntoIterator for &'a {{{classname}}} { type IntoIter = std::slice::Iter<'a, {{{arrayModelType}}}>; fn into_iter(self) -> Self::IntoIter { - (&self.0).into_iter() + (&self.0).iter() } } @@ -198,7 +198,7 @@ impl<'a> std::iter::IntoIterator for &'a mut {{{classname}}} { type IntoIter = std::slice::IterMut<'a, {{{arrayModelType}}}>; fn into_iter(self) -> Self::IntoIter { - (&mut self.0).into_iter() + (&mut self.0).iter_mut() } } @@ -220,7 +220,7 @@ impl std::ops::DerefMut for {{{classname}}} { /// Should be implemented in a serde serializer impl std::string::ToString for {{{classname}}} { fn to_string(&self) -> String { - self.iter().map(|x| x.to_string()).collect::>().join(",").to_string() + self.iter().map(|x| x.to_string()).collect::>().join(",") } } @@ -274,9 +274,10 @@ pub struct {{{classname}}} { } impl {{{classname}}} { + #[allow(clippy::new_without_default)] pub fn new({{#vars}}{{^defaultValue}}{{{name}}}: {{#isNullable}}swagger::Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}, {{/defaultValue}}{{/vars}}) -> {{{classname}}} { {{{classname}}} { -{{#vars}} {{{name}}}: {{{defaultValue}}}{{^defaultValue}}{{{name}}}{{/defaultValue}}, +{{#vars}} {{#defaultValue}}{{{name}}}: {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}{{{name}}}{{/defaultValue}}, {{/vars}} } } @@ -287,64 +288,68 @@ impl {{{classname}}} { /// Should be implemented in a serde serializer impl std::string::ToString for {{{classname}}} { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ {{#vars}} {{#isByteArray}} - // Skipping {{baseName}} in query parameter serialization + // Skipping {{baseName}} in query parameter serialization {{/isByteArray}} {{#isBinary}} - // Skipping {{baseName}} in query parameter serialization + // Skipping {{baseName}} in query parameter serialization {{/isBinary}} {{#isMap}} - // Skipping {{baseName}} in query parameter serialization + // Skipping {{baseName}} in query parameter serialization {{/isMap}} {{^isPrimitiveType}} - // Skipping {{baseName}} in query parameter serialization + // Skipping {{baseName}} in query parameter serialization {{/isPrimitiveType}} {{^isByteArray}}{{^isBinary}}{{^isMap}}{{#isPrimitiveType}} {{#required}} - params.push("{{{baseName}}}".to_string()); + Some("{{{baseName}}}".to_string()), {{^isArray}} {{#isNullable}} - params.push(self.{{{name}}}.as_ref().map_or("null".to_string(), |x| x.to_string())); + Some(self.{{{name}}}.as_ref().map_or("null".to_string(), |x| x.to_string())), {{/isNullable}} {{^isNullable}} - params.push(self.{{{name}}}.to_string()); + Some(self.{{{name}}}.to_string()), {{/isNullable}} {{/isArray}} {{#isArray}} {{#isNullable}} - params.push(self.{{{name}}}.as_ref().map_or(vec!["null".to_string()], |x| x.iter().map(|x| x.to_string()).collect::>().join(",").to_string())); + Some(self.{{{name}}}.as_ref().map_or(vec!["null".to_string()], |x| x.iter().map(|x| x.to_string()).collect::>().join(","))), {{/isNullable}} {{^isNullable}} - params.push(self.{{{name}}}.iter().map(|x| x.to_string()).collect::>().join(",").to_string()); + Some(self.{{{name}}}.iter().map(|x| x.to_string()).collect::>().join(",")), {{/isNullable}} {{/isArray}} {{/required}} {{^required}} - if let Some(ref {{{name}}}) = self.{{{name}}} { - params.push("{{{baseName}}}".to_string()); + self.{{{name}}}.as_ref().map(|{{{name}}}| { + vec![ + "{{{baseName}}}".to_string(), {{^isArray}} {{#isNullable}} - params.push({{{name}}}.as_ref().map_or("null".to_string(), |x| x.to_string())); + {{{name}}}.as_ref().map_or("null".to_string(), |x| x.to_string()), {{/isNullable}} {{^isNullable}} - params.push({{{name}}}.to_string()); + {{{name}}}.to_string(), {{/isNullable}} {{/isArray}} {{#isArray}} {{#isNullable}} - params.push({{{name}}}.as_ref().map_or("null".to_string(), |x| x.iter().map(|x| x.to_string()).collect::>().join(",").to_string())); + {{{name}}}.as_ref().map_or("null".to_string(), |x| x.iter().map(|x| x.to_string()).collect::>().join(",")), {{/isNullable}} {{^isNullable}} - params.push({{{name}}}.iter().map(|x| x.to_string()).collect::>().join(",").to_string()); + {{{name}}}.iter().map(|x| x.to_string()).collect::>().join(","), {{/isNullable}} {{/isArray}} - } + ].join(",") + }), {{/required}} {{/isPrimitiveType}}{{/isMap}}{{/isBinary}}{{/isByteArray}} {{/vars}} - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -355,8 +360,9 @@ impl std::str::FromStr for {{{classname}}} { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { {{#vars}} pub {{{name}}}: Vec<{{{dataType}}}>, @@ -366,7 +372,7 @@ impl std::str::FromStr for {{{classname}}} { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -376,6 +382,7 @@ impl std::str::FromStr for {{{classname}}} { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { {{#vars}} {{#isBinary}} @@ -394,7 +401,8 @@ impl std::str::FromStr for {{{classname}}} { "{{{baseName}}}" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in {{{classname}}}".to_string()), {{/isNullable}} {{^isNullable}} - "{{{baseName}}}" => intermediate_rep.{{{name}}}.push(<{{{dataType}}} as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "{{{baseName}}}" => intermediate_rep.{{{name}}}.push(<{{{dataType}}} as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?), {{/isNullable}} {{/isContainer}} {{/isByteArray}} @@ -415,7 +423,7 @@ impl std::str::FromStr for {{{classname}}} { {{{name}}}: std::result::Result::Err("Nullable types not supported in {{{classname}}}".to_string())?, {{/isNullable}} {{^isNullable}} - {{{name}}}: intermediate_rep.{{{name}}}.into_iter().next(){{#required}}.ok_or("{{{baseName}}} missing in {{{classname}}}".to_string())?{{/required}}, + {{{name}}}: intermediate_rep.{{{name}}}.into_iter().next(){{#required}}.ok_or_else(|| "{{{baseName}}} missing in {{{classname}}}".to_string())?{{/required}}, {{/isNullable}} {{/vars}} }) @@ -479,7 +487,7 @@ impl {{{classname}}} { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { {{#xmlNamespace}} let mut namespaces = std::collections::BTreeMap::new(); // An empty string is used to indicate a global namespace in xmltree. diff --git a/modules/openapi-generator/src/main/resources/rust-server/server-mod.mustache b/modules/openapi-generator/src/main/resources/rust-server/server-mod.mustache index d38f3b5b3dae..08e63ca087e3 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/server-mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/server-mod.mustache @@ -28,13 +28,13 @@ pub struct ApiRequestParser; impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Option<&'static str> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); - match request.method() { + match *request.method() { {{#apiInfo}} {{#apis}} {{#operations}} {{#operation}} // {{{operationId}}} - {{{httpMethod}}} {{{path}}} - &hyper::Method::{{{vendorExtensions.x-http-method}}} if path.matched(paths::ID_{{{vendorExtensions.x-path-id}}}) => Some("{{{operationId}}}"), + hyper::Method::{{{vendorExtensions.x-http-method}}} if path.matched(paths::ID_{{{vendorExtensions.x-path-id}}}) => Some("{{{operationId}}}"), {{/operation}} {{/operations}} {{/apis}} diff --git a/modules/openapi-generator/src/main/resources/rust-server/server-operation.mustache b/modules/openapi-generator/src/main/resources/rust-server/server-operation.mustache index 0560d72e7dbe..a8ac8bbc8021 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/server-operation.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/server-operation.mustache @@ -1,10 +1,10 @@ // {{{operationId}}} - {{{httpMethod}}} {{{path}}} - &hyper::Method::{{vendorExtensions.x-http-method}} if path.matched(paths::ID_{{vendorExtensions.x-path-id}}) => { + hyper::Method::{{vendorExtensions.x-http-method}} if path.matched(paths::ID_{{vendorExtensions.x-path-id}}) => { {{#hasAuthMethods}} { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -50,10 +50,10 @@ {{/x-consumes-multipart}} {{#x-has-path-params}} // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_{{{x-path-id}}} - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE {{{x-path-id}}} in set but failed match against \"{}\"", path, paths::REGEX_{{{x-path-id}}}.as_str()) ); @@ -139,7 +139,7 @@ {{/required}} {{/vendorExtensions.x-consumes-json}} {{#vendorExtensions.x-consumes-json}} - .nth(0); + .next(); let param_{{{paramName}}} = match param_{{{paramName}}} { Some(param_{{{paramName}}}) => { let param_{{{paramName}}} = @@ -167,7 +167,7 @@ {{/vendorExtensions.x-consumes-json}} {{/isArray}} {{^isArray}} - .nth(0); + .next(); let param_{{{paramName}}} = match param_{{{paramName}}} { Some(param_{{{paramName}}}) => { let param_{{{paramName}}} = @@ -292,7 +292,7 @@ _ => { return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Unable to process all message parts"))) + .body(Body::from("Unable to process all message parts".to_string())) .expect("Unable to create Bad Request response due to failure to process all message")) }, }; @@ -335,7 +335,7 @@ return Ok( Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Missing required form parameter {{{paramName}}}"))) + .body(Body::from("Missing required form parameter {{{paramName}}}".to_string())) .expect("Unable to create Bad Request due to missing required form parameter {{{paramName}}}")) {{/required}} {{^required}} @@ -378,9 +378,9 @@ // Extract the top-level content type header. let content_type_mime = headers .get(CONTENT_TYPE) - .ok_or("Missing content-type header".to_string()) + .ok_or_else(|| "Missing content-type header".to_string()) .and_then(|v| v.to_str().map_err(|e| format!("Couldn't read content-type header value for {{operationId}}: {}", e))) - .and_then(|v| v.parse::().map_err(|_e| format!("Couldn't parse content-type header value for {{operationId}}"))); + .and_then(|v| v.parse::().map_err(|_e| "Couldn't parse content-type header value for {{operationId}}".to_string())); // Insert top-level content type header into a Headers object. let mut multi_part_headers = Headers::new(); @@ -415,7 +415,7 @@ for node in nodes { if let Node::Part(part) = node { let content_type = part.content_type().map(|x| format!("{}",x)); - match content_type.as_ref().map(|x| x.as_str()) { + match content_type.as_deref() { {{#formParams}} {{^isBinary}} Some("{{{contentType}}}") if param_{{{paramName}}}.is_none() => { @@ -464,7 +464,7 @@ Some(x) => x, None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Missing required multipart/related parameter {{{paramName}}}"))) + .body(Body::from("Missing required multipart/related parameter {{{paramName}}}".to_string())) .expect("Unable to create Bad Request response for missing multipart/related parameter {{{paramName}}} due to schema")) }; {{/required}} @@ -488,7 +488,7 @@ let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); {{#bodyParams}} @@ -641,7 +641,7 @@ }, Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Couldn't read multipart body"))) + .body(Body::from("Couldn't read multipart body".to_string())) .expect("Unable to create Bad Request response due to unable read multipart body")), } {{/vendorExtensions}} diff --git a/modules/openapi-generator/src/main/resources/rust-server/server-paths.mustache b/modules/openapi-generator/src/main/resources/rust-server/server-paths.mustache index 2930a49e1633..c5297d058d26 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/server-paths.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/server-paths.mustache @@ -14,6 +14,7 @@ mod paths { {{#hasPathParams}} lazy_static! { pub static ref REGEX_{{{PATH_ID}}}: regex::Regex = + #[allow(clippy::invalid_regex)] regex::Regex::new(r"^{{{basePathWithoutHost}}}{{{pathRegEx}}}") .expect("Unable to create regex for {{{PATH_ID}}}"); } diff --git a/modules/openapi-generator/src/main/resources/rust-server/server-service-header.mustache b/modules/openapi-generator/src/main/resources/rust-server/server-service-header.mustache index 76c0e9a85406..01fde31fa1e4 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/server-service-header.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/server-service-header.mustache @@ -20,7 +20,7 @@ impl Service where { pub fn new(api_impl: T) -> Self { Service { - api_impl: api_impl, + api_impl, marker: PhantomData } } @@ -33,7 +33,7 @@ impl Clone for Service where fn clone(&self) -> Self { Service { api_impl: self.api_impl.clone(), - marker: self.marker.clone(), + marker: self.marker, } } } @@ -63,4 +63,4 @@ impl hyper::service::Service<(Request, C)> for Service where This match statement is duplicated below in `parse_operation_id()`. Please update both places if changing how this code is autogenerated. }} - match &method { + match method { diff --git a/samples/server/petstore/rust-server/.cargo/config b/samples/server/petstore/rust-server/.cargo/config new file mode 100644 index 000000000000..b8acc9c00c8c --- /dev/null +++ b/samples/server/petstore/rust-server/.cargo/config @@ -0,0 +1,18 @@ +[build] +rustflags = [ + "-W", "missing_docs", # detects missing documentation for public members + + "-W", "trivial_casts", # detects trivial casts which could be removed + + "-W", "trivial_numeric_casts", # detects trivial casts of numeric types which could be removed + + "-W", "unsafe_code", # usage of `unsafe` code + + "-W", "unused_qualifications", # detects unnecessarily qualified names + + "-W", "unused_extern_crates", # extern crates that are never used + + "-W", "unused_import_braces", # unnecessary braces around an imported item + + "-D", "warnings", # all warnings should be denied +] diff --git a/samples/server/petstore/rust-server/output/multipart-v3/examples/server/server.rs b/samples/server/petstore/rust-server/output/multipart-v3/examples/server/server.rs index 892a189b8efc..a031eb139ca8 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/multipart-v3/examples/server/server.rs @@ -32,6 +32,7 @@ pub async fn create(addr: &str, https: bool) { let service = MakeAllowAllAuthenticator::new(service, "cosmo"); + #[allow(unused_mut)] let mut service = multipart_v3::server::context::MakeAddContext::<_, EmptyContext>::new( service diff --git a/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs index bd02a236767c..eaea306af10e 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs @@ -429,8 +429,8 @@ impl Api for Client where // no such boundary is used. let mut boundary = generate_boundary(); for b in boundary.iter_mut() { - if b == &('/' as u8) { - *b = '=' as u8; + if b == &(b'/') { + *b = b'='; } } @@ -722,8 +722,8 @@ impl Api for Client where // no such boundary is used. let mut boundary = generate_boundary(); for b in boundary.iter_mut() { - if b == &('/' as u8) { - *b = '=' as u8; + if b == &(b'/') { + *b = b'='; } } diff --git a/samples/server/petstore/rust-server/output/multipart-v3/src/lib.rs b/samples/server/petstore/rust-server/output/multipart-v3/src/lib.rs index 8d8eb9a4ba39..b1c50ab40a6f 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/src/lib.rs +++ b/samples/server/petstore/rust-server/output/multipart-v3/src/lib.rs @@ -1,5 +1,6 @@ #![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] -#![allow(unused_imports)] +#![allow(unused_imports, unused_attributes)] +#![allow(clippy::derive_partial_eq_without_eq, clippy::blacklisted_name)] use async_trait::async_trait; use futures::Stream; @@ -33,6 +34,7 @@ pub enum MultipleIdenticalMimeTypesPostResponse { /// API #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait Api { fn poll_ready(&self, _cx: &mut Context) -> Poll>> { Poll::Ready(Ok(())) @@ -63,6 +65,7 @@ pub trait Api { /// API where `Context` isn't passed on every API call #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait ApiNoContext { fn poll_ready(&self, _cx: &mut Context) -> Poll>>; diff --git a/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs b/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs index ca528ed40acc..f94163d91064 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs +++ b/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs @@ -21,11 +21,12 @@ pub struct MultipartRelatedRequest { } impl MultipartRelatedRequest { + #[allow(clippy::new_without_default)] pub fn new(required_binary_field: swagger::ByteArray, ) -> MultipartRelatedRequest { MultipartRelatedRequest { object_field: None, optional_binary_field: None, - required_binary_field: required_binary_field, + required_binary_field, } } } @@ -35,16 +36,18 @@ impl MultipartRelatedRequest { /// Should be implemented in a serde serializer impl std::string::ToString for MultipartRelatedRequest { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - // Skipping object_field in query parameter serialization + let params: Vec> = vec![ + // Skipping object_field in query parameter serialization - // Skipping optional_binary_field in query parameter serialization - // Skipping optional_binary_field in query parameter serialization + // Skipping optional_binary_field in query parameter serialization + // Skipping optional_binary_field in query parameter serialization - // Skipping required_binary_field in query parameter serialization - // Skipping required_binary_field in query parameter serialization + // Skipping required_binary_field in query parameter serialization + // Skipping required_binary_field in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -55,8 +58,9 @@ impl std::str::FromStr for MultipartRelatedRequest { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub object_field: Vec, pub optional_binary_field: Vec, @@ -66,7 +70,7 @@ impl std::str::FromStr for MultipartRelatedRequest { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -76,8 +80,10 @@ impl std::str::FromStr for MultipartRelatedRequest { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "object_field" => intermediate_rep.object_field.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "object_field" => intermediate_rep.object_field.push(::from_str(val).map_err(|x| x.to_string())?), "optional_binary_field" => return std::result::Result::Err("Parsing binary data in this style is not supported in MultipartRelatedRequest".to_string()), "required_binary_field" => return std::result::Result::Err("Parsing binary data in this style is not supported in MultipartRelatedRequest".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing MultipartRelatedRequest".to_string()) @@ -92,7 +98,7 @@ impl std::str::FromStr for MultipartRelatedRequest { std::result::Result::Ok(MultipartRelatedRequest { object_field: intermediate_rep.object_field.into_iter().next(), optional_binary_field: intermediate_rep.optional_binary_field.into_iter().next(), - required_binary_field: intermediate_rep.required_binary_field.into_iter().next().ok_or("required_binary_field missing in MultipartRelatedRequest".to_string())?, + required_binary_field: intermediate_rep.required_binary_field.into_iter().next().ok_or_else(|| "required_binary_field missing in MultipartRelatedRequest".to_string())?, }) } } @@ -149,9 +155,10 @@ pub struct MultipartRequestObjectField { } impl MultipartRequestObjectField { + #[allow(clippy::new_without_default)] pub fn new(field_a: String, ) -> MultipartRequestObjectField { MultipartRequestObjectField { - field_a: field_a, + field_a, field_b: None, } } @@ -162,18 +169,22 @@ impl MultipartRequestObjectField { /// Should be implemented in a serde serializer impl std::string::ToString for MultipartRequestObjectField { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - params.push("field_a".to_string()); - params.push(self.field_a.to_string()); + Some("field_a".to_string()), + Some(self.field_a.to_string()), - if let Some(ref field_b) = self.field_b { - params.push("field_b".to_string()); - params.push(field_b.iter().map(|x| x.to_string()).collect::>().join(",").to_string()); - } + self.field_b.as_ref().map(|field_b| { + vec![ + "field_b".to_string(), + field_b.iter().map(|x| x.to_string()).collect::>().join(","), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -184,8 +195,9 @@ impl std::str::FromStr for MultipartRequestObjectField { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub field_a: Vec, pub field_b: Vec>, @@ -194,7 +206,7 @@ impl std::str::FromStr for MultipartRequestObjectField { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -204,8 +216,10 @@ impl std::str::FromStr for MultipartRequestObjectField { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "field_a" => intermediate_rep.field_a.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "field_a" => intermediate_rep.field_a.push(::from_str(val).map_err(|x| x.to_string())?), "field_b" => return std::result::Result::Err("Parsing a container in this style is not supported in MultipartRequestObjectField".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing MultipartRequestObjectField".to_string()) } @@ -217,7 +231,7 @@ impl std::str::FromStr for MultipartRequestObjectField { // Use the intermediate representation to return the struct std::result::Result::Ok(MultipartRequestObjectField { - field_a: intermediate_rep.field_a.into_iter().next().ok_or("field_a missing in MultipartRequestObjectField".to_string())?, + field_a: intermediate_rep.field_a.into_iter().next().ok_or_else(|| "field_a missing in MultipartRequestObjectField".to_string())?, field_b: intermediate_rep.field_b.into_iter().next(), }) } @@ -276,6 +290,7 @@ pub struct MultipleIdenticalMimeTypesPostRequest { } impl MultipleIdenticalMimeTypesPostRequest { + #[allow(clippy::new_without_default)] pub fn new() -> MultipleIdenticalMimeTypesPostRequest { MultipleIdenticalMimeTypesPostRequest { binary1: None, @@ -289,14 +304,16 @@ impl MultipleIdenticalMimeTypesPostRequest { /// Should be implemented in a serde serializer impl std::string::ToString for MultipleIdenticalMimeTypesPostRequest { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - // Skipping binary1 in query parameter serialization - // Skipping binary1 in query parameter serialization + let params: Vec> = vec![ + // Skipping binary1 in query parameter serialization + // Skipping binary1 in query parameter serialization - // Skipping binary2 in query parameter serialization - // Skipping binary2 in query parameter serialization + // Skipping binary2 in query parameter serialization + // Skipping binary2 in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -307,8 +324,9 @@ impl std::str::FromStr for MultipleIdenticalMimeTypesPostRequest { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub binary1: Vec, pub binary2: Vec, @@ -317,7 +335,7 @@ impl std::str::FromStr for MultipleIdenticalMimeTypesPostRequest { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -327,6 +345,7 @@ impl std::str::FromStr for MultipleIdenticalMimeTypesPostRequest { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { "binary1" => return std::result::Result::Err("Parsing binary data in this style is not supported in MultipleIdenticalMimeTypesPostRequest".to_string()), "binary2" => return std::result::Result::Err("Parsing binary data in this style is not supported in MultipleIdenticalMimeTypesPostRequest".to_string()), diff --git a/samples/server/petstore/rust-server/output/multipart-v3/src/server/mod.rs b/samples/server/petstore/rust-server/output/multipart-v3/src/server/mod.rs index 3330f2236215..c3ab4bd0e641 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/multipart-v3/src/server/mod.rs @@ -109,7 +109,7 @@ impl Service where { pub fn new(api_impl: T) -> Self { Service { - api_impl: api_impl, + api_impl, marker: PhantomData } } @@ -122,7 +122,7 @@ impl Clone for Service where fn clone(&self) -> Self { Service { api_impl: self.api_impl.clone(), - marker: self.marker.clone(), + marker: self.marker, } } } @@ -148,10 +148,10 @@ impl hyper::service::Service<(Request, C)> for Service where let (method, uri, headers) = (parts.method, parts.uri, parts.headers); let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); - match &method { + match method { // MultipartRelatedRequestPost - POST /multipart_related_request - &hyper::Method::POST if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => { + hyper::Method::POST if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -165,9 +165,9 @@ impl hyper::service::Service<(Request, C)> for Service where // Extract the top-level content type header. let content_type_mime = headers .get(CONTENT_TYPE) - .ok_or("Missing content-type header".to_string()) + .ok_or_else(|| "Missing content-type header".to_string()) .and_then(|v| v.to_str().map_err(|e| format!("Couldn't read content-type header value for MultipartRelatedRequestPost: {}", e))) - .and_then(|v| v.parse::().map_err(|_e| format!("Couldn't parse content-type header value for MultipartRelatedRequestPost"))); + .and_then(|v| v.parse::().map_err(|_e| "Couldn't parse content-type header value for MultipartRelatedRequestPost".to_string())); // Insert top-level content type header into a Headers object. let mut multi_part_headers = Headers::new(); @@ -202,7 +202,7 @@ impl hyper::service::Service<(Request, C)> for Service where for node in nodes { if let Node::Part(part) = node { let content_type = part.content_type().map(|x| format!("{}",x)); - match content_type.as_ref().map(|x| x.as_str()) { + match content_type.as_deref() { Some("application/json") if param_object_field.is_none() => { // Extract JSON part. let deserializer = &mut serde_json::Deserializer::from_slice(part.body.as_slice()); @@ -244,7 +244,7 @@ impl hyper::service::Service<(Request, C)> for Service where Some(x) => x, None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Missing required multipart/related parameter required_binary_field"))) + .body(Body::from("Missing required multipart/related parameter required_binary_field".to_string())) .expect("Unable to create Bad Request response for missing multipart/related parameter required_binary_field due to schema")) }; @@ -257,7 +257,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -285,7 +285,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // MultipartRequestPost - POST /multipart_request - &hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => { + hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => { let boundary = match swagger::multipart::form::boundary(&headers) { Some(boundary) => boundary.to_string(), None => return Ok(Response::builder() @@ -310,7 +310,7 @@ impl hyper::service::Service<(Request, C)> for Service where _ => { return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Unable to process all message parts"))) + .body(Body::from("Unable to process all message parts".to_string())) .expect("Unable to create Bad Request response due to failure to process all message")) }, }; @@ -336,7 +336,7 @@ impl hyper::service::Service<(Request, C)> for Service where return Ok( Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Missing required form parameter string_field"))) + .body(Body::from("Missing required form parameter string_field".to_string())) .expect("Unable to create Bad Request due to missing required form parameter string_field")) } }; @@ -400,7 +400,7 @@ impl hyper::service::Service<(Request, C)> for Service where return Ok( Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Missing required form parameter binary_field"))) + .body(Body::from("Missing required form parameter binary_field".to_string())) .expect("Unable to create Bad Request due to missing required form parameter binary_field")) } }; @@ -414,7 +414,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -436,13 +436,13 @@ impl hyper::service::Service<(Request, C)> for Service where }, Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Couldn't read multipart body"))) + .body(Body::from("Couldn't read multipart body".to_string())) .expect("Unable to create Bad Request response due to unable read multipart body")), } }, // MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types - &hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => { + hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -456,9 +456,9 @@ impl hyper::service::Service<(Request, C)> for Service where // Extract the top-level content type header. let content_type_mime = headers .get(CONTENT_TYPE) - .ok_or("Missing content-type header".to_string()) + .ok_or_else(|| "Missing content-type header".to_string()) .and_then(|v| v.to_str().map_err(|e| format!("Couldn't read content-type header value for MultipleIdenticalMimeTypesPost: {}", e))) - .and_then(|v| v.parse::().map_err(|_e| format!("Couldn't parse content-type header value for MultipleIdenticalMimeTypesPost"))); + .and_then(|v| v.parse::().map_err(|_e| "Couldn't parse content-type header value for MultipleIdenticalMimeTypesPost".to_string())); // Insert top-level content type header into a Headers object. let mut multi_part_headers = Headers::new(); @@ -492,7 +492,7 @@ impl hyper::service::Service<(Request, C)> for Service where for node in nodes { if let Node::Part(part) = node { let content_type = part.content_type().map(|x| format!("{}",x)); - match content_type.as_ref().map(|x| x.as_str()) { + match content_type.as_deref() { Some("application/octet-stream") if param_binary1.is_none() => { param_binary1.get_or_insert(swagger::ByteArray(part.body)); }, @@ -523,7 +523,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -565,13 +565,13 @@ pub struct ApiRequestParser; impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Option<&'static str> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); - match request.method() { + match *request.method() { // MultipartRelatedRequestPost - POST /multipart_related_request - &hyper::Method::POST if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => Some("MultipartRelatedRequestPost"), + hyper::Method::POST if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => Some("MultipartRelatedRequestPost"), // MultipartRequestPost - POST /multipart_request - &hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => Some("MultipartRequestPost"), + hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => Some("MultipartRequestPost"), // MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types - &hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => Some("MultipleIdenticalMimeTypesPost"), + hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => Some("MultipleIdenticalMimeTypesPost"), _ => None, } } diff --git a/samples/server/petstore/rust-server/output/no-example-v3/examples/server/server.rs b/samples/server/petstore/rust-server/output/no-example-v3/examples/server/server.rs index 3bc8fa48fe23..55f8d608b52e 100644 --- a/samples/server/petstore/rust-server/output/no-example-v3/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/no-example-v3/examples/server/server.rs @@ -32,6 +32,7 @@ pub async fn create(addr: &str, https: bool) { let service = MakeAllowAllAuthenticator::new(service, "cosmo"); + #[allow(unused_mut)] let mut service = no_example_v3::server::context::MakeAddContext::<_, EmptyContext>::new( service diff --git a/samples/server/petstore/rust-server/output/no-example-v3/src/lib.rs b/samples/server/petstore/rust-server/output/no-example-v3/src/lib.rs index 398896f52072..05aca2b05b4e 100644 --- a/samples/server/petstore/rust-server/output/no-example-v3/src/lib.rs +++ b/samples/server/petstore/rust-server/output/no-example-v3/src/lib.rs @@ -1,5 +1,6 @@ #![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] -#![allow(unused_imports)] +#![allow(unused_imports, unused_attributes)] +#![allow(clippy::derive_partial_eq_without_eq, clippy::blacklisted_name)] use async_trait::async_trait; use futures::Stream; @@ -21,6 +22,7 @@ pub enum OpGetResponse { /// API #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait Api { fn poll_ready(&self, _cx: &mut Context) -> Poll>> { Poll::Ready(Ok(())) @@ -35,6 +37,7 @@ pub trait Api { /// API where `Context` isn't passed on every API call #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait ApiNoContext { fn poll_ready(&self, _cx: &mut Context) -> Poll>>; diff --git a/samples/server/petstore/rust-server/output/no-example-v3/src/models.rs b/samples/server/petstore/rust-server/output/no-example-v3/src/models.rs index fa170060bd96..cc90dcda97e5 100644 --- a/samples/server/petstore/rust-server/output/no-example-v3/src/models.rs +++ b/samples/server/petstore/rust-server/output/no-example-v3/src/models.rs @@ -14,6 +14,7 @@ pub struct OpGetRequest { } impl OpGetRequest { + #[allow(clippy::new_without_default)] pub fn new() -> OpGetRequest { OpGetRequest { propery: None, @@ -26,14 +27,18 @@ impl OpGetRequest { /// Should be implemented in a serde serializer impl std::string::ToString for OpGetRequest { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref propery) = self.propery { - params.push("propery".to_string()); - params.push(propery.to_string()); - } + self.propery.as_ref().map(|propery| { + vec![ + "propery".to_string(), + propery.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -44,8 +49,9 @@ impl std::str::FromStr for OpGetRequest { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub propery: Vec, } @@ -53,7 +59,7 @@ impl std::str::FromStr for OpGetRequest { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -63,8 +69,10 @@ impl std::str::FromStr for OpGetRequest { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "propery" => intermediate_rep.propery.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "propery" => intermediate_rep.propery.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing OpGetRequest".to_string()) } } diff --git a/samples/server/petstore/rust-server/output/no-example-v3/src/server/mod.rs b/samples/server/petstore/rust-server/output/no-example-v3/src/server/mod.rs index c8cced13d34d..6bd3627a9164 100644 --- a/samples/server/petstore/rust-server/output/no-example-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/no-example-v3/src/server/mod.rs @@ -98,7 +98,7 @@ impl Service where { pub fn new(api_impl: T) -> Self { Service { - api_impl: api_impl, + api_impl, marker: PhantomData } } @@ -111,7 +111,7 @@ impl Clone for Service where fn clone(&self) -> Self { Service { api_impl: self.api_impl.clone(), - marker: self.marker.clone(), + marker: self.marker, } } } @@ -137,10 +137,10 @@ impl hyper::service::Service<(Request, C)> for Service where let (method, uri, headers) = (parts.method, parts.uri, parts.headers); let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); - match &method { + match method { // OpGet - GET /op - &hyper::Method::GET if path.matched(paths::ID_OP) => { + hyper::Method::GET if path.matched(paths::ID_OP) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -178,7 +178,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -225,9 +225,9 @@ pub struct ApiRequestParser; impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Option<&'static str> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); - match request.method() { + match *request.method() { // OpGet - GET /op - &hyper::Method::GET if path.matched(paths::ID_OP) => Some("OpGet"), + hyper::Method::GET if path.matched(paths::ID_OP) => Some("OpGet"), _ => None, } } diff --git a/samples/server/petstore/rust-server/output/openapi-v3/examples/client/server.rs b/samples/server/petstore/rust-server/output/openapi-v3/examples/client/server.rs index fab67f0476b1..a66747e42db8 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/examples/client/server.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/examples/client/server.rs @@ -32,6 +32,7 @@ pub async fn create(addr: &str, https: bool) { let service = MakeAllowAllAuthenticator::new(service, "cosmo"); + #[allow(unused_mut)] let mut service = openapi_v3::server::context::MakeAddContext::<_, EmptyContext>::new( service diff --git a/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs b/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs index e2d19e2266c0..1fde6bbdf1e6 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs @@ -32,6 +32,7 @@ pub async fn create(addr: &str, https: bool) { let service = MakeAllowAllAuthenticator::new(service, "cosmo"); + #[allow(unused_mut)] let mut service = openapi_v3::server::context::MakeAddContext::<_, EmptyContext>::new( service diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/client/callbacks.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/client/callbacks.rs index 082ae5911b1c..3f3d2b0cf82f 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/client/callbacks.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/client/callbacks.rs @@ -38,12 +38,14 @@ mod paths { pub(crate) static ID_REQUEST_QUERY_URL_CALLBACK: usize = 0; lazy_static! { pub static ref REGEX_REQUEST_QUERY_URL_CALLBACK: regex::Regex = + #[allow(clippy::invalid_regex)] regex::Regex::new(r"^/(?P.*)/callback$") .expect("Unable to create regex for REQUEST_QUERY_URL_CALLBACK"); } pub(crate) static ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER: usize = 1; lazy_static! { pub static ref REGEX_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER: regex::Regex = + #[allow(clippy::invalid_regex)] regex::Regex::new(r"^/(?P.*)/callback-with-header$") .expect("Unable to create regex for REQUEST_QUERY_URL_CALLBACK_WITH_HEADER"); } @@ -112,7 +114,7 @@ impl Service where { pub fn new(api_impl: T) -> Self { Service { - api_impl: api_impl, + api_impl, marker: PhantomData } } @@ -125,7 +127,7 @@ impl Clone for Service where fn clone(&self) -> Self { Service { api_impl: self.api_impl.clone(), - marker: self.marker.clone(), + marker: self.marker, } } } @@ -151,15 +153,15 @@ impl hyper::service::Service<(Request, C)> for Service where let (method, uri, headers) = (parts.method, parts.uri, parts.headers); let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); - match &method { + match method { // CallbackCallbackWithHeaderPost - POST /{$request.query.url}/callback-with-header - &hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER) => { + hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER) => { // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE REQUEST_QUERY_URL_CALLBACK_WITH_HEADER in set but failed match against \"{}\"", path, paths::REGEX_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER.as_str()) ); @@ -193,7 +195,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -215,12 +217,12 @@ impl hyper::service::Service<(Request, C)> for Service where }, // CallbackCallbackPost - POST /{$request.query.url}/callback - &hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => { + hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => { // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_REQUEST_QUERY_URL_CALLBACK - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE REQUEST_QUERY_URL_CALLBACK in set but failed match against \"{}\"", path, paths::REGEX_REQUEST_QUERY_URL_CALLBACK.as_str()) ); @@ -233,7 +235,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -268,11 +270,11 @@ pub struct ApiRequestParser; impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Option<&'static str> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); - match request.method() { + match *request.method() { // CallbackCallbackWithHeaderPost - POST /{$request.query.url}/callback-with-header - &hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER) => Some("CallbackCallbackWithHeaderPost"), + hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER) => Some("CallbackCallbackWithHeaderPost"), // CallbackCallbackPost - POST /{$request.query.url}/callback - &hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => Some("CallbackCallbackPost"), + hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => Some("CallbackCallbackPost"), _ => None, } } diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs index 76a64ab229bc..71a4af713398 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs @@ -532,7 +532,7 @@ impl Api for Client where let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.append_pair("url", - ¶m_url.to_string()); + ¶m_url); query_string.finish() }; if !query_string.is_empty() { @@ -850,6 +850,7 @@ impl Api for Client where // Header parameters request.headers_mut().append( HeaderName::from_static("x-header"), + #[allow(clippy::redundant_clone)] match header::IntoHeaderValue(param_x_header.clone()).try_into() { Ok(header) => header, Err(e) => { @@ -1159,8 +1160,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); @@ -1481,8 +1484,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); @@ -1542,7 +1547,7 @@ impl Api for Client where let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.append_pair("url", - ¶m_url.to_string()); + ¶m_url); query_string.finish() }; if !query_string.is_empty() { @@ -1728,8 +1733,7 @@ impl Api for Client where return Err(ApiError(format!("Invalid response header Success-Info for response 200 - {}", e))); }, }; - let response_success_info = response_success_info.0; - response_success_info + response_success_info.0 }, None => return Err(ApiError(String::from("Required response header Success-Info for response 200 was not found."))), }; @@ -1743,8 +1747,7 @@ impl Api for Client where return Err(ApiError(format!("Invalid response header Bool-Header for response 200 - {}", e))); }, }; - let response_bool_header = response_bool_header.0; - Some(response_bool_header) + Some(response_bool_header.0) }, None => None, }; @@ -1758,8 +1761,7 @@ impl Api for Client where return Err(ApiError(format!("Invalid response header Object-Header for response 200 - {}", e))); }, }; - let response_object_header = response_object_header.0; - Some(response_object_header) + Some(response_object_header.0) }, None => None, }; @@ -1775,7 +1777,7 @@ impl Api for Client where })?; Ok(ResponsesWithHeadersGetResponse::Success { - body: body, + body, success_info: response_success_info, bool_header: response_bool_header, object_header: response_object_header, @@ -1792,8 +1794,7 @@ impl Api for Client where return Err(ApiError(format!("Invalid response header Further-Info for response 412 - {}", e))); }, }; - let response_further_info = response_further_info.0; - Some(response_further_info) + Some(response_further_info.0) }, None => None, }; @@ -1807,8 +1808,7 @@ impl Api for Client where return Err(ApiError(format!("Invalid response header Failure-Info for response 412 - {}", e))); }, }; - let response_failure_info = response_failure_info.0; - Some(response_failure_info) + Some(response_failure_info.0) }, None => None, }; @@ -2140,7 +2140,7 @@ impl Api for Client where }; let body = param_duplicate_xml_object.map(|ref body| { - body.to_xml() + body.as_xml() }); if let Some(body) = body { *request.body_mut() = Body::from(body); @@ -2226,7 +2226,7 @@ impl Api for Client where }; let body = param_another_xml_object.map(|ref body| { - body.to_xml() + body.as_xml() }); if let Some(body) = body { *request.body_mut() = Body::from(body); @@ -2322,7 +2322,7 @@ impl Api for Client where }; let body = param_another_xml_array.map(|ref body| { - body.to_xml() + body.as_xml() }); if let Some(body) = body { *request.body_mut() = Body::from(body); @@ -2408,7 +2408,7 @@ impl Api for Client where }; let body = param_xml_array.map(|ref body| { - body.to_xml() + body.as_xml() }); if let Some(body) = body { *request.body_mut() = Body::from(body); @@ -2494,7 +2494,7 @@ impl Api for Client where }; let body = param_xml_object.map(|ref body| { - body.to_xml() + body.as_xml() }); if let Some(body) = body { diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/context.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/context.rs index 6f0300532522..ac1c07864b89 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/context.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/context.rs @@ -107,7 +107,7 @@ impl Service> for AddContext(&headers) { + if let Some(bearer) = swagger::auth::from_headers::(headers) { let auth_data = AuthData::Bearer(bearer); let context = context.push(Some(auth_data)); let context = context.push(None::); diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs index 87ddda8a3146..1f5793d8bf14 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs @@ -1,5 +1,6 @@ #![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] -#![allow(unused_imports)] +#![allow(unused_imports, unused_attributes)] +#![allow(clippy::derive_partial_eq_without_eq, clippy::blacklisted_name)] use async_trait::async_trait; use futures::Stream; @@ -273,6 +274,7 @@ pub enum GetRepoInfoResponse { /// API #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait Api { fn poll_ready(&self, _cx: &mut Context) -> Poll>> { Poll::Ready(Ok(())) @@ -408,6 +410,7 @@ pub trait Api { /// API where `Context` isn't passed on every API call #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait ApiNoContext { fn poll_ready(&self, _cx: &mut Context) -> Poll>>; @@ -854,7 +857,7 @@ pub trait CallbackApiNoContext { pub trait CallbackContextWrapperExt where Self: Sized { /// Binds this API to a context. - fn with_context(self: Self, context: C) -> ContextWrapper; + fn with_context(self, context: C) -> ContextWrapper; } impl + Send + Sync, C: Clone + Send + Sync> CallbackContextWrapperExt for T { diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs index 6a7a2fab4823..f422536428c1 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs @@ -58,7 +58,7 @@ impl AdditionalPropertiesWithList { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -111,7 +111,7 @@ impl<'a> std::iter::IntoIterator for &'a AnotherXmlArray { type IntoIter = std::slice::Iter<'a, String>; fn into_iter(self) -> Self::IntoIter { - (&self.0).into_iter() + (&self.0).iter() } } @@ -120,7 +120,7 @@ impl<'a> std::iter::IntoIterator for &'a mut AnotherXmlArray { type IntoIter = std::slice::IterMut<'a, String>; fn into_iter(self) -> Self::IntoIter { - (&mut self.0).into_iter() + (&mut self.0).iter_mut() } } @@ -142,7 +142,7 @@ impl std::ops::DerefMut for AnotherXmlArray { /// Should be implemented in a serde serializer impl std::string::ToString for AnotherXmlArray { fn to_string(&self) -> String { - self.iter().map(|x| x.to_string()).collect::>().join(",").to_string() + self.iter().map(|x| x.to_string()).collect::>().join(",") } } @@ -206,7 +206,7 @@ impl AnotherXmlArray { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -259,7 +259,7 @@ impl AnotherXmlInner { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -276,6 +276,7 @@ pub struct AnotherXmlObject { } impl AnotherXmlObject { + #[allow(clippy::new_without_default)] pub fn new() -> AnotherXmlObject { AnotherXmlObject { inner_string: None, @@ -288,14 +289,18 @@ impl AnotherXmlObject { /// Should be implemented in a serde serializer impl std::string::ToString for AnotherXmlObject { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref inner_string) = self.inner_string { - params.push("inner_string".to_string()); - params.push(inner_string.to_string()); - } + self.inner_string.as_ref().map(|inner_string| { + vec![ + "inner_string".to_string(), + inner_string.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -306,8 +311,9 @@ impl std::str::FromStr for AnotherXmlObject { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub inner_string: Vec, } @@ -315,7 +321,7 @@ impl std::str::FromStr for AnotherXmlObject { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -325,8 +331,10 @@ impl std::str::FromStr for AnotherXmlObject { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "inner_string" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "inner_string" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing AnotherXmlObject".to_string()) } } @@ -391,7 +399,7 @@ impl AnotherXmlObject { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { let mut namespaces = std::collections::BTreeMap::new(); // An empty string is used to indicate a global namespace in xmltree. namespaces.insert("".to_string(), Self::NAMESPACE.to_string()); @@ -405,6 +413,7 @@ pub struct AnyOfGet202Response { } impl AnyOfGet202Response { + #[allow(clippy::new_without_default)] pub fn new() -> AnyOfGet202Response { AnyOfGet202Response { } @@ -416,8 +425,10 @@ impl AnyOfGet202Response { /// Should be implemented in a serde serializer impl std::string::ToString for AnyOfGet202Response { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - params.join(",").to_string() + let params: Vec> = vec![ + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -428,15 +439,16 @@ impl std::str::FromStr for AnyOfGet202Response { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { } let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -446,6 +458,7 @@ impl std::str::FromStr for AnyOfGet202Response { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { _ => return std::result::Result::Err("Unexpected key while parsing AnyOfGet202Response".to_string()) } @@ -504,7 +517,7 @@ impl AnyOfGet202Response { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -516,6 +529,7 @@ pub struct AnyOfObject { } impl AnyOfObject { + #[allow(clippy::new_without_default)] pub fn new() -> AnyOfObject { AnyOfObject { } @@ -527,8 +541,10 @@ impl AnyOfObject { /// Should be implemented in a serde serializer impl std::string::ToString for AnyOfObject { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - params.join(",").to_string() + let params: Vec> = vec![ + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -539,15 +555,16 @@ impl std::str::FromStr for AnyOfObject { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { } let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -557,6 +574,7 @@ impl std::str::FromStr for AnyOfObject { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { _ => return std::result::Result::Err("Unexpected key while parsing AnyOfObject".to_string()) } @@ -615,7 +633,7 @@ impl AnyOfObject { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -637,8 +655,8 @@ pub enum AnyOfObjectAnyOf { impl std::fmt::Display for AnyOfObjectAnyOf { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self { - AnyOfObjectAnyOf::Foo => write!(f, "{}", "FOO"), - AnyOfObjectAnyOf::Bar => write!(f, "{}", "BAR"), + AnyOfObjectAnyOf::Foo => write!(f, "FOO"), + AnyOfObjectAnyOf::Bar => write!(f, "BAR"), } } } @@ -659,7 +677,7 @@ impl AnyOfObjectAnyOf { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -678,9 +696,10 @@ pub struct AnyOfProperty { } impl AnyOfProperty { + #[allow(clippy::new_without_default)] pub fn new(required_any_of: models::AnyOfObject, ) -> AnyOfProperty { AnyOfProperty { - required_any_of: required_any_of, + required_any_of, optional_any_of: None, } } @@ -691,12 +710,14 @@ impl AnyOfProperty { /// Should be implemented in a serde serializer impl std::string::ToString for AnyOfProperty { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - // Skipping requiredAnyOf in query parameter serialization + let params: Vec> = vec![ + // Skipping requiredAnyOf in query parameter serialization - // Skipping optionalAnyOf in query parameter serialization + // Skipping optionalAnyOf in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -707,8 +728,9 @@ impl std::str::FromStr for AnyOfProperty { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub required_any_of: Vec, pub optional_any_of: Vec, @@ -717,7 +739,7 @@ impl std::str::FromStr for AnyOfProperty { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -727,9 +749,12 @@ impl std::str::FromStr for AnyOfProperty { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "requiredAnyOf" => intermediate_rep.required_any_of.push(::from_str(val).map_err(|x| format!("{}", x))?), - "optionalAnyOf" => intermediate_rep.optional_any_of.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "requiredAnyOf" => intermediate_rep.required_any_of.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "optionalAnyOf" => intermediate_rep.optional_any_of.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing AnyOfProperty".to_string()) } } @@ -740,7 +765,7 @@ impl std::str::FromStr for AnyOfProperty { // Use the intermediate representation to return the struct std::result::Result::Ok(AnyOfProperty { - required_any_of: intermediate_rep.required_any_of.into_iter().next().ok_or("requiredAnyOf missing in AnyOfProperty".to_string())?, + required_any_of: intermediate_rep.required_any_of.into_iter().next().ok_or_else(|| "requiredAnyOf missing in AnyOfProperty".to_string())?, optional_any_of: intermediate_rep.optional_any_of.into_iter().next(), }) } @@ -789,7 +814,7 @@ impl AnyOfProperty { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -810,10 +835,11 @@ pub struct DuplicateXmlObject { } impl DuplicateXmlObject { + #[allow(clippy::new_without_default)] pub fn new(inner_array: models::XmlArray, ) -> DuplicateXmlObject { DuplicateXmlObject { inner_string: None, - inner_array: inner_array, + inner_array, } } } @@ -823,16 +849,20 @@ impl DuplicateXmlObject { /// Should be implemented in a serde serializer impl std::string::ToString for DuplicateXmlObject { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref inner_string) = self.inner_string { - params.push("inner_string".to_string()); - params.push(inner_string.to_string()); - } + self.inner_string.as_ref().map(|inner_string| { + vec![ + "inner_string".to_string(), + inner_string.to_string(), + ].join(",") + }), - // Skipping inner_array in query parameter serialization + // Skipping inner_array in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -843,8 +873,9 @@ impl std::str::FromStr for DuplicateXmlObject { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub inner_string: Vec, pub inner_array: Vec, @@ -853,7 +884,7 @@ impl std::str::FromStr for DuplicateXmlObject { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -863,9 +894,12 @@ impl std::str::FromStr for DuplicateXmlObject { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "inner_string" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| format!("{}", x))?), - "inner_array" => intermediate_rep.inner_array.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "inner_string" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "inner_array" => intermediate_rep.inner_array.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing DuplicateXmlObject".to_string()) } } @@ -877,7 +911,7 @@ impl std::str::FromStr for DuplicateXmlObject { // Use the intermediate representation to return the struct std::result::Result::Ok(DuplicateXmlObject { inner_string: intermediate_rep.inner_string.into_iter().next(), - inner_array: intermediate_rep.inner_array.into_iter().next().ok_or("inner_array missing in DuplicateXmlObject".to_string())?, + inner_array: intermediate_rep.inner_array.into_iter().next().ok_or_else(|| "inner_array missing in DuplicateXmlObject".to_string())?, }) } } @@ -931,7 +965,7 @@ impl DuplicateXmlObject { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { let mut namespaces = std::collections::BTreeMap::new(); // An empty string is used to indicate a global namespace in xmltree. namespaces.insert("".to_string(), Self::NAMESPACE.to_string()); @@ -959,9 +993,9 @@ pub enum EnumWithStarObject { impl std::fmt::Display for EnumWithStarObject { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self { - EnumWithStarObject::Foo => write!(f, "{}", "FOO"), - EnumWithStarObject::Bar => write!(f, "{}", "BAR"), - EnumWithStarObject::Star => write!(f, "{}", "*"), + EnumWithStarObject::Foo => write!(f, "FOO"), + EnumWithStarObject::Bar => write!(f, "BAR"), + EnumWithStarObject::Star => write!(f, "*"), } } } @@ -983,7 +1017,7 @@ impl EnumWithStarObject { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1035,7 +1069,7 @@ impl Err { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1087,7 +1121,7 @@ impl Error { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1099,6 +1133,7 @@ pub struct Model12345AnyOfObject { } impl Model12345AnyOfObject { + #[allow(clippy::new_without_default)] pub fn new() -> Model12345AnyOfObject { Model12345AnyOfObject { } @@ -1110,8 +1145,10 @@ impl Model12345AnyOfObject { /// Should be implemented in a serde serializer impl std::string::ToString for Model12345AnyOfObject { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - params.join(",").to_string() + let params: Vec> = vec![ + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1122,15 +1159,16 @@ impl std::str::FromStr for Model12345AnyOfObject { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { } let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1140,6 +1178,7 @@ impl std::str::FromStr for Model12345AnyOfObject { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { _ => return std::result::Result::Err("Unexpected key while parsing Model12345AnyOfObject".to_string()) } @@ -1198,7 +1237,7 @@ impl Model12345AnyOfObject { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1222,9 +1261,9 @@ pub enum Model12345AnyOfObjectAnyOf { impl std::fmt::Display for Model12345AnyOfObjectAnyOf { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self { - Model12345AnyOfObjectAnyOf::Foo => write!(f, "{}", "FOO"), - Model12345AnyOfObjectAnyOf::Bar => write!(f, "{}", "BAR"), - Model12345AnyOfObjectAnyOf::Star => write!(f, "{}", "*"), + Model12345AnyOfObjectAnyOf::Foo => write!(f, "FOO"), + Model12345AnyOfObjectAnyOf::Bar => write!(f, "BAR"), + Model12345AnyOfObjectAnyOf::Star => write!(f, "*"), } } } @@ -1246,7 +1285,7 @@ impl Model12345AnyOfObjectAnyOf { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1261,6 +1300,7 @@ pub struct MultigetGet201Response { } impl MultigetGet201Response { + #[allow(clippy::new_without_default)] pub fn new() -> MultigetGet201Response { MultigetGet201Response { foo: None, @@ -1273,14 +1313,18 @@ impl MultigetGet201Response { /// Should be implemented in a serde serializer impl std::string::ToString for MultigetGet201Response { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref foo) = self.foo { - params.push("foo".to_string()); - params.push(foo.to_string()); - } + self.foo.as_ref().map(|foo| { + vec![ + "foo".to_string(), + foo.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1291,8 +1335,9 @@ impl std::str::FromStr for MultigetGet201Response { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub foo: Vec, } @@ -1300,7 +1345,7 @@ impl std::str::FromStr for MultigetGet201Response { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1310,8 +1355,10 @@ impl std::str::FromStr for MultigetGet201Response { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "foo" => intermediate_rep.foo.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "foo" => intermediate_rep.foo.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing MultigetGet201Response".to_string()) } } @@ -1370,7 +1417,7 @@ impl MultigetGet201Response { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1409,7 +1456,7 @@ impl MyId { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1452,7 +1499,7 @@ impl<'a> std::iter::IntoIterator for &'a MyIdList { type IntoIter = std::slice::Iter<'a, i32>; fn into_iter(self) -> Self::IntoIter { - (&self.0).into_iter() + (&self.0).iter() } } @@ -1461,7 +1508,7 @@ impl<'a> std::iter::IntoIterator for &'a mut MyIdList { type IntoIter = std::slice::IterMut<'a, i32>; fn into_iter(self) -> Self::IntoIter { - (&mut self.0).into_iter() + (&mut self.0).iter_mut() } } @@ -1483,7 +1530,7 @@ impl std::ops::DerefMut for MyIdList { /// Should be implemented in a serde serializer impl std::string::ToString for MyIdList { fn to_string(&self) -> String { - self.iter().map(|x| x.to_string()).collect::>().join(",").to_string() + self.iter().map(|x| x.to_string()).collect::>().join(",") } } @@ -1547,7 +1594,7 @@ impl MyIdList { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1585,9 +1632,10 @@ pub struct NullableTest { } impl NullableTest { + #[allow(clippy::new_without_default)] pub fn new(nullable: swagger::Nullable, ) -> NullableTest { NullableTest { - nullable: nullable, + nullable, nullable_with_null_default: None, nullable_with_present_default: Some(swagger::Nullable::Present("default".to_string())), nullable_with_no_default: None, @@ -1601,36 +1649,46 @@ impl NullableTest { /// Should be implemented in a serde serializer impl std::string::ToString for NullableTest { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - params.push("nullable".to_string()); - params.push(self.nullable.as_ref().map_or("null".to_string(), |x| x.to_string())); + Some("nullable".to_string()), + Some(self.nullable.as_ref().map_or("null".to_string(), |x| x.to_string())), - if let Some(ref nullable_with_null_default) = self.nullable_with_null_default { - params.push("nullableWithNullDefault".to_string()); - params.push(nullable_with_null_default.as_ref().map_or("null".to_string(), |x| x.to_string())); - } + self.nullable_with_null_default.as_ref().map(|nullable_with_null_default| { + vec![ + "nullableWithNullDefault".to_string(), + nullable_with_null_default.as_ref().map_or("null".to_string(), |x| x.to_string()), + ].join(",") + }), - if let Some(ref nullable_with_present_default) = self.nullable_with_present_default { - params.push("nullableWithPresentDefault".to_string()); - params.push(nullable_with_present_default.as_ref().map_or("null".to_string(), |x| x.to_string())); - } + self.nullable_with_present_default.as_ref().map(|nullable_with_present_default| { + vec![ + "nullableWithPresentDefault".to_string(), + nullable_with_present_default.as_ref().map_or("null".to_string(), |x| x.to_string()), + ].join(",") + }), - if let Some(ref nullable_with_no_default) = self.nullable_with_no_default { - params.push("nullableWithNoDefault".to_string()); - params.push(nullable_with_no_default.as_ref().map_or("null".to_string(), |x| x.to_string())); - } + self.nullable_with_no_default.as_ref().map(|nullable_with_no_default| { + vec![ + "nullableWithNoDefault".to_string(), + nullable_with_no_default.as_ref().map_or("null".to_string(), |x| x.to_string()), + ].join(",") + }), - if let Some(ref nullable_array) = self.nullable_array { - params.push("nullableArray".to_string()); - params.push(nullable_array.as_ref().map_or("null".to_string(), |x| x.iter().map(|x| x.to_string()).collect::>().join(",").to_string())); - } + self.nullable_array.as_ref().map(|nullable_array| { + vec![ + "nullableArray".to_string(), + nullable_array.as_ref().map_or("null".to_string(), |x| x.iter().map(|x| x.to_string()).collect::>().join(",")), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1641,8 +1699,9 @@ impl std::str::FromStr for NullableTest { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub nullable: Vec, pub nullable_with_null_default: Vec, @@ -1654,7 +1713,7 @@ impl std::str::FromStr for NullableTest { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1664,6 +1723,7 @@ impl std::str::FromStr for NullableTest { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { "nullable" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()), "nullableWithNullDefault" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()), @@ -1732,7 +1792,7 @@ impl NullableTest { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1750,9 +1810,10 @@ pub struct ObjectHeader { } impl ObjectHeader { + #[allow(clippy::new_without_default)] pub fn new(required_object_header: bool, ) -> ObjectHeader { ObjectHeader { - required_object_header: required_object_header, + required_object_header, optional_object_header: None, } } @@ -1763,18 +1824,22 @@ impl ObjectHeader { /// Should be implemented in a serde serializer impl std::string::ToString for ObjectHeader { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - params.push("requiredObjectHeader".to_string()); - params.push(self.required_object_header.to_string()); + Some("requiredObjectHeader".to_string()), + Some(self.required_object_header.to_string()), - if let Some(ref optional_object_header) = self.optional_object_header { - params.push("optionalObjectHeader".to_string()); - params.push(optional_object_header.to_string()); - } + self.optional_object_header.as_ref().map(|optional_object_header| { + vec![ + "optionalObjectHeader".to_string(), + optional_object_header.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1785,8 +1850,9 @@ impl std::str::FromStr for ObjectHeader { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub required_object_header: Vec, pub optional_object_header: Vec, @@ -1795,7 +1861,7 @@ impl std::str::FromStr for ObjectHeader { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1805,9 +1871,12 @@ impl std::str::FromStr for ObjectHeader { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "requiredObjectHeader" => intermediate_rep.required_object_header.push(::from_str(val).map_err(|x| format!("{}", x))?), - "optionalObjectHeader" => intermediate_rep.optional_object_header.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "requiredObjectHeader" => intermediate_rep.required_object_header.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "optionalObjectHeader" => intermediate_rep.optional_object_header.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectHeader".to_string()) } } @@ -1818,7 +1887,7 @@ impl std::str::FromStr for ObjectHeader { // Use the intermediate representation to return the struct std::result::Result::Ok(ObjectHeader { - required_object_header: intermediate_rep.required_object_header.into_iter().next().ok_or("requiredObjectHeader missing in ObjectHeader".to_string())?, + required_object_header: intermediate_rep.required_object_header.into_iter().next().ok_or_else(|| "requiredObjectHeader missing in ObjectHeader".to_string())?, optional_object_header: intermediate_rep.optional_object_header.into_iter().next(), }) } @@ -1867,7 +1936,7 @@ impl ObjectHeader { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1885,9 +1954,10 @@ pub struct ObjectParam { } impl ObjectParam { + #[allow(clippy::new_without_default)] pub fn new(required_param: bool, ) -> ObjectParam { ObjectParam { - required_param: required_param, + required_param, optional_param: None, } } @@ -1898,18 +1968,22 @@ impl ObjectParam { /// Should be implemented in a serde serializer impl std::string::ToString for ObjectParam { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - params.push("requiredParam".to_string()); - params.push(self.required_param.to_string()); + Some("requiredParam".to_string()), + Some(self.required_param.to_string()), - if let Some(ref optional_param) = self.optional_param { - params.push("optionalParam".to_string()); - params.push(optional_param.to_string()); - } + self.optional_param.as_ref().map(|optional_param| { + vec![ + "optionalParam".to_string(), + optional_param.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1920,8 +1994,9 @@ impl std::str::FromStr for ObjectParam { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub required_param: Vec, pub optional_param: Vec, @@ -1930,7 +2005,7 @@ impl std::str::FromStr for ObjectParam { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1940,9 +2015,12 @@ impl std::str::FromStr for ObjectParam { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "requiredParam" => intermediate_rep.required_param.push(::from_str(val).map_err(|x| format!("{}", x))?), - "optionalParam" => intermediate_rep.optional_param.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "requiredParam" => intermediate_rep.required_param.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "optionalParam" => intermediate_rep.optional_param.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectParam".to_string()) } } @@ -1953,7 +2031,7 @@ impl std::str::FromStr for ObjectParam { // Use the intermediate representation to return the struct std::result::Result::Ok(ObjectParam { - required_param: intermediate_rep.required_param.into_iter().next().ok_or("requiredParam missing in ObjectParam".to_string())?, + required_param: intermediate_rep.required_param.into_iter().next().ok_or_else(|| "requiredParam missing in ObjectParam".to_string())?, optional_param: intermediate_rep.optional_param.into_iter().next(), }) } @@ -2002,7 +2080,7 @@ impl ObjectParam { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2027,10 +2105,11 @@ pub struct ObjectUntypedProps { } impl ObjectUntypedProps { + #[allow(clippy::new_without_default)] pub fn new(required_untyped: serde_json::Value, required_untyped_nullable: swagger::Nullable, ) -> ObjectUntypedProps { ObjectUntypedProps { - required_untyped: required_untyped, - required_untyped_nullable: required_untyped_nullable, + required_untyped, + required_untyped_nullable, not_required_untyped: None, not_required_untyped_nullable: None, } @@ -2042,16 +2121,18 @@ impl ObjectUntypedProps { /// Should be implemented in a serde serializer impl std::string::ToString for ObjectUntypedProps { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - // Skipping required_untyped in query parameter serialization + let params: Vec> = vec![ + // Skipping required_untyped in query parameter serialization - // Skipping required_untyped_nullable in query parameter serialization + // Skipping required_untyped_nullable in query parameter serialization - // Skipping not_required_untyped in query parameter serialization + // Skipping not_required_untyped in query parameter serialization - // Skipping not_required_untyped_nullable in query parameter serialization + // Skipping not_required_untyped_nullable in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -2062,8 +2143,9 @@ impl std::str::FromStr for ObjectUntypedProps { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub required_untyped: Vec, pub required_untyped_nullable: Vec, @@ -2074,7 +2156,7 @@ impl std::str::FromStr for ObjectUntypedProps { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -2084,11 +2166,15 @@ impl std::str::FromStr for ObjectUntypedProps { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "required_untyped" => intermediate_rep.required_untyped.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "required_untyped" => intermediate_rep.required_untyped.push(::from_str(val).map_err(|x| x.to_string())?), "required_untyped_nullable" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in ObjectUntypedProps".to_string()), - "not_required_untyped" => intermediate_rep.not_required_untyped.push(::from_str(val).map_err(|x| format!("{}", x))?), - "not_required_untyped_nullable" => intermediate_rep.not_required_untyped_nullable.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "not_required_untyped" => intermediate_rep.not_required_untyped.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "not_required_untyped_nullable" => intermediate_rep.not_required_untyped_nullable.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectUntypedProps".to_string()) } } @@ -2099,7 +2185,7 @@ impl std::str::FromStr for ObjectUntypedProps { // Use the intermediate representation to return the struct std::result::Result::Ok(ObjectUntypedProps { - required_untyped: intermediate_rep.required_untyped.into_iter().next().ok_or("required_untyped missing in ObjectUntypedProps".to_string())?, + required_untyped: intermediate_rep.required_untyped.into_iter().next().ok_or_else(|| "required_untyped missing in ObjectUntypedProps".to_string())?, required_untyped_nullable: std::result::Result::Err("Nullable types not supported in ObjectUntypedProps".to_string())?, not_required_untyped: intermediate_rep.not_required_untyped.into_iter().next(), not_required_untyped_nullable: intermediate_rep.not_required_untyped_nullable.into_iter().next(), @@ -2150,7 +2236,7 @@ impl ObjectUntypedProps { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2165,6 +2251,7 @@ pub struct ObjectWithArrayOfObjects { } impl ObjectWithArrayOfObjects { + #[allow(clippy::new_without_default)] pub fn new() -> ObjectWithArrayOfObjects { ObjectWithArrayOfObjects { object_array: None, @@ -2177,14 +2264,18 @@ impl ObjectWithArrayOfObjects { /// Should be implemented in a serde serializer impl std::string::ToString for ObjectWithArrayOfObjects { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref object_array) = self.object_array { - params.push("objectArray".to_string()); - params.push(object_array.iter().map(|x| x.to_string()).collect::>().join(",").to_string()); - } + self.object_array.as_ref().map(|object_array| { + vec![ + "objectArray".to_string(), + object_array.iter().map(|x| x.to_string()).collect::>().join(","), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -2195,8 +2286,9 @@ impl std::str::FromStr for ObjectWithArrayOfObjects { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub object_array: Vec>, } @@ -2204,7 +2296,7 @@ impl std::str::FromStr for ObjectWithArrayOfObjects { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -2214,6 +2306,7 @@ impl std::str::FromStr for ObjectWithArrayOfObjects { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { "objectArray" => return std::result::Result::Err("Parsing a container in this style is not supported in ObjectWithArrayOfObjects".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing ObjectWithArrayOfObjects".to_string()) @@ -2274,7 +2367,7 @@ impl ObjectWithArrayOfObjects { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2326,7 +2419,7 @@ impl Ok { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2337,6 +2430,7 @@ pub struct OneOfGet200Response { } impl OneOfGet200Response { + #[allow(clippy::new_without_default)] pub fn new() -> OneOfGet200Response { OneOfGet200Response { } @@ -2348,8 +2442,10 @@ impl OneOfGet200Response { /// Should be implemented in a serde serializer impl std::string::ToString for OneOfGet200Response { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - params.join(",").to_string() + let params: Vec> = vec![ + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -2360,15 +2456,16 @@ impl std::str::FromStr for OneOfGet200Response { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { } let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -2378,6 +2475,7 @@ impl std::str::FromStr for OneOfGet200Response { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { _ => return std::result::Result::Err("Unexpected key while parsing OneOfGet200Response".to_string()) } @@ -2436,7 +2534,7 @@ impl OneOfGet200Response { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2475,7 +2573,7 @@ impl OptionalObjectHeader { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2514,7 +2612,7 @@ impl RequiredObjectHeader { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2566,7 +2664,7 @@ impl Result { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2588,8 +2686,8 @@ pub enum StringEnum { impl std::fmt::Display for StringEnum { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self { - StringEnum::Foo => write!(f, "{}", "FOO"), - StringEnum::Bar => write!(f, "{}", "BAR"), + StringEnum::Foo => write!(f, "FOO"), + StringEnum::Bar => write!(f, "BAR"), } } } @@ -2610,7 +2708,7 @@ impl StringEnum { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2662,7 +2760,7 @@ impl StringObject { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2702,7 +2800,7 @@ impl UuidObject { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2755,7 +2853,7 @@ impl<'a> std::iter::IntoIterator for &'a XmlArray { type IntoIter = std::slice::Iter<'a, String>; fn into_iter(self) -> Self::IntoIter { - (&self.0).into_iter() + (&self.0).iter() } } @@ -2764,7 +2862,7 @@ impl<'a> std::iter::IntoIterator for &'a mut XmlArray { type IntoIter = std::slice::IterMut<'a, String>; fn into_iter(self) -> Self::IntoIter { - (&mut self.0).into_iter() + (&mut self.0).iter_mut() } } @@ -2786,7 +2884,7 @@ impl std::ops::DerefMut for XmlArray { /// Should be implemented in a serde serializer impl std::string::ToString for XmlArray { fn to_string(&self) -> String { - self.iter().map(|x| x.to_string()).collect::>().join(",").to_string() + self.iter().map(|x| x.to_string()).collect::>().join(",") } } @@ -2850,7 +2948,7 @@ impl XmlArray { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2903,7 +3001,7 @@ impl XmlInner { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2924,6 +3022,7 @@ pub struct XmlObject { } impl XmlObject { + #[allow(clippy::new_without_default)] pub fn new() -> XmlObject { XmlObject { inner_string: None, @@ -2937,20 +3036,26 @@ impl XmlObject { /// Should be implemented in a serde serializer impl std::string::ToString for XmlObject { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref inner_string) = self.inner_string { - params.push("innerString".to_string()); - params.push(inner_string.to_string()); - } + self.inner_string.as_ref().map(|inner_string| { + vec![ + "innerString".to_string(), + inner_string.to_string(), + ].join(",") + }), - if let Some(ref other_inner_rename) = self.other_inner_rename { - params.push("other_inner_rename".to_string()); - params.push(other_inner_rename.to_string()); - } + self.other_inner_rename.as_ref().map(|other_inner_rename| { + vec![ + "other_inner_rename".to_string(), + other_inner_rename.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -2961,8 +3066,9 @@ impl std::str::FromStr for XmlObject { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub inner_string: Vec, pub other_inner_rename: Vec, @@ -2971,7 +3077,7 @@ impl std::str::FromStr for XmlObject { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -2981,9 +3087,12 @@ impl std::str::FromStr for XmlObject { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "innerString" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| format!("{}", x))?), - "other_inner_rename" => intermediate_rep.other_inner_rename.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "innerString" => intermediate_rep.inner_string.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "other_inner_rename" => intermediate_rep.other_inner_rename.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing XmlObject".to_string()) } } @@ -3049,7 +3158,7 @@ impl XmlObject { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { let mut namespaces = std::collections::BTreeMap::new(); // An empty string is used to indicate a global namespace in xmltree. namespaces.insert("".to_string(), Self::NAMESPACE.to_string()); diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/server/callbacks.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/server/callbacks.rs index 38dd27fa7ae3..0486992669b5 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/server/callbacks.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/server/callbacks.rs @@ -275,6 +275,7 @@ impl CallbackApi for Client where Some(param_information) => { request.headers_mut().append( HeaderName::from_static("information"), + #[allow(clippy::redundant_clone)] match header::IntoHeaderValue(param_information.clone()).try_into() { Ok(header) => header, Err(e) => { diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs index 813b8d962d02..66216f5a2f04 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs @@ -90,6 +90,7 @@ mod paths { pub(crate) static ID_ENUM_IN_PATH_PATH_PARAM: usize = 3; lazy_static! { pub static ref REGEX_ENUM_IN_PATH_PATH_PARAM: regex::Regex = + #[allow(clippy::invalid_regex)] regex::Regex::new(r"^/enum_in_path/(?P[^/?#]*)$") .expect("Unable to create regex for ENUM_IN_PATH_PATH_PARAM"); } @@ -107,6 +108,7 @@ mod paths { pub(crate) static ID_REPOS_REPOID: usize = 15; lazy_static! { pub static ref REGEX_REPOS_REPOID: regex::Regex = + #[allow(clippy::invalid_regex)] regex::Regex::new(r"^/repos/(?P[^/?#]*)$") .expect("Unable to create regex for REPOS_REPOID"); } @@ -181,7 +183,7 @@ impl Service where { pub fn new(api_impl: T) -> Self { Service { - api_impl: api_impl, + api_impl, marker: PhantomData } } @@ -194,7 +196,7 @@ impl Clone for Service where fn clone(&self) -> Self { Service { api_impl: self.api_impl.clone(), - marker: self.marker.clone(), + marker: self.marker, } } } @@ -220,10 +222,10 @@ impl hyper::service::Service<(Request, C)> for Service where let (method, uri, headers) = (parts.method, parts.uri, parts.headers); let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); - match &method { + match method { // AnyOfGet - GET /any-of - &hyper::Method::GET if path.matched(paths::ID_ANY_OF) => { + hyper::Method::GET if path.matched(paths::ID_ANY_OF) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::>(); let param_any_of = query_params.iter().filter(|e| e.0 == "any-of").map(|e| e.1.to_owned()) @@ -242,7 +244,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -293,11 +295,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // CallbackWithHeaderPost - POST /callback-with-header - &hyper::Method::POST if path.matched(paths::ID_CALLBACK_WITH_HEADER) => { + hyper::Method::POST if path.matched(paths::ID_CALLBACK_WITH_HEADER) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::>(); let param_url = query_params.iter().filter(|e| e.0 == "url").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_url = match param_url { Some(param_url) => { let param_url = @@ -328,7 +330,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -350,7 +352,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // ComplexQueryParamGet - GET /complex-query-param - &hyper::Method::GET if path.matched(paths::ID_COMPLEX_QUERY_PARAM) => { + hyper::Method::GET if path.matched(paths::ID_COMPLEX_QUERY_PARAM) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::>(); let param_list_of_strings = query_params.iter().filter(|e| e.0 == "list-of-strings").map(|e| e.1.to_owned()) @@ -369,7 +371,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -391,12 +393,12 @@ impl hyper::service::Service<(Request, C)> for Service where }, // EnumInPathPathParamGet - GET /enum_in_path/{path_param} - &hyper::Method::GET if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => { + hyper::Method::GET if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => { // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_ENUM_IN_PATH_PATH_PARAM - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE ENUM_IN_PATH_PATH_PARAM in set but failed match against \"{}\"", path, paths::REGEX_ENUM_IN_PATH_PATH_PARAM.as_str()) ); @@ -422,7 +424,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -444,11 +446,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // JsonComplexQueryParamGet - GET /json-complex-query-param - &hyper::Method::GET if path.matched(paths::ID_JSON_COMPLEX_QUERY_PARAM) => { + hyper::Method::GET if path.matched(paths::ID_JSON_COMPLEX_QUERY_PARAM) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::>(); let param_list_of_strings = query_params.iter().filter(|e| e.0 == "list-of-strings").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_list_of_strings = match param_list_of_strings { Some(param_list_of_strings) => { let param_list_of_strings = @@ -472,7 +474,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -494,7 +496,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // MandatoryRequestHeaderGet - GET /mandatory-request-header - &hyper::Method::GET if path.matched(paths::ID_MANDATORY_REQUEST_HEADER) => { + hyper::Method::GET if path.matched(paths::ID_MANDATORY_REQUEST_HEADER) => { // Header parameters let param_x_header = headers.get(HeaderName::from_static("x-header")); @@ -525,7 +527,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -547,14 +549,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // MergePatchJsonGet - GET /merge-patch-json - &hyper::Method::GET if path.matched(paths::ID_MERGE_PATCH_JSON) => { + hyper::Method::GET if path.matched(paths::ID_MERGE_PATCH_JSON) => { let result = api_impl.merge_patch_json_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -583,14 +585,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // MultigetGet - GET /multiget - &hyper::Method::GET if path.matched(paths::ID_MULTIGET) => { + hyper::Method::GET if path.matched(paths::ID_MULTIGET) => { let result = api_impl.multiget_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -685,11 +687,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // MultipleAuthSchemeGet - GET /multiple_auth_scheme - &hyper::Method::GET if path.matched(paths::ID_MULTIPLE_AUTH_SCHEME) => { + hyper::Method::GET if path.matched(paths::ID_MULTIPLE_AUTH_SCHEME) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -722,7 +724,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -744,14 +746,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // OneOfGet - GET /one-of - &hyper::Method::GET if path.matched(paths::ID_ONE_OF) => { + hyper::Method::GET if path.matched(paths::ID_ONE_OF) => { let result = api_impl.one_of_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -780,14 +782,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // OverrideServerGet - GET /override-server - &hyper::Method::GET if path.matched(paths::ID_OVERRIDE_SERVER) => { + hyper::Method::GET if path.matched(paths::ID_OVERRIDE_SERVER) => { let result = api_impl.override_server_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -809,11 +811,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // ParamgetGet - GET /paramget - &hyper::Method::GET if path.matched(paths::ID_PARAMGET) => { + hyper::Method::GET if path.matched(paths::ID_PARAMGET) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::>(); let param_uuid = query_params.iter().filter(|e| e.0 == "uuid").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_uuid = match param_uuid { Some(param_uuid) => { let param_uuid = @@ -830,7 +832,7 @@ impl hyper::service::Service<(Request, C)> for Service where None => None, }; let param_some_object = query_params.iter().filter(|e| e.0 == "someObject").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_some_object = match param_some_object { Some(param_some_object) => { let param_some_object = @@ -847,7 +849,7 @@ impl hyper::service::Service<(Request, C)> for Service where None => None, }; let param_some_list = query_params.iter().filter(|e| e.0 == "someList").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_some_list = match param_some_list { Some(param_some_list) => { let param_some_list = @@ -873,7 +875,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -902,11 +904,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // ReadonlyAuthSchemeGet - GET /readonly_auth_scheme - &hyper::Method::GET if path.matched(paths::ID_READONLY_AUTH_SCHEME) => { + hyper::Method::GET if path.matched(paths::ID_READONLY_AUTH_SCHEME) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -938,7 +940,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -960,11 +962,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // RegisterCallbackPost - POST /register-callback - &hyper::Method::POST if path.matched(paths::ID_REGISTER_CALLBACK) => { + hyper::Method::POST if path.matched(paths::ID_REGISTER_CALLBACK) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::>(); let param_url = query_params.iter().filter(|e| e.0 == "url").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_url = match param_url { Some(param_url) => { let param_url = @@ -995,7 +997,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1017,7 +1019,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // RequiredOctetStreamPut - PUT /required_octet_stream - &hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => { + hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1044,7 +1046,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1072,14 +1074,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // ResponsesWithHeadersGet - GET /responses_with_headers - &hyper::Method::GET if path.matched(paths::ID_RESPONSES_WITH_HEADERS) => { + hyper::Method::GET if path.matched(paths::ID_RESPONSES_WITH_HEADERS) => { let result = api_impl.responses_with_headers_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1199,14 +1201,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Rfc7807Get - GET /rfc7807 - &hyper::Method::GET if path.matched(paths::ID_RFC7807) => { + hyper::Method::GET if path.matched(paths::ID_RFC7807) => { let result = api_impl.rfc7807_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1257,7 +1259,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // UntypedPropertyGet - GET /untyped_property - &hyper::Method::GET if path.matched(paths::ID_UNTYPED_PROPERTY) => { + hyper::Method::GET if path.matched(paths::ID_UNTYPED_PROPERTY) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1285,7 +1287,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1320,14 +1322,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // UuidGet - GET /uuid - &hyper::Method::GET if path.matched(paths::ID_UUID) => { + hyper::Method::GET if path.matched(paths::ID_UUID) => { let result = api_impl.uuid_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1356,7 +1358,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // XmlExtraPost - POST /xml_extra - &hyper::Method::POST if path.matched(paths::ID_XML_EXTRA) => { + hyper::Method::POST if path.matched(paths::ID_XML_EXTRA) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1384,7 +1386,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1423,7 +1425,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // XmlOtherPost - POST /xml_other - &hyper::Method::POST if path.matched(paths::ID_XML_OTHER) => { + hyper::Method::POST if path.matched(paths::ID_XML_OTHER) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1451,7 +1453,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1501,7 +1503,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // XmlOtherPut - PUT /xml_other - &hyper::Method::PUT if path.matched(paths::ID_XML_OTHER) => { + hyper::Method::PUT if path.matched(paths::ID_XML_OTHER) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1529,7 +1531,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1568,7 +1570,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // XmlPost - POST /xml - &hyper::Method::POST if path.matched(paths::ID_XML) => { + hyper::Method::POST if path.matched(paths::ID_XML) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1596,7 +1598,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1635,7 +1637,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // XmlPut - PUT /xml - &hyper::Method::PUT if path.matched(paths::ID_XML) => { + hyper::Method::PUT if path.matched(paths::ID_XML) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1663,7 +1665,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1702,7 +1704,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // CreateRepo - POST /repos - &hyper::Method::POST if path.matched(paths::ID_REPOS) => { + hyper::Method::POST if path.matched(paths::ID_REPOS) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1740,7 +1742,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1775,12 +1777,12 @@ impl hyper::service::Service<(Request, C)> for Service where }, // GetRepoInfo - GET /repos/{repoId} - &hyper::Method::GET if path.matched(paths::ID_REPOS_REPOID) => { + hyper::Method::GET if path.matched(paths::ID_REPOS_REPOID) => { // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_REPOS_REPOID - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE REPOS_REPOID in set but failed match against \"{}\"", path, paths::REGEX_REPOS_REPOID.as_str()) ); @@ -1806,7 +1808,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1870,59 +1872,59 @@ pub struct ApiRequestParser; impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Option<&'static str> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); - match request.method() { + match *request.method() { // AnyOfGet - GET /any-of - &hyper::Method::GET if path.matched(paths::ID_ANY_OF) => Some("AnyOfGet"), + hyper::Method::GET if path.matched(paths::ID_ANY_OF) => Some("AnyOfGet"), // CallbackWithHeaderPost - POST /callback-with-header - &hyper::Method::POST if path.matched(paths::ID_CALLBACK_WITH_HEADER) => Some("CallbackWithHeaderPost"), + hyper::Method::POST if path.matched(paths::ID_CALLBACK_WITH_HEADER) => Some("CallbackWithHeaderPost"), // ComplexQueryParamGet - GET /complex-query-param - &hyper::Method::GET if path.matched(paths::ID_COMPLEX_QUERY_PARAM) => Some("ComplexQueryParamGet"), + hyper::Method::GET if path.matched(paths::ID_COMPLEX_QUERY_PARAM) => Some("ComplexQueryParamGet"), // EnumInPathPathParamGet - GET /enum_in_path/{path_param} - &hyper::Method::GET if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => Some("EnumInPathPathParamGet"), + hyper::Method::GET if path.matched(paths::ID_ENUM_IN_PATH_PATH_PARAM) => Some("EnumInPathPathParamGet"), // JsonComplexQueryParamGet - GET /json-complex-query-param - &hyper::Method::GET if path.matched(paths::ID_JSON_COMPLEX_QUERY_PARAM) => Some("JsonComplexQueryParamGet"), + hyper::Method::GET if path.matched(paths::ID_JSON_COMPLEX_QUERY_PARAM) => Some("JsonComplexQueryParamGet"), // MandatoryRequestHeaderGet - GET /mandatory-request-header - &hyper::Method::GET if path.matched(paths::ID_MANDATORY_REQUEST_HEADER) => Some("MandatoryRequestHeaderGet"), + hyper::Method::GET if path.matched(paths::ID_MANDATORY_REQUEST_HEADER) => Some("MandatoryRequestHeaderGet"), // MergePatchJsonGet - GET /merge-patch-json - &hyper::Method::GET if path.matched(paths::ID_MERGE_PATCH_JSON) => Some("MergePatchJsonGet"), + hyper::Method::GET if path.matched(paths::ID_MERGE_PATCH_JSON) => Some("MergePatchJsonGet"), // MultigetGet - GET /multiget - &hyper::Method::GET if path.matched(paths::ID_MULTIGET) => Some("MultigetGet"), + hyper::Method::GET if path.matched(paths::ID_MULTIGET) => Some("MultigetGet"), // MultipleAuthSchemeGet - GET /multiple_auth_scheme - &hyper::Method::GET if path.matched(paths::ID_MULTIPLE_AUTH_SCHEME) => Some("MultipleAuthSchemeGet"), + hyper::Method::GET if path.matched(paths::ID_MULTIPLE_AUTH_SCHEME) => Some("MultipleAuthSchemeGet"), // OneOfGet - GET /one-of - &hyper::Method::GET if path.matched(paths::ID_ONE_OF) => Some("OneOfGet"), + hyper::Method::GET if path.matched(paths::ID_ONE_OF) => Some("OneOfGet"), // OverrideServerGet - GET /override-server - &hyper::Method::GET if path.matched(paths::ID_OVERRIDE_SERVER) => Some("OverrideServerGet"), + hyper::Method::GET if path.matched(paths::ID_OVERRIDE_SERVER) => Some("OverrideServerGet"), // ParamgetGet - GET /paramget - &hyper::Method::GET if path.matched(paths::ID_PARAMGET) => Some("ParamgetGet"), + hyper::Method::GET if path.matched(paths::ID_PARAMGET) => Some("ParamgetGet"), // ReadonlyAuthSchemeGet - GET /readonly_auth_scheme - &hyper::Method::GET if path.matched(paths::ID_READONLY_AUTH_SCHEME) => Some("ReadonlyAuthSchemeGet"), + hyper::Method::GET if path.matched(paths::ID_READONLY_AUTH_SCHEME) => Some("ReadonlyAuthSchemeGet"), // RegisterCallbackPost - POST /register-callback - &hyper::Method::POST if path.matched(paths::ID_REGISTER_CALLBACK) => Some("RegisterCallbackPost"), + hyper::Method::POST if path.matched(paths::ID_REGISTER_CALLBACK) => Some("RegisterCallbackPost"), // RequiredOctetStreamPut - PUT /required_octet_stream - &hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => Some("RequiredOctetStreamPut"), + hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => Some("RequiredOctetStreamPut"), // ResponsesWithHeadersGet - GET /responses_with_headers - &hyper::Method::GET if path.matched(paths::ID_RESPONSES_WITH_HEADERS) => Some("ResponsesWithHeadersGet"), + hyper::Method::GET if path.matched(paths::ID_RESPONSES_WITH_HEADERS) => Some("ResponsesWithHeadersGet"), // Rfc7807Get - GET /rfc7807 - &hyper::Method::GET if path.matched(paths::ID_RFC7807) => Some("Rfc7807Get"), + hyper::Method::GET if path.matched(paths::ID_RFC7807) => Some("Rfc7807Get"), // UntypedPropertyGet - GET /untyped_property - &hyper::Method::GET if path.matched(paths::ID_UNTYPED_PROPERTY) => Some("UntypedPropertyGet"), + hyper::Method::GET if path.matched(paths::ID_UNTYPED_PROPERTY) => Some("UntypedPropertyGet"), // UuidGet - GET /uuid - &hyper::Method::GET if path.matched(paths::ID_UUID) => Some("UuidGet"), + hyper::Method::GET if path.matched(paths::ID_UUID) => Some("UuidGet"), // XmlExtraPost - POST /xml_extra - &hyper::Method::POST if path.matched(paths::ID_XML_EXTRA) => Some("XmlExtraPost"), + hyper::Method::POST if path.matched(paths::ID_XML_EXTRA) => Some("XmlExtraPost"), // XmlOtherPost - POST /xml_other - &hyper::Method::POST if path.matched(paths::ID_XML_OTHER) => Some("XmlOtherPost"), + hyper::Method::POST if path.matched(paths::ID_XML_OTHER) => Some("XmlOtherPost"), // XmlOtherPut - PUT /xml_other - &hyper::Method::PUT if path.matched(paths::ID_XML_OTHER) => Some("XmlOtherPut"), + hyper::Method::PUT if path.matched(paths::ID_XML_OTHER) => Some("XmlOtherPut"), // XmlPost - POST /xml - &hyper::Method::POST if path.matched(paths::ID_XML) => Some("XmlPost"), + hyper::Method::POST if path.matched(paths::ID_XML) => Some("XmlPost"), // XmlPut - PUT /xml - &hyper::Method::PUT if path.matched(paths::ID_XML) => Some("XmlPut"), + hyper::Method::PUT if path.matched(paths::ID_XML) => Some("XmlPut"), // CreateRepo - POST /repos - &hyper::Method::POST if path.matched(paths::ID_REPOS) => Some("CreateRepo"), + hyper::Method::POST if path.matched(paths::ID_REPOS) => Some("CreateRepo"), // GetRepoInfo - GET /repos/{repoId} - &hyper::Method::GET if path.matched(paths::ID_REPOS_REPOID) => Some("GetRepoInfo"), + hyper::Method::GET if path.matched(paths::ID_REPOS_REPOID) => Some("GetRepoInfo"), _ => None, } } diff --git a/samples/server/petstore/rust-server/output/ops-v3/examples/server/server.rs b/samples/server/petstore/rust-server/output/ops-v3/examples/server/server.rs index ffd7d59c8042..0f5e145f345a 100644 --- a/samples/server/petstore/rust-server/output/ops-v3/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/ops-v3/examples/server/server.rs @@ -32,6 +32,7 @@ pub async fn create(addr: &str, https: bool) { let service = MakeAllowAllAuthenticator::new(service, "cosmo"); + #[allow(unused_mut)] let mut service = ops_v3::server::context::MakeAddContext::<_, EmptyContext>::new( service diff --git a/samples/server/petstore/rust-server/output/ops-v3/src/lib.rs b/samples/server/petstore/rust-server/output/ops-v3/src/lib.rs index 2c47196b1dd2..4cc7e28f7397 100644 --- a/samples/server/petstore/rust-server/output/ops-v3/src/lib.rs +++ b/samples/server/petstore/rust-server/output/ops-v3/src/lib.rs @@ -1,5 +1,6 @@ #![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] -#![allow(unused_imports)] +#![allow(unused_imports, unused_attributes)] +#![allow(clippy::derive_partial_eq_without_eq, clippy::blacklisted_name)] use async_trait::async_trait; use futures::Stream; @@ -237,6 +238,7 @@ pub enum Op9GetResponse { /// API #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait Api { fn poll_ready(&self, _cx: &mut Context) -> Poll>> { Poll::Ready(Ok(())) @@ -394,6 +396,7 @@ pub trait Api { /// API where `Context` isn't passed on every API call #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait ApiNoContext { fn poll_ready(&self, _cx: &mut Context) -> Poll>>; diff --git a/samples/server/petstore/rust-server/output/ops-v3/src/server/mod.rs b/samples/server/petstore/rust-server/output/ops-v3/src/server/mod.rs index 438fe894ae93..e27cc1ed58c6 100644 --- a/samples/server/petstore/rust-server/output/ops-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/ops-v3/src/server/mod.rs @@ -206,7 +206,7 @@ impl Service where { pub fn new(api_impl: T) -> Self { Service { - api_impl: api_impl, + api_impl, marker: PhantomData } } @@ -219,7 +219,7 @@ impl Clone for Service where fn clone(&self) -> Self { Service { api_impl: self.api_impl.clone(), - marker: self.marker.clone(), + marker: self.marker, } } } @@ -245,17 +245,17 @@ impl hyper::service::Service<(Request, C)> for Service where let (method, uri, headers) = (parts.method, parts.uri, parts.headers); let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); - match &method { + match method { // Op10Get - GET /op10 - &hyper::Method::GET if path.matched(paths::ID_OP10) => { + hyper::Method::GET if path.matched(paths::ID_OP10) => { let result = api_impl.op10_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -277,14 +277,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op11Get - GET /op11 - &hyper::Method::GET if path.matched(paths::ID_OP11) => { + hyper::Method::GET if path.matched(paths::ID_OP11) => { let result = api_impl.op11_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -306,14 +306,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op12Get - GET /op12 - &hyper::Method::GET if path.matched(paths::ID_OP12) => { + hyper::Method::GET if path.matched(paths::ID_OP12) => { let result = api_impl.op12_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -335,14 +335,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op13Get - GET /op13 - &hyper::Method::GET if path.matched(paths::ID_OP13) => { + hyper::Method::GET if path.matched(paths::ID_OP13) => { let result = api_impl.op13_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -364,14 +364,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op14Get - GET /op14 - &hyper::Method::GET if path.matched(paths::ID_OP14) => { + hyper::Method::GET if path.matched(paths::ID_OP14) => { let result = api_impl.op14_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -393,14 +393,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op15Get - GET /op15 - &hyper::Method::GET if path.matched(paths::ID_OP15) => { + hyper::Method::GET if path.matched(paths::ID_OP15) => { let result = api_impl.op15_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -422,14 +422,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op16Get - GET /op16 - &hyper::Method::GET if path.matched(paths::ID_OP16) => { + hyper::Method::GET if path.matched(paths::ID_OP16) => { let result = api_impl.op16_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -451,14 +451,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op17Get - GET /op17 - &hyper::Method::GET if path.matched(paths::ID_OP17) => { + hyper::Method::GET if path.matched(paths::ID_OP17) => { let result = api_impl.op17_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -480,14 +480,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op18Get - GET /op18 - &hyper::Method::GET if path.matched(paths::ID_OP18) => { + hyper::Method::GET if path.matched(paths::ID_OP18) => { let result = api_impl.op18_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -509,14 +509,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op19Get - GET /op19 - &hyper::Method::GET if path.matched(paths::ID_OP19) => { + hyper::Method::GET if path.matched(paths::ID_OP19) => { let result = api_impl.op19_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -538,14 +538,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op1Get - GET /op1 - &hyper::Method::GET if path.matched(paths::ID_OP1) => { + hyper::Method::GET if path.matched(paths::ID_OP1) => { let result = api_impl.op1_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -567,14 +567,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op20Get - GET /op20 - &hyper::Method::GET if path.matched(paths::ID_OP20) => { + hyper::Method::GET if path.matched(paths::ID_OP20) => { let result = api_impl.op20_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -596,14 +596,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op21Get - GET /op21 - &hyper::Method::GET if path.matched(paths::ID_OP21) => { + hyper::Method::GET if path.matched(paths::ID_OP21) => { let result = api_impl.op21_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -625,14 +625,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op22Get - GET /op22 - &hyper::Method::GET if path.matched(paths::ID_OP22) => { + hyper::Method::GET if path.matched(paths::ID_OP22) => { let result = api_impl.op22_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -654,14 +654,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op23Get - GET /op23 - &hyper::Method::GET if path.matched(paths::ID_OP23) => { + hyper::Method::GET if path.matched(paths::ID_OP23) => { let result = api_impl.op23_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -683,14 +683,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op24Get - GET /op24 - &hyper::Method::GET if path.matched(paths::ID_OP24) => { + hyper::Method::GET if path.matched(paths::ID_OP24) => { let result = api_impl.op24_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -712,14 +712,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op25Get - GET /op25 - &hyper::Method::GET if path.matched(paths::ID_OP25) => { + hyper::Method::GET if path.matched(paths::ID_OP25) => { let result = api_impl.op25_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -741,14 +741,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op26Get - GET /op26 - &hyper::Method::GET if path.matched(paths::ID_OP26) => { + hyper::Method::GET if path.matched(paths::ID_OP26) => { let result = api_impl.op26_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -770,14 +770,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op27Get - GET /op27 - &hyper::Method::GET if path.matched(paths::ID_OP27) => { + hyper::Method::GET if path.matched(paths::ID_OP27) => { let result = api_impl.op27_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -799,14 +799,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op28Get - GET /op28 - &hyper::Method::GET if path.matched(paths::ID_OP28) => { + hyper::Method::GET if path.matched(paths::ID_OP28) => { let result = api_impl.op28_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -828,14 +828,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op29Get - GET /op29 - &hyper::Method::GET if path.matched(paths::ID_OP29) => { + hyper::Method::GET if path.matched(paths::ID_OP29) => { let result = api_impl.op29_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -857,14 +857,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op2Get - GET /op2 - &hyper::Method::GET if path.matched(paths::ID_OP2) => { + hyper::Method::GET if path.matched(paths::ID_OP2) => { let result = api_impl.op2_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -886,14 +886,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op30Get - GET /op30 - &hyper::Method::GET if path.matched(paths::ID_OP30) => { + hyper::Method::GET if path.matched(paths::ID_OP30) => { let result = api_impl.op30_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -915,14 +915,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op31Get - GET /op31 - &hyper::Method::GET if path.matched(paths::ID_OP31) => { + hyper::Method::GET if path.matched(paths::ID_OP31) => { let result = api_impl.op31_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -944,14 +944,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op32Get - GET /op32 - &hyper::Method::GET if path.matched(paths::ID_OP32) => { + hyper::Method::GET if path.matched(paths::ID_OP32) => { let result = api_impl.op32_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -973,14 +973,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op33Get - GET /op33 - &hyper::Method::GET if path.matched(paths::ID_OP33) => { + hyper::Method::GET if path.matched(paths::ID_OP33) => { let result = api_impl.op33_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1002,14 +1002,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op34Get - GET /op34 - &hyper::Method::GET if path.matched(paths::ID_OP34) => { + hyper::Method::GET if path.matched(paths::ID_OP34) => { let result = api_impl.op34_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1031,14 +1031,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op35Get - GET /op35 - &hyper::Method::GET if path.matched(paths::ID_OP35) => { + hyper::Method::GET if path.matched(paths::ID_OP35) => { let result = api_impl.op35_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1060,14 +1060,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op36Get - GET /op36 - &hyper::Method::GET if path.matched(paths::ID_OP36) => { + hyper::Method::GET if path.matched(paths::ID_OP36) => { let result = api_impl.op36_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1089,14 +1089,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op37Get - GET /op37 - &hyper::Method::GET if path.matched(paths::ID_OP37) => { + hyper::Method::GET if path.matched(paths::ID_OP37) => { let result = api_impl.op37_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1118,14 +1118,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op3Get - GET /op3 - &hyper::Method::GET if path.matched(paths::ID_OP3) => { + hyper::Method::GET if path.matched(paths::ID_OP3) => { let result = api_impl.op3_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1147,14 +1147,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op4Get - GET /op4 - &hyper::Method::GET if path.matched(paths::ID_OP4) => { + hyper::Method::GET if path.matched(paths::ID_OP4) => { let result = api_impl.op4_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1176,14 +1176,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op5Get - GET /op5 - &hyper::Method::GET if path.matched(paths::ID_OP5) => { + hyper::Method::GET if path.matched(paths::ID_OP5) => { let result = api_impl.op5_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1205,14 +1205,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op6Get - GET /op6 - &hyper::Method::GET if path.matched(paths::ID_OP6) => { + hyper::Method::GET if path.matched(paths::ID_OP6) => { let result = api_impl.op6_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1234,14 +1234,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op7Get - GET /op7 - &hyper::Method::GET if path.matched(paths::ID_OP7) => { + hyper::Method::GET if path.matched(paths::ID_OP7) => { let result = api_impl.op7_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1263,14 +1263,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op8Get - GET /op8 - &hyper::Method::GET if path.matched(paths::ID_OP8) => { + hyper::Method::GET if path.matched(paths::ID_OP8) => { let result = api_impl.op8_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1292,14 +1292,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Op9Get - GET /op9 - &hyper::Method::GET if path.matched(paths::ID_OP9) => { + hyper::Method::GET if path.matched(paths::ID_OP9) => { let result = api_impl.op9_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1369,81 +1369,81 @@ pub struct ApiRequestParser; impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Option<&'static str> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); - match request.method() { + match *request.method() { // Op10Get - GET /op10 - &hyper::Method::GET if path.matched(paths::ID_OP10) => Some("Op10Get"), + hyper::Method::GET if path.matched(paths::ID_OP10) => Some("Op10Get"), // Op11Get - GET /op11 - &hyper::Method::GET if path.matched(paths::ID_OP11) => Some("Op11Get"), + hyper::Method::GET if path.matched(paths::ID_OP11) => Some("Op11Get"), // Op12Get - GET /op12 - &hyper::Method::GET if path.matched(paths::ID_OP12) => Some("Op12Get"), + hyper::Method::GET if path.matched(paths::ID_OP12) => Some("Op12Get"), // Op13Get - GET /op13 - &hyper::Method::GET if path.matched(paths::ID_OP13) => Some("Op13Get"), + hyper::Method::GET if path.matched(paths::ID_OP13) => Some("Op13Get"), // Op14Get - GET /op14 - &hyper::Method::GET if path.matched(paths::ID_OP14) => Some("Op14Get"), + hyper::Method::GET if path.matched(paths::ID_OP14) => Some("Op14Get"), // Op15Get - GET /op15 - &hyper::Method::GET if path.matched(paths::ID_OP15) => Some("Op15Get"), + hyper::Method::GET if path.matched(paths::ID_OP15) => Some("Op15Get"), // Op16Get - GET /op16 - &hyper::Method::GET if path.matched(paths::ID_OP16) => Some("Op16Get"), + hyper::Method::GET if path.matched(paths::ID_OP16) => Some("Op16Get"), // Op17Get - GET /op17 - &hyper::Method::GET if path.matched(paths::ID_OP17) => Some("Op17Get"), + hyper::Method::GET if path.matched(paths::ID_OP17) => Some("Op17Get"), // Op18Get - GET /op18 - &hyper::Method::GET if path.matched(paths::ID_OP18) => Some("Op18Get"), + hyper::Method::GET if path.matched(paths::ID_OP18) => Some("Op18Get"), // Op19Get - GET /op19 - &hyper::Method::GET if path.matched(paths::ID_OP19) => Some("Op19Get"), + hyper::Method::GET if path.matched(paths::ID_OP19) => Some("Op19Get"), // Op1Get - GET /op1 - &hyper::Method::GET if path.matched(paths::ID_OP1) => Some("Op1Get"), + hyper::Method::GET if path.matched(paths::ID_OP1) => Some("Op1Get"), // Op20Get - GET /op20 - &hyper::Method::GET if path.matched(paths::ID_OP20) => Some("Op20Get"), + hyper::Method::GET if path.matched(paths::ID_OP20) => Some("Op20Get"), // Op21Get - GET /op21 - &hyper::Method::GET if path.matched(paths::ID_OP21) => Some("Op21Get"), + hyper::Method::GET if path.matched(paths::ID_OP21) => Some("Op21Get"), // Op22Get - GET /op22 - &hyper::Method::GET if path.matched(paths::ID_OP22) => Some("Op22Get"), + hyper::Method::GET if path.matched(paths::ID_OP22) => Some("Op22Get"), // Op23Get - GET /op23 - &hyper::Method::GET if path.matched(paths::ID_OP23) => Some("Op23Get"), + hyper::Method::GET if path.matched(paths::ID_OP23) => Some("Op23Get"), // Op24Get - GET /op24 - &hyper::Method::GET if path.matched(paths::ID_OP24) => Some("Op24Get"), + hyper::Method::GET if path.matched(paths::ID_OP24) => Some("Op24Get"), // Op25Get - GET /op25 - &hyper::Method::GET if path.matched(paths::ID_OP25) => Some("Op25Get"), + hyper::Method::GET if path.matched(paths::ID_OP25) => Some("Op25Get"), // Op26Get - GET /op26 - &hyper::Method::GET if path.matched(paths::ID_OP26) => Some("Op26Get"), + hyper::Method::GET if path.matched(paths::ID_OP26) => Some("Op26Get"), // Op27Get - GET /op27 - &hyper::Method::GET if path.matched(paths::ID_OP27) => Some("Op27Get"), + hyper::Method::GET if path.matched(paths::ID_OP27) => Some("Op27Get"), // Op28Get - GET /op28 - &hyper::Method::GET if path.matched(paths::ID_OP28) => Some("Op28Get"), + hyper::Method::GET if path.matched(paths::ID_OP28) => Some("Op28Get"), // Op29Get - GET /op29 - &hyper::Method::GET if path.matched(paths::ID_OP29) => Some("Op29Get"), + hyper::Method::GET if path.matched(paths::ID_OP29) => Some("Op29Get"), // Op2Get - GET /op2 - &hyper::Method::GET if path.matched(paths::ID_OP2) => Some("Op2Get"), + hyper::Method::GET if path.matched(paths::ID_OP2) => Some("Op2Get"), // Op30Get - GET /op30 - &hyper::Method::GET if path.matched(paths::ID_OP30) => Some("Op30Get"), + hyper::Method::GET if path.matched(paths::ID_OP30) => Some("Op30Get"), // Op31Get - GET /op31 - &hyper::Method::GET if path.matched(paths::ID_OP31) => Some("Op31Get"), + hyper::Method::GET if path.matched(paths::ID_OP31) => Some("Op31Get"), // Op32Get - GET /op32 - &hyper::Method::GET if path.matched(paths::ID_OP32) => Some("Op32Get"), + hyper::Method::GET if path.matched(paths::ID_OP32) => Some("Op32Get"), // Op33Get - GET /op33 - &hyper::Method::GET if path.matched(paths::ID_OP33) => Some("Op33Get"), + hyper::Method::GET if path.matched(paths::ID_OP33) => Some("Op33Get"), // Op34Get - GET /op34 - &hyper::Method::GET if path.matched(paths::ID_OP34) => Some("Op34Get"), + hyper::Method::GET if path.matched(paths::ID_OP34) => Some("Op34Get"), // Op35Get - GET /op35 - &hyper::Method::GET if path.matched(paths::ID_OP35) => Some("Op35Get"), + hyper::Method::GET if path.matched(paths::ID_OP35) => Some("Op35Get"), // Op36Get - GET /op36 - &hyper::Method::GET if path.matched(paths::ID_OP36) => Some("Op36Get"), + hyper::Method::GET if path.matched(paths::ID_OP36) => Some("Op36Get"), // Op37Get - GET /op37 - &hyper::Method::GET if path.matched(paths::ID_OP37) => Some("Op37Get"), + hyper::Method::GET if path.matched(paths::ID_OP37) => Some("Op37Get"), // Op3Get - GET /op3 - &hyper::Method::GET if path.matched(paths::ID_OP3) => Some("Op3Get"), + hyper::Method::GET if path.matched(paths::ID_OP3) => Some("Op3Get"), // Op4Get - GET /op4 - &hyper::Method::GET if path.matched(paths::ID_OP4) => Some("Op4Get"), + hyper::Method::GET if path.matched(paths::ID_OP4) => Some("Op4Get"), // Op5Get - GET /op5 - &hyper::Method::GET if path.matched(paths::ID_OP5) => Some("Op5Get"), + hyper::Method::GET if path.matched(paths::ID_OP5) => Some("Op5Get"), // Op6Get - GET /op6 - &hyper::Method::GET if path.matched(paths::ID_OP6) => Some("Op6Get"), + hyper::Method::GET if path.matched(paths::ID_OP6) => Some("Op6Get"), // Op7Get - GET /op7 - &hyper::Method::GET if path.matched(paths::ID_OP7) => Some("Op7Get"), + hyper::Method::GET if path.matched(paths::ID_OP7) => Some("Op7Get"), // Op8Get - GET /op8 - &hyper::Method::GET if path.matched(paths::ID_OP8) => Some("Op8Get"), + hyper::Method::GET if path.matched(paths::ID_OP8) => Some("Op8Get"), // Op9Get - GET /op9 - &hyper::Method::GET if path.matched(paths::ID_OP9) => Some("Op9Get"), + hyper::Method::GET if path.matched(paths::ID_OP9) => Some("Op9Get"), _ => None, } } diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server/server.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server/server.rs index e86eaae25fb5..304590c34f17 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server/server.rs @@ -32,6 +32,7 @@ pub async fn create(addr: &str, https: bool) { let service = MakeAllowAllAuthenticator::new(service, "cosmo"); + #[allow(unused_mut)] let mut service = petstore_with_fake_endpoints_models_for_testing::server::context::MakeAddContext::<_, EmptyContext>::new( service diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs index a4b4158b4ff7..0ea239e35c8f 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs @@ -1088,7 +1088,7 @@ impl Api for Client where let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.append_pair("query", - ¶m_query.to_string()); + ¶m_query); query_string.finish() }; if !query_string.is_empty() { @@ -1315,8 +1315,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Basic(ref basic_header) => { let auth = swagger::auth::Header(basic_header.clone()); @@ -1392,7 +1394,7 @@ impl Api for Client where } if let Some(param_enum_query_string) = param_enum_query_string { query_string.append_pair("enum_query_string", - ¶m_enum_query_string.to_string()); + ¶m_enum_query_string); } if let Some(param_enum_query_integer) = param_enum_query_integer { query_string.append_pair("enum_query_integer", @@ -1444,6 +1446,7 @@ impl Api for Client where Some(param_enum_header_string_array) => { request.headers_mut().append( HeaderName::from_static("enum_header_string_array"), + #[allow(clippy::redundant_clone)] match header::IntoHeaderValue(param_enum_header_string_array.clone()).try_into() { Ok(header) => header, Err(e) => { @@ -1459,6 +1462,7 @@ impl Api for Client where Some(param_enum_header_string) => { request.headers_mut().append( HeaderName::from_static("enum_header_string"), + #[allow(clippy::redundant_clone)] match header::IntoHeaderValue(param_enum_header_string.clone()).try_into() { Ok(header) => header, Err(e) => { @@ -1677,10 +1681,8 @@ impl Api for Client where // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); - if let Some(auth_data) = (context as &dyn Has>).get().as_ref() { - if let AuthData::ApiKey(ref api_key) = *auth_data { - query_string.append_pair("api_key_query", api_key); - } + if let Some(AuthData::ApiKey(ref api_key)) = (context as &dyn Has>).get().as_ref() { + query_string.append_pair("api_key_query", api_key); } query_string.finish() }; @@ -1719,8 +1721,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { _ => {} } @@ -1799,7 +1803,7 @@ impl Api for Client where }; // Body parameter - let body = param_body.to_xml(); + let body = param_body.as_xml(); *request.body_mut() = Body::from(body); let header = "application/json"; @@ -1813,8 +1817,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); @@ -1901,8 +1907,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); @@ -1923,6 +1931,7 @@ impl Api for Client where Some(param_api_key) => { request.headers_mut().append( HeaderName::from_static("api_key"), + #[allow(clippy::redundant_clone)] match header::IntoHeaderValue(param_api_key.clone()).try_into() { Ok(header) => header, Err(e) => { @@ -2005,8 +2014,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); @@ -2108,8 +2119,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); @@ -2210,8 +2223,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { _ => {} } @@ -2300,7 +2315,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))) }; - let body = param_body.to_xml(); + let body = param_body.as_xml(); *request.body_mut() = Body::from(body); let header = "application/json"; @@ -2314,8 +2329,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); @@ -2425,8 +2442,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); @@ -2569,8 +2588,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); @@ -2738,8 +2759,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { _ => {} } @@ -3380,9 +3403,9 @@ impl Api for Client where let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.append_pair("username", - ¶m_username.to_string()); + ¶m_username); query_string.append_pair("password", - ¶m_password.to_string()); + ¶m_password); query_string.finish() }; if !query_string.is_empty() { @@ -3423,8 +3446,7 @@ impl Api for Client where return Err(ApiError(format!("Invalid response header X-Rate-Limit for response 200 - {}", e))); }, }; - let response_x_rate_limit = response_x_rate_limit.0; - Some(response_x_rate_limit) + Some(response_x_rate_limit.0) }, None => None, }; @@ -3438,8 +3460,7 @@ impl Api for Client where return Err(ApiError(format!("Invalid response header X-Expires-After for response 200 - {}", e))); }, }; - let response_x_expires_after = response_x_expires_after.0; - Some(response_x_expires_after) + Some(response_x_expires_after.0) }, None => None, }; @@ -3456,7 +3477,7 @@ impl Api for Client where .map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?; Ok(LoginUserResponse::SuccessfulOperation { - body: body, + body, x_rate_limit: response_x_rate_limit, x_expires_after: response_x_expires_after, } diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/context.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/context.rs index d9b711341769..dc28f08c1cf4 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/context.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/context.rs @@ -107,7 +107,7 @@ impl Service> for AddContext); @@ -119,7 +119,7 @@ impl Service> for AddContext Service> for AddContext(&headers) { + if let Some(basic) = swagger::auth::from_headers::(headers) { let auth_data = AuthData::Basic(basic); let context = context.push(Some(auth_data)); let context = context.push(None::); @@ -142,7 +142,7 @@ impl Service> for AddContext(&headers) { + if let Some(bearer) = swagger::auth::from_headers::(headers) { let auth_data = AuthData::Bearer(bearer); let context = context.push(Some(auth_data)); let context = context.push(None::); diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs index f011e13ecb2a..18a5ecab0249 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs @@ -1,5 +1,6 @@ #![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] -#![allow(unused_imports)] +#![allow(unused_imports, unused_attributes)] +#![allow(clippy::derive_partial_eq_without_eq, clippy::blacklisted_name)] use async_trait::async_trait; use futures::Stream; @@ -316,6 +317,7 @@ pub enum UpdateUserResponse { /// API #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait Api { fn poll_ready(&self, _cx: &mut Context) -> Poll>> { Poll::Ready(Ok(())) @@ -551,6 +553,7 @@ pub trait Api { /// API where `Context` isn't passed on every API call #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait ApiNoContext { fn poll_ready(&self, _cx: &mut Context) -> Poll>>; diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs index df387fdf1d5b..cab73c967ba8 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs @@ -18,6 +18,7 @@ pub struct AdditionalPropertiesClass { } impl AdditionalPropertiesClass { + #[allow(clippy::new_without_default)] pub fn new() -> AdditionalPropertiesClass { AdditionalPropertiesClass { map_property: None, @@ -31,13 +32,15 @@ impl AdditionalPropertiesClass { /// Should be implemented in a serde serializer impl std::string::ToString for AdditionalPropertiesClass { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - // Skipping map_property in query parameter serialization + let params: Vec> = vec![ + // Skipping map_property in query parameter serialization - // Skipping map_of_map_property in query parameter serialization - // Skipping map_of_map_property in query parameter serialization + // Skipping map_of_map_property in query parameter serialization + // Skipping map_of_map_property in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -48,8 +51,9 @@ impl std::str::FromStr for AdditionalPropertiesClass { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub map_property: Vec>, pub map_of_map_property: Vec>>, @@ -58,7 +62,7 @@ impl std::str::FromStr for AdditionalPropertiesClass { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -68,6 +72,7 @@ impl std::str::FromStr for AdditionalPropertiesClass { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { "map_property" => return std::result::Result::Err("Parsing a container in this style is not supported in AdditionalPropertiesClass".to_string()), "map_of_map_property" => return std::result::Result::Err("Parsing a container in this style is not supported in AdditionalPropertiesClass".to_string()), @@ -130,7 +135,7 @@ impl AdditionalPropertiesClass { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -148,9 +153,10 @@ pub struct Animal { } impl Animal { + #[allow(clippy::new_without_default)] pub fn new(class_name: String, ) -> Animal { Animal { - class_name: class_name, + class_name, color: Some("red".to_string()), } } @@ -161,18 +167,22 @@ impl Animal { /// Should be implemented in a serde serializer impl std::string::ToString for Animal { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - params.push("className".to_string()); - params.push(self.class_name.to_string()); + Some("className".to_string()), + Some(self.class_name.to_string()), - if let Some(ref color) = self.color { - params.push("color".to_string()); - params.push(color.to_string()); - } + self.color.as_ref().map(|color| { + vec![ + "color".to_string(), + color.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -183,8 +193,9 @@ impl std::str::FromStr for Animal { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub class_name: Vec, pub color: Vec, @@ -193,7 +204,7 @@ impl std::str::FromStr for Animal { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -203,9 +214,12 @@ impl std::str::FromStr for Animal { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| format!("{}", x))?), - "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Animal".to_string()) } } @@ -216,7 +230,7 @@ impl std::str::FromStr for Animal { // Use the intermediate representation to return the struct std::result::Result::Ok(Animal { - class_name: intermediate_rep.class_name.into_iter().next().ok_or("className missing in Animal".to_string())?, + class_name: intermediate_rep.class_name.into_iter().next().ok_or_else(|| "className missing in Animal".to_string())?, color: intermediate_rep.color.into_iter().next(), }) } @@ -265,7 +279,7 @@ impl Animal { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -308,7 +322,7 @@ impl<'a> std::iter::IntoIterator for &'a AnimalFarm { type IntoIter = std::slice::Iter<'a, Animal>; fn into_iter(self) -> Self::IntoIter { - (&self.0).into_iter() + (&self.0).iter() } } @@ -317,7 +331,7 @@ impl<'a> std::iter::IntoIterator for &'a mut AnimalFarm { type IntoIter = std::slice::IterMut<'a, Animal>; fn into_iter(self) -> Self::IntoIter { - (&mut self.0).into_iter() + (&mut self.0).iter_mut() } } @@ -339,7 +353,7 @@ impl std::ops::DerefMut for AnimalFarm { /// Should be implemented in a serde serializer impl std::string::ToString for AnimalFarm { fn to_string(&self) -> String { - self.iter().map(|x| x.to_string()).collect::>().join(",").to_string() + self.iter().map(|x| x.to_string()).collect::>().join(",") } } @@ -403,7 +417,7 @@ impl AnimalFarm { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -426,6 +440,7 @@ pub struct ApiResponse { } impl ApiResponse { + #[allow(clippy::new_without_default)] pub fn new() -> ApiResponse { ApiResponse { code: None, @@ -440,26 +455,34 @@ impl ApiResponse { /// Should be implemented in a serde serializer impl std::string::ToString for ApiResponse { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref code) = self.code { - params.push("code".to_string()); - params.push(code.to_string()); - } + self.code.as_ref().map(|code| { + vec![ + "code".to_string(), + code.to_string(), + ].join(",") + }), - if let Some(ref r#type) = self.r#type { - params.push("type".to_string()); - params.push(r#type.to_string()); - } + self.r#type.as_ref().map(|r#type| { + vec![ + "type".to_string(), + r#type.to_string(), + ].join(",") + }), - if let Some(ref message) = self.message { - params.push("message".to_string()); - params.push(message.to_string()); - } + self.message.as_ref().map(|message| { + vec![ + "message".to_string(), + message.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -470,8 +493,9 @@ impl std::str::FromStr for ApiResponse { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub code: Vec, pub r#type: Vec, @@ -481,7 +505,7 @@ impl std::str::FromStr for ApiResponse { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -491,10 +515,14 @@ impl std::str::FromStr for ApiResponse { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "code" => intermediate_rep.code.push(::from_str(val).map_err(|x| format!("{}", x))?), - "type" => intermediate_rep.r#type.push(::from_str(val).map_err(|x| format!("{}", x))?), - "message" => intermediate_rep.message.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "code" => intermediate_rep.code.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "type" => intermediate_rep.r#type.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "message" => intermediate_rep.message.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ApiResponse".to_string()) } } @@ -555,7 +583,7 @@ impl ApiResponse { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -570,6 +598,7 @@ pub struct ArrayOfArrayOfNumberOnly { } impl ArrayOfArrayOfNumberOnly { + #[allow(clippy::new_without_default)] pub fn new() -> ArrayOfArrayOfNumberOnly { ArrayOfArrayOfNumberOnly { array_array_number: None, @@ -582,10 +611,12 @@ impl ArrayOfArrayOfNumberOnly { /// Should be implemented in a serde serializer impl std::string::ToString for ArrayOfArrayOfNumberOnly { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - // Skipping ArrayArrayNumber in query parameter serialization + let params: Vec> = vec![ + // Skipping ArrayArrayNumber in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -596,8 +627,9 @@ impl std::str::FromStr for ArrayOfArrayOfNumberOnly { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub array_array_number: Vec>>, } @@ -605,7 +637,7 @@ impl std::str::FromStr for ArrayOfArrayOfNumberOnly { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -615,6 +647,7 @@ impl std::str::FromStr for ArrayOfArrayOfNumberOnly { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { "ArrayArrayNumber" => return std::result::Result::Err("Parsing a container in this style is not supported in ArrayOfArrayOfNumberOnly".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing ArrayOfArrayOfNumberOnly".to_string()) @@ -675,7 +708,7 @@ impl ArrayOfArrayOfNumberOnly { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -690,6 +723,7 @@ pub struct ArrayOfNumberOnly { } impl ArrayOfNumberOnly { + #[allow(clippy::new_without_default)] pub fn new() -> ArrayOfNumberOnly { ArrayOfNumberOnly { array_number: None, @@ -702,14 +736,18 @@ impl ArrayOfNumberOnly { /// Should be implemented in a serde serializer impl std::string::ToString for ArrayOfNumberOnly { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref array_number) = self.array_number { - params.push("ArrayNumber".to_string()); - params.push(array_number.iter().map(|x| x.to_string()).collect::>().join(",").to_string()); - } + self.array_number.as_ref().map(|array_number| { + vec![ + "ArrayNumber".to_string(), + array_number.iter().map(|x| x.to_string()).collect::>().join(","), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -720,8 +758,9 @@ impl std::str::FromStr for ArrayOfNumberOnly { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub array_number: Vec>, } @@ -729,7 +768,7 @@ impl std::str::FromStr for ArrayOfNumberOnly { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -739,6 +778,7 @@ impl std::str::FromStr for ArrayOfNumberOnly { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { "ArrayNumber" => return std::result::Result::Err("Parsing a container in this style is not supported in ArrayOfNumberOnly".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing ArrayOfNumberOnly".to_string()) @@ -799,7 +839,7 @@ impl ArrayOfNumberOnly { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -827,6 +867,7 @@ pub struct ArrayTest { } impl ArrayTest { + #[allow(clippy::new_without_default)] pub fn new() -> ArrayTest { ArrayTest { array_of_string: None, @@ -842,24 +883,30 @@ impl ArrayTest { /// Should be implemented in a serde serializer impl std::string::ToString for ArrayTest { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref array_of_string) = self.array_of_string { - params.push("array_of_string".to_string()); - params.push(array_of_string.iter().map(|x| x.to_string()).collect::>().join(",").to_string()); - } + self.array_of_string.as_ref().map(|array_of_string| { + vec![ + "array_of_string".to_string(), + array_of_string.iter().map(|x| x.to_string()).collect::>().join(","), + ].join(",") + }), - // Skipping array_array_of_integer in query parameter serialization + // Skipping array_array_of_integer in query parameter serialization - // Skipping array_array_of_model in query parameter serialization + // Skipping array_array_of_model in query parameter serialization - if let Some(ref array_of_enum) = self.array_of_enum { - params.push("array_of_enum".to_string()); - params.push(array_of_enum.iter().map(|x| x.to_string()).collect::>().join(",").to_string()); - } + self.array_of_enum.as_ref().map(|array_of_enum| { + vec![ + "array_of_enum".to_string(), + array_of_enum.iter().map(|x| x.to_string()).collect::>().join(","), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -870,8 +917,9 @@ impl std::str::FromStr for ArrayTest { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub array_of_string: Vec>, pub array_array_of_integer: Vec>>, @@ -882,7 +930,7 @@ impl std::str::FromStr for ArrayTest { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -892,6 +940,7 @@ impl std::str::FromStr for ArrayTest { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { "array_of_string" => return std::result::Result::Err("Parsing a container in this style is not supported in ArrayTest".to_string()), "array_array_of_integer" => return std::result::Result::Err("Parsing a container in this style is not supported in ArrayTest".to_string()), @@ -958,7 +1007,7 @@ impl ArrayTest { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -994,6 +1043,7 @@ pub struct Capitalization { } impl Capitalization { + #[allow(clippy::new_without_default)] pub fn new() -> Capitalization { Capitalization { small_camel: None, @@ -1011,44 +1061,58 @@ impl Capitalization { /// Should be implemented in a serde serializer impl std::string::ToString for Capitalization { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref small_camel) = self.small_camel { - params.push("smallCamel".to_string()); - params.push(small_camel.to_string()); - } + self.small_camel.as_ref().map(|small_camel| { + vec![ + "smallCamel".to_string(), + small_camel.to_string(), + ].join(",") + }), - if let Some(ref capital_camel) = self.capital_camel { - params.push("CapitalCamel".to_string()); - params.push(capital_camel.to_string()); - } + self.capital_camel.as_ref().map(|capital_camel| { + vec![ + "CapitalCamel".to_string(), + capital_camel.to_string(), + ].join(",") + }), - if let Some(ref small_snake) = self.small_snake { - params.push("small_Snake".to_string()); - params.push(small_snake.to_string()); - } + self.small_snake.as_ref().map(|small_snake| { + vec![ + "small_Snake".to_string(), + small_snake.to_string(), + ].join(",") + }), - if let Some(ref capital_snake) = self.capital_snake { - params.push("Capital_Snake".to_string()); - params.push(capital_snake.to_string()); - } + self.capital_snake.as_ref().map(|capital_snake| { + vec![ + "Capital_Snake".to_string(), + capital_snake.to_string(), + ].join(",") + }), - if let Some(ref sca_eth_flow_points) = self.sca_eth_flow_points { - params.push("SCA_ETH_Flow_Points".to_string()); - params.push(sca_eth_flow_points.to_string()); - } + self.sca_eth_flow_points.as_ref().map(|sca_eth_flow_points| { + vec![ + "SCA_ETH_Flow_Points".to_string(), + sca_eth_flow_points.to_string(), + ].join(",") + }), - if let Some(ref att_name) = self.att_name { - params.push("ATT_NAME".to_string()); - params.push(att_name.to_string()); - } + self.att_name.as_ref().map(|att_name| { + vec![ + "ATT_NAME".to_string(), + att_name.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1059,8 +1123,9 @@ impl std::str::FromStr for Capitalization { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub small_camel: Vec, pub capital_camel: Vec, @@ -1073,7 +1138,7 @@ impl std::str::FromStr for Capitalization { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1083,13 +1148,20 @@ impl std::str::FromStr for Capitalization { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "smallCamel" => intermediate_rep.small_camel.push(::from_str(val).map_err(|x| format!("{}", x))?), - "CapitalCamel" => intermediate_rep.capital_camel.push(::from_str(val).map_err(|x| format!("{}", x))?), - "small_Snake" => intermediate_rep.small_snake.push(::from_str(val).map_err(|x| format!("{}", x))?), - "Capital_Snake" => intermediate_rep.capital_snake.push(::from_str(val).map_err(|x| format!("{}", x))?), - "SCA_ETH_Flow_Points" => intermediate_rep.sca_eth_flow_points.push(::from_str(val).map_err(|x| format!("{}", x))?), - "ATT_NAME" => intermediate_rep.att_name.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "smallCamel" => intermediate_rep.small_camel.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "CapitalCamel" => intermediate_rep.capital_camel.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "small_Snake" => intermediate_rep.small_snake.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "Capital_Snake" => intermediate_rep.capital_snake.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "SCA_ETH_Flow_Points" => intermediate_rep.sca_eth_flow_points.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "ATT_NAME" => intermediate_rep.att_name.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Capitalization".to_string()) } } @@ -1153,7 +1225,7 @@ impl Capitalization { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1175,9 +1247,10 @@ pub struct Cat { } impl Cat { + #[allow(clippy::new_without_default)] pub fn new(class_name: String, ) -> Cat { Cat { - class_name: class_name, + class_name, color: Some("red".to_string()), declawed: None, } @@ -1189,24 +1262,30 @@ impl Cat { /// Should be implemented in a serde serializer impl std::string::ToString for Cat { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - params.push("className".to_string()); - params.push(self.class_name.to_string()); + Some("className".to_string()), + Some(self.class_name.to_string()), - if let Some(ref color) = self.color { - params.push("color".to_string()); - params.push(color.to_string()); - } + self.color.as_ref().map(|color| { + vec![ + "color".to_string(), + color.to_string(), + ].join(",") + }), - if let Some(ref declawed) = self.declawed { - params.push("declawed".to_string()); - params.push(declawed.to_string()); - } + self.declawed.as_ref().map(|declawed| { + vec![ + "declawed".to_string(), + declawed.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1217,8 +1296,9 @@ impl std::str::FromStr for Cat { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub class_name: Vec, pub color: Vec, @@ -1228,7 +1308,7 @@ impl std::str::FromStr for Cat { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1238,10 +1318,14 @@ impl std::str::FromStr for Cat { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| format!("{}", x))?), - "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| format!("{}", x))?), - "declawed" => intermediate_rep.declawed.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "declawed" => intermediate_rep.declawed.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Cat".to_string()) } } @@ -1252,7 +1336,7 @@ impl std::str::FromStr for Cat { // Use the intermediate representation to return the struct std::result::Result::Ok(Cat { - class_name: intermediate_rep.class_name.into_iter().next().ok_or("className missing in Cat".to_string())?, + class_name: intermediate_rep.class_name.into_iter().next().ok_or_else(|| "className missing in Cat".to_string())?, color: intermediate_rep.color.into_iter().next(), declawed: intermediate_rep.declawed.into_iter().next(), }) @@ -1302,7 +1386,7 @@ impl Cat { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1317,6 +1401,7 @@ pub struct CatAllOf { } impl CatAllOf { + #[allow(clippy::new_without_default)] pub fn new() -> CatAllOf { CatAllOf { declawed: None, @@ -1329,14 +1414,18 @@ impl CatAllOf { /// Should be implemented in a serde serializer impl std::string::ToString for CatAllOf { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref declawed) = self.declawed { - params.push("declawed".to_string()); - params.push(declawed.to_string()); - } + self.declawed.as_ref().map(|declawed| { + vec![ + "declawed".to_string(), + declawed.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1347,8 +1436,9 @@ impl std::str::FromStr for CatAllOf { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub declawed: Vec, } @@ -1356,7 +1446,7 @@ impl std::str::FromStr for CatAllOf { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1366,8 +1456,10 @@ impl std::str::FromStr for CatAllOf { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "declawed" => intermediate_rep.declawed.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "declawed" => intermediate_rep.declawed.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing CatAllOf".to_string()) } } @@ -1426,7 +1518,7 @@ impl CatAllOf { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1446,6 +1538,7 @@ pub struct Category { } impl Category { + #[allow(clippy::new_without_default)] pub fn new() -> Category { Category { id: None, @@ -1459,20 +1552,26 @@ impl Category { /// Should be implemented in a serde serializer impl std::string::ToString for Category { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref id) = self.id { - params.push("id".to_string()); - params.push(id.to_string()); - } + self.id.as_ref().map(|id| { + vec![ + "id".to_string(), + id.to_string(), + ].join(",") + }), - if let Some(ref name) = self.name { - params.push("name".to_string()); - params.push(name.to_string()); - } + self.name.as_ref().map(|name| { + vec![ + "name".to_string(), + name.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1483,8 +1582,9 @@ impl std::str::FromStr for Category { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub id: Vec, pub name: Vec, @@ -1493,7 +1593,7 @@ impl std::str::FromStr for Category { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1503,9 +1603,12 @@ impl std::str::FromStr for Category { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Category".to_string()) } } @@ -1565,7 +1668,7 @@ impl Category { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1581,6 +1684,7 @@ pub struct ClassModel { } impl ClassModel { + #[allow(clippy::new_without_default)] pub fn new() -> ClassModel { ClassModel { _class: None, @@ -1593,14 +1697,18 @@ impl ClassModel { /// Should be implemented in a serde serializer impl std::string::ToString for ClassModel { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref _class) = self._class { - params.push("_class".to_string()); - params.push(_class.to_string()); - } + self._class.as_ref().map(|_class| { + vec![ + "_class".to_string(), + _class.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1611,8 +1719,9 @@ impl std::str::FromStr for ClassModel { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub _class: Vec, } @@ -1620,7 +1729,7 @@ impl std::str::FromStr for ClassModel { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1630,8 +1739,10 @@ impl std::str::FromStr for ClassModel { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "_class" => intermediate_rep._class.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "_class" => intermediate_rep._class.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ClassModel".to_string()) } } @@ -1690,7 +1801,7 @@ impl ClassModel { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1705,6 +1816,7 @@ pub struct Client { } impl Client { + #[allow(clippy::new_without_default)] pub fn new() -> Client { Client { client: None, @@ -1717,14 +1829,18 @@ impl Client { /// Should be implemented in a serde serializer impl std::string::ToString for Client { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref client) = self.client { - params.push("client".to_string()); - params.push(client.to_string()); - } + self.client.as_ref().map(|client| { + vec![ + "client".to_string(), + client.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1735,8 +1851,9 @@ impl std::str::FromStr for Client { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub client: Vec, } @@ -1744,7 +1861,7 @@ impl std::str::FromStr for Client { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1754,8 +1871,10 @@ impl std::str::FromStr for Client { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "client" => intermediate_rep.client.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "client" => intermediate_rep.client.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Client".to_string()) } } @@ -1814,7 +1933,7 @@ impl Client { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1836,9 +1955,10 @@ pub struct Dog { } impl Dog { + #[allow(clippy::new_without_default)] pub fn new(class_name: String, ) -> Dog { Dog { - class_name: class_name, + class_name, color: Some("red".to_string()), breed: None, } @@ -1850,24 +1970,30 @@ impl Dog { /// Should be implemented in a serde serializer impl std::string::ToString for Dog { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - params.push("className".to_string()); - params.push(self.class_name.to_string()); + Some("className".to_string()), + Some(self.class_name.to_string()), - if let Some(ref color) = self.color { - params.push("color".to_string()); - params.push(color.to_string()); - } + self.color.as_ref().map(|color| { + vec![ + "color".to_string(), + color.to_string(), + ].join(",") + }), - if let Some(ref breed) = self.breed { - params.push("breed".to_string()); - params.push(breed.to_string()); - } + self.breed.as_ref().map(|breed| { + vec![ + "breed".to_string(), + breed.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -1878,8 +2004,9 @@ impl std::str::FromStr for Dog { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub class_name: Vec, pub color: Vec, @@ -1889,7 +2016,7 @@ impl std::str::FromStr for Dog { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -1899,10 +2026,14 @@ impl std::str::FromStr for Dog { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| format!("{}", x))?), - "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| format!("{}", x))?), - "breed" => intermediate_rep.breed.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "className" => intermediate_rep.class_name.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "color" => intermediate_rep.color.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "breed" => intermediate_rep.breed.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Dog".to_string()) } } @@ -1913,7 +2044,7 @@ impl std::str::FromStr for Dog { // Use the intermediate representation to return the struct std::result::Result::Ok(Dog { - class_name: intermediate_rep.class_name.into_iter().next().ok_or("className missing in Dog".to_string())?, + class_name: intermediate_rep.class_name.into_iter().next().ok_or_else(|| "className missing in Dog".to_string())?, color: intermediate_rep.color.into_iter().next(), breed: intermediate_rep.breed.into_iter().next(), }) @@ -1963,7 +2094,7 @@ impl Dog { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -1978,6 +2109,7 @@ pub struct DogAllOf { } impl DogAllOf { + #[allow(clippy::new_without_default)] pub fn new() -> DogAllOf { DogAllOf { breed: None, @@ -1990,14 +2122,18 @@ impl DogAllOf { /// Should be implemented in a serde serializer impl std::string::ToString for DogAllOf { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref breed) = self.breed { - params.push("breed".to_string()); - params.push(breed.to_string()); - } + self.breed.as_ref().map(|breed| { + vec![ + "breed".to_string(), + breed.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -2008,8 +2144,9 @@ impl std::str::FromStr for DogAllOf { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub breed: Vec, } @@ -2017,7 +2154,7 @@ impl std::str::FromStr for DogAllOf { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -2027,8 +2164,10 @@ impl std::str::FromStr for DogAllOf { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "breed" => intermediate_rep.breed.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "breed" => intermediate_rep.breed.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing DogAllOf".to_string()) } } @@ -2087,7 +2226,7 @@ impl DogAllOf { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2103,6 +2242,7 @@ pub struct DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket { } impl DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket { + #[allow(clippy::new_without_default)] pub fn new() -> DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket { DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket { dollar_special_left_square_bracket_property_period_name_right_square_bracket: None, @@ -2115,14 +2255,18 @@ impl DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket { /// Should be implemented in a serde serializer impl std::string::ToString for DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref dollar_special_left_square_bracket_property_period_name_right_square_bracket) = self.dollar_special_left_square_bracket_property_period_name_right_square_bracket { - params.push("$special[property.name]".to_string()); - params.push(dollar_special_left_square_bracket_property_period_name_right_square_bracket.to_string()); - } + self.dollar_special_left_square_bracket_property_period_name_right_square_bracket.as_ref().map(|dollar_special_left_square_bracket_property_period_name_right_square_bracket| { + vec![ + "$special[property.name]".to_string(), + dollar_special_left_square_bracket_property_period_name_right_square_bracket.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -2133,8 +2277,9 @@ impl std::str::FromStr for DollarSpecialLeftSquareBracketModelPeriodNameRightSqu type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub dollar_special_left_square_bracket_property_period_name_right_square_bracket: Vec, } @@ -2142,7 +2287,7 @@ impl std::str::FromStr for DollarSpecialLeftSquareBracketModelPeriodNameRightSqu let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -2152,8 +2297,10 @@ impl std::str::FromStr for DollarSpecialLeftSquareBracketModelPeriodNameRightSqu }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "$special[property.name]" => intermediate_rep.dollar_special_left_square_bracket_property_period_name_right_square_bracket.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "$special[property.name]" => intermediate_rep.dollar_special_left_square_bracket_property_period_name_right_square_bracket.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket".to_string()) } } @@ -2212,7 +2359,7 @@ impl DollarSpecialLeftSquareBracketModelPeriodNameRightSquareBracket { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2238,6 +2385,7 @@ pub struct EnumArrays { } impl EnumArrays { + #[allow(clippy::new_without_default)] pub fn new() -> EnumArrays { EnumArrays { just_symbol: None, @@ -2252,22 +2400,28 @@ impl EnumArrays { /// Should be implemented in a serde serializer impl std::string::ToString for EnumArrays { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref just_symbol) = self.just_symbol { - params.push("just_symbol".to_string()); - params.push(just_symbol.to_string()); - } + self.just_symbol.as_ref().map(|just_symbol| { + vec![ + "just_symbol".to_string(), + just_symbol.to_string(), + ].join(",") + }), - if let Some(ref array_enum) = self.array_enum { - params.push("array_enum".to_string()); - params.push(array_enum.iter().map(|x| x.to_string()).collect::>().join(",").to_string()); - } + self.array_enum.as_ref().map(|array_enum| { + vec![ + "array_enum".to_string(), + array_enum.iter().map(|x| x.to_string()).collect::>().join(","), + ].join(",") + }), - // Skipping array_array_enum in query parameter serialization + // Skipping array_array_enum in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -2278,8 +2432,9 @@ impl std::str::FromStr for EnumArrays { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub just_symbol: Vec, pub array_enum: Vec>, @@ -2289,7 +2444,7 @@ impl std::str::FromStr for EnumArrays { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -2299,8 +2454,10 @@ impl std::str::FromStr for EnumArrays { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "just_symbol" => intermediate_rep.just_symbol.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "just_symbol" => intermediate_rep.just_symbol.push(::from_str(val).map_err(|x| x.to_string())?), "array_enum" => return std::result::Result::Err("Parsing a container in this style is not supported in EnumArrays".to_string()), "array_array_enum" => return std::result::Result::Err("Parsing a container in this style is not supported in EnumArrays".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing EnumArrays".to_string()) @@ -2363,7 +2520,7 @@ impl EnumArrays { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2387,9 +2544,9 @@ pub enum EnumClass { impl std::fmt::Display for EnumClass { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self { - EnumClass::Abc => write!(f, "{}", "_abc"), - EnumClass::Efg => write!(f, "{}", "-efg"), - EnumClass::LeftParenthesisXyzRightParenthesis => write!(f, "{}", "(xyz)"), + EnumClass::Abc => write!(f, "_abc"), + EnumClass::Efg => write!(f, "-efg"), + EnumClass::LeftParenthesisXyzRightParenthesis => write!(f, "(xyz)"), } } } @@ -2411,7 +2568,7 @@ impl EnumClass { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2445,10 +2602,11 @@ pub struct EnumTest { } impl EnumTest { + #[allow(clippy::new_without_default)] pub fn new(enum_string_required: String, ) -> EnumTest { EnumTest { enum_string: None, - enum_string_required: enum_string_required, + enum_string_required, enum_integer: None, enum_number: None, outer_enum: None, @@ -2461,32 +2619,40 @@ impl EnumTest { /// Should be implemented in a serde serializer impl std::string::ToString for EnumTest { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref enum_string) = self.enum_string { - params.push("enum_string".to_string()); - params.push(enum_string.to_string()); - } + self.enum_string.as_ref().map(|enum_string| { + vec![ + "enum_string".to_string(), + enum_string.to_string(), + ].join(",") + }), - params.push("enum_string_required".to_string()); - params.push(self.enum_string_required.to_string()); + Some("enum_string_required".to_string()), + Some(self.enum_string_required.to_string()), - if let Some(ref enum_integer) = self.enum_integer { - params.push("enum_integer".to_string()); - params.push(enum_integer.to_string()); - } + self.enum_integer.as_ref().map(|enum_integer| { + vec![ + "enum_integer".to_string(), + enum_integer.to_string(), + ].join(",") + }), - if let Some(ref enum_number) = self.enum_number { - params.push("enum_number".to_string()); - params.push(enum_number.to_string()); - } + self.enum_number.as_ref().map(|enum_number| { + vec![ + "enum_number".to_string(), + enum_number.to_string(), + ].join(",") + }), - // Skipping outerEnum in query parameter serialization + // Skipping outerEnum in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -2497,8 +2663,9 @@ impl std::str::FromStr for EnumTest { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub enum_string: Vec, pub enum_string_required: Vec, @@ -2510,7 +2677,7 @@ impl std::str::FromStr for EnumTest { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -2520,12 +2687,18 @@ impl std::str::FromStr for EnumTest { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "enum_string" => intermediate_rep.enum_string.push(::from_str(val).map_err(|x| format!("{}", x))?), - "enum_string_required" => intermediate_rep.enum_string_required.push(::from_str(val).map_err(|x| format!("{}", x))?), - "enum_integer" => intermediate_rep.enum_integer.push(::from_str(val).map_err(|x| format!("{}", x))?), - "enum_number" => intermediate_rep.enum_number.push(::from_str(val).map_err(|x| format!("{}", x))?), - "outerEnum" => intermediate_rep.outer_enum.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "enum_string" => intermediate_rep.enum_string.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "enum_string_required" => intermediate_rep.enum_string_required.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "enum_integer" => intermediate_rep.enum_integer.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "enum_number" => intermediate_rep.enum_number.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "outerEnum" => intermediate_rep.outer_enum.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing EnumTest".to_string()) } } @@ -2537,7 +2710,7 @@ impl std::str::FromStr for EnumTest { // Use the intermediate representation to return the struct std::result::Result::Ok(EnumTest { enum_string: intermediate_rep.enum_string.into_iter().next(), - enum_string_required: intermediate_rep.enum_string_required.into_iter().next().ok_or("enum_string_required missing in EnumTest".to_string())?, + enum_string_required: intermediate_rep.enum_string_required.into_iter().next().ok_or_else(|| "enum_string_required missing in EnumTest".to_string())?, enum_integer: intermediate_rep.enum_integer.into_iter().next(), enum_number: intermediate_rep.enum_number.into_iter().next(), outer_enum: intermediate_rep.outer_enum.into_iter().next(), @@ -2588,7 +2761,7 @@ impl EnumTest { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2647,21 +2820,22 @@ pub struct FormatTest { } impl FormatTest { + #[allow(clippy::new_without_default)] pub fn new(number: f64, byte: swagger::ByteArray, date: chrono::DateTime::, password: String, ) -> FormatTest { FormatTest { integer: None, int32: None, int64: None, - number: number, + number, float: None, double: None, string: None, - byte: byte, + byte, binary: None, - date: date, + date, date_time: None, uuid: None, - password: password, + password, } } } @@ -2671,64 +2845,78 @@ impl FormatTest { /// Should be implemented in a serde serializer impl std::string::ToString for FormatTest { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref integer) = self.integer { - params.push("integer".to_string()); - params.push(integer.to_string()); - } + self.integer.as_ref().map(|integer| { + vec![ + "integer".to_string(), + integer.to_string(), + ].join(",") + }), - if let Some(ref int32) = self.int32 { - params.push("int32".to_string()); - params.push(int32.to_string()); - } + self.int32.as_ref().map(|int32| { + vec![ + "int32".to_string(), + int32.to_string(), + ].join(",") + }), - if let Some(ref int64) = self.int64 { - params.push("int64".to_string()); - params.push(int64.to_string()); - } + self.int64.as_ref().map(|int64| { + vec![ + "int64".to_string(), + int64.to_string(), + ].join(",") + }), - params.push("number".to_string()); - params.push(self.number.to_string()); + Some("number".to_string()), + Some(self.number.to_string()), - if let Some(ref float) = self.float { - params.push("float".to_string()); - params.push(float.to_string()); - } + self.float.as_ref().map(|float| { + vec![ + "float".to_string(), + float.to_string(), + ].join(",") + }), - if let Some(ref double) = self.double { - params.push("double".to_string()); - params.push(double.to_string()); - } + self.double.as_ref().map(|double| { + vec![ + "double".to_string(), + double.to_string(), + ].join(",") + }), - if let Some(ref string) = self.string { - params.push("string".to_string()); - params.push(string.to_string()); - } + self.string.as_ref().map(|string| { + vec![ + "string".to_string(), + string.to_string(), + ].join(",") + }), - // Skipping byte in query parameter serialization - // Skipping byte in query parameter serialization + // Skipping byte in query parameter serialization + // Skipping byte in query parameter serialization - // Skipping binary in query parameter serialization - // Skipping binary in query parameter serialization + // Skipping binary in query parameter serialization + // Skipping binary in query parameter serialization - // Skipping date in query parameter serialization + // Skipping date in query parameter serialization - // Skipping dateTime in query parameter serialization + // Skipping dateTime in query parameter serialization - // Skipping uuid in query parameter serialization + // Skipping uuid in query parameter serialization - params.push("password".to_string()); - params.push(self.password.to_string()); + Some("password".to_string()), + Some(self.password.to_string()), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -2739,8 +2927,9 @@ impl std::str::FromStr for FormatTest { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub integer: Vec, pub int32: Vec, @@ -2760,7 +2949,7 @@ impl std::str::FromStr for FormatTest { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -2770,20 +2959,32 @@ impl std::str::FromStr for FormatTest { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "integer" => intermediate_rep.integer.push(::from_str(val).map_err(|x| format!("{}", x))?), - "int32" => intermediate_rep.int32.push(::from_str(val).map_err(|x| format!("{}", x))?), - "int64" => intermediate_rep.int64.push(::from_str(val).map_err(|x| format!("{}", x))?), - "number" => intermediate_rep.number.push(::from_str(val).map_err(|x| format!("{}", x))?), - "float" => intermediate_rep.float.push(::from_str(val).map_err(|x| format!("{}", x))?), - "double" => intermediate_rep.double.push(::from_str(val).map_err(|x| format!("{}", x))?), - "string" => intermediate_rep.string.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "integer" => intermediate_rep.integer.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "int32" => intermediate_rep.int32.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "int64" => intermediate_rep.int64.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "number" => intermediate_rep.number.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "float" => intermediate_rep.float.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "double" => intermediate_rep.double.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "string" => intermediate_rep.string.push(::from_str(val).map_err(|x| x.to_string())?), "byte" => return std::result::Result::Err("Parsing binary data in this style is not supported in FormatTest".to_string()), "binary" => return std::result::Result::Err("Parsing binary data in this style is not supported in FormatTest".to_string()), - "date" => intermediate_rep.date.push( as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), - "dateTime" => intermediate_rep.date_time.push( as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), - "uuid" => intermediate_rep.uuid.push(::from_str(val).map_err(|x| format!("{}", x))?), - "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "date" => intermediate_rep.date.push( as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "dateTime" => intermediate_rep.date_time.push( as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "uuid" => intermediate_rep.uuid.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing FormatTest".to_string()) } } @@ -2797,16 +2998,16 @@ impl std::str::FromStr for FormatTest { integer: intermediate_rep.integer.into_iter().next(), int32: intermediate_rep.int32.into_iter().next(), int64: intermediate_rep.int64.into_iter().next(), - number: intermediate_rep.number.into_iter().next().ok_or("number missing in FormatTest".to_string())?, + number: intermediate_rep.number.into_iter().next().ok_or_else(|| "number missing in FormatTest".to_string())?, float: intermediate_rep.float.into_iter().next(), double: intermediate_rep.double.into_iter().next(), string: intermediate_rep.string.into_iter().next(), - byte: intermediate_rep.byte.into_iter().next().ok_or("byte missing in FormatTest".to_string())?, + byte: intermediate_rep.byte.into_iter().next().ok_or_else(|| "byte missing in FormatTest".to_string())?, binary: intermediate_rep.binary.into_iter().next(), - date: intermediate_rep.date.into_iter().next().ok_or("date missing in FormatTest".to_string())?, + date: intermediate_rep.date.into_iter().next().ok_or_else(|| "date missing in FormatTest".to_string())?, date_time: intermediate_rep.date_time.into_iter().next(), uuid: intermediate_rep.uuid.into_iter().next(), - password: intermediate_rep.password.into_iter().next().ok_or("password missing in FormatTest".to_string())?, + password: intermediate_rep.password.into_iter().next().ok_or_else(|| "password missing in FormatTest".to_string())?, }) } } @@ -2854,7 +3055,7 @@ impl FormatTest { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -2873,6 +3074,7 @@ pub struct HasOnlyReadOnly { } impl HasOnlyReadOnly { + #[allow(clippy::new_without_default)] pub fn new() -> HasOnlyReadOnly { HasOnlyReadOnly { bar: None, @@ -2886,20 +3088,26 @@ impl HasOnlyReadOnly { /// Should be implemented in a serde serializer impl std::string::ToString for HasOnlyReadOnly { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref bar) = self.bar { - params.push("bar".to_string()); - params.push(bar.to_string()); - } + self.bar.as_ref().map(|bar| { + vec![ + "bar".to_string(), + bar.to_string(), + ].join(",") + }), - if let Some(ref foo) = self.foo { - params.push("foo".to_string()); - params.push(foo.to_string()); - } + self.foo.as_ref().map(|foo| { + vec![ + "foo".to_string(), + foo.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -2910,8 +3118,9 @@ impl std::str::FromStr for HasOnlyReadOnly { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub bar: Vec, pub foo: Vec, @@ -2920,7 +3129,7 @@ impl std::str::FromStr for HasOnlyReadOnly { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -2930,9 +3139,12 @@ impl std::str::FromStr for HasOnlyReadOnly { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "bar" => intermediate_rep.bar.push(::from_str(val).map_err(|x| format!("{}", x))?), - "foo" => intermediate_rep.foo.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "bar" => intermediate_rep.bar.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "foo" => intermediate_rep.foo.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing HasOnlyReadOnly".to_string()) } } @@ -2992,7 +3204,7 @@ impl HasOnlyReadOnly { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -3007,6 +3219,7 @@ pub struct List { } impl List { + #[allow(clippy::new_without_default)] pub fn new() -> List { List { param_123_list: None, @@ -3019,14 +3232,18 @@ impl List { /// Should be implemented in a serde serializer impl std::string::ToString for List { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref param_123_list) = self.param_123_list { - params.push("123-list".to_string()); - params.push(param_123_list.to_string()); - } + self.param_123_list.as_ref().map(|param_123_list| { + vec![ + "123-list".to_string(), + param_123_list.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -3037,8 +3254,9 @@ impl std::str::FromStr for List { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub param_123_list: Vec, } @@ -3046,7 +3264,7 @@ impl std::str::FromStr for List { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -3056,8 +3274,10 @@ impl std::str::FromStr for List { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "123-list" => intermediate_rep.param_123_list.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "123-list" => intermediate_rep.param_123_list.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing List".to_string()) } } @@ -3116,7 +3336,7 @@ impl List { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -3141,6 +3361,7 @@ pub struct MapTest { } impl MapTest { + #[allow(clippy::new_without_default)] pub fn new() -> MapTest { MapTest { map_map_of_string: None, @@ -3155,16 +3376,18 @@ impl MapTest { /// Should be implemented in a serde serializer impl std::string::ToString for MapTest { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - // Skipping map_map_of_string in query parameter serialization - // Skipping map_map_of_string in query parameter serialization + let params: Vec> = vec![ + // Skipping map_map_of_string in query parameter serialization + // Skipping map_map_of_string in query parameter serialization - // Skipping map_map_of_enum in query parameter serialization - // Skipping map_map_of_enum in query parameter serialization + // Skipping map_map_of_enum in query parameter serialization + // Skipping map_map_of_enum in query parameter serialization - // Skipping map_of_enum_string in query parameter serialization + // Skipping map_of_enum_string in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -3175,8 +3398,9 @@ impl std::str::FromStr for MapTest { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub map_map_of_string: Vec>>, pub map_map_of_enum: Vec>>, @@ -3186,7 +3410,7 @@ impl std::str::FromStr for MapTest { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -3196,6 +3420,7 @@ impl std::str::FromStr for MapTest { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { "map_map_of_string" => return std::result::Result::Err("Parsing a container in this style is not supported in MapTest".to_string()), "map_map_of_enum" => return std::result::Result::Err("Parsing a container in this style is not supported in MapTest".to_string()), @@ -3260,7 +3485,7 @@ impl MapTest { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -3283,6 +3508,7 @@ pub struct MixedPropertiesAndAdditionalPropertiesClass { } impl MixedPropertiesAndAdditionalPropertiesClass { + #[allow(clippy::new_without_default)] pub fn new() -> MixedPropertiesAndAdditionalPropertiesClass { MixedPropertiesAndAdditionalPropertiesClass { uuid: None, @@ -3297,15 +3523,17 @@ impl MixedPropertiesAndAdditionalPropertiesClass { /// Should be implemented in a serde serializer impl std::string::ToString for MixedPropertiesAndAdditionalPropertiesClass { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - // Skipping uuid in query parameter serialization + let params: Vec> = vec![ + // Skipping uuid in query parameter serialization - // Skipping dateTime in query parameter serialization + // Skipping dateTime in query parameter serialization - // Skipping map in query parameter serialization - // Skipping map in query parameter serialization + // Skipping map in query parameter serialization + // Skipping map in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -3316,8 +3544,9 @@ impl std::str::FromStr for MixedPropertiesAndAdditionalPropertiesClass { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub uuid: Vec, pub date_time: Vec>, @@ -3327,7 +3556,7 @@ impl std::str::FromStr for MixedPropertiesAndAdditionalPropertiesClass { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -3337,9 +3566,12 @@ impl std::str::FromStr for MixedPropertiesAndAdditionalPropertiesClass { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "uuid" => intermediate_rep.uuid.push(::from_str(val).map_err(|x| format!("{}", x))?), - "dateTime" => intermediate_rep.date_time.push( as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "uuid" => intermediate_rep.uuid.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "dateTime" => intermediate_rep.date_time.push( as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?), "map" => return std::result::Result::Err("Parsing a container in this style is not supported in MixedPropertiesAndAdditionalPropertiesClass".to_string()), _ => return std::result::Result::Err("Unexpected key while parsing MixedPropertiesAndAdditionalPropertiesClass".to_string()) } @@ -3401,7 +3633,7 @@ impl MixedPropertiesAndAdditionalPropertiesClass { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -3422,6 +3654,7 @@ pub struct Model200Response { } impl Model200Response { + #[allow(clippy::new_without_default)] pub fn new() -> Model200Response { Model200Response { name: None, @@ -3435,20 +3668,26 @@ impl Model200Response { /// Should be implemented in a serde serializer impl std::string::ToString for Model200Response { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref name) = self.name { - params.push("name".to_string()); - params.push(name.to_string()); - } + self.name.as_ref().map(|name| { + vec![ + "name".to_string(), + name.to_string(), + ].join(",") + }), - if let Some(ref class) = self.class { - params.push("class".to_string()); - params.push(class.to_string()); - } + self.class.as_ref().map(|class| { + vec![ + "class".to_string(), + class.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -3459,8 +3698,9 @@ impl std::str::FromStr for Model200Response { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub name: Vec, pub class: Vec, @@ -3469,7 +3709,7 @@ impl std::str::FromStr for Model200Response { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -3479,9 +3719,12 @@ impl std::str::FromStr for Model200Response { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| format!("{}", x))?), - "class" => intermediate_rep.class.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "class" => intermediate_rep.class.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Model200Response".to_string()) } } @@ -3541,7 +3784,7 @@ impl Model200Response { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -3569,9 +3812,10 @@ pub struct Name { } impl Name { + #[allow(clippy::new_without_default)] pub fn new(name: i32, ) -> Name { Name { - name: name, + name, snake_case: None, property: None, param_123_number: None, @@ -3584,30 +3828,38 @@ impl Name { /// Should be implemented in a serde serializer impl std::string::ToString for Name { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - params.push("name".to_string()); - params.push(self.name.to_string()); + Some("name".to_string()), + Some(self.name.to_string()), - if let Some(ref snake_case) = self.snake_case { - params.push("snake_case".to_string()); - params.push(snake_case.to_string()); - } + self.snake_case.as_ref().map(|snake_case| { + vec![ + "snake_case".to_string(), + snake_case.to_string(), + ].join(",") + }), - if let Some(ref property) = self.property { - params.push("property".to_string()); - params.push(property.to_string()); - } + self.property.as_ref().map(|property| { + vec![ + "property".to_string(), + property.to_string(), + ].join(",") + }), - if let Some(ref param_123_number) = self.param_123_number { - params.push("123Number".to_string()); - params.push(param_123_number.to_string()); - } + self.param_123_number.as_ref().map(|param_123_number| { + vec![ + "123Number".to_string(), + param_123_number.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -3618,8 +3870,9 @@ impl std::str::FromStr for Name { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub name: Vec, pub snake_case: Vec, @@ -3630,7 +3883,7 @@ impl std::str::FromStr for Name { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -3640,11 +3893,16 @@ impl std::str::FromStr for Name { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| format!("{}", x))?), - "snake_case" => intermediate_rep.snake_case.push(::from_str(val).map_err(|x| format!("{}", x))?), - "property" => intermediate_rep.property.push(::from_str(val).map_err(|x| format!("{}", x))?), - "123Number" => intermediate_rep.param_123_number.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "snake_case" => intermediate_rep.snake_case.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "property" => intermediate_rep.property.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "123Number" => intermediate_rep.param_123_number.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Name".to_string()) } } @@ -3655,7 +3913,7 @@ impl std::str::FromStr for Name { // Use the intermediate representation to return the struct std::result::Result::Ok(Name { - name: intermediate_rep.name.into_iter().next().ok_or("name missing in Name".to_string())?, + name: intermediate_rep.name.into_iter().next().ok_or_else(|| "name missing in Name".to_string())?, snake_case: intermediate_rep.snake_case.into_iter().next(), property: intermediate_rep.property.into_iter().next(), param_123_number: intermediate_rep.param_123_number.into_iter().next(), @@ -3706,7 +3964,7 @@ impl Name { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -3721,6 +3979,7 @@ pub struct NumberOnly { } impl NumberOnly { + #[allow(clippy::new_without_default)] pub fn new() -> NumberOnly { NumberOnly { just_number: None, @@ -3733,14 +3992,18 @@ impl NumberOnly { /// Should be implemented in a serde serializer impl std::string::ToString for NumberOnly { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref just_number) = self.just_number { - params.push("JustNumber".to_string()); - params.push(just_number.to_string()); - } + self.just_number.as_ref().map(|just_number| { + vec![ + "JustNumber".to_string(), + just_number.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -3751,8 +4014,9 @@ impl std::str::FromStr for NumberOnly { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub just_number: Vec, } @@ -3760,7 +4024,7 @@ impl std::str::FromStr for NumberOnly { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -3770,8 +4034,10 @@ impl std::str::FromStr for NumberOnly { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "JustNumber" => intermediate_rep.just_number.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "JustNumber" => intermediate_rep.just_number.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing NumberOnly".to_string()) } } @@ -3830,7 +4096,7 @@ impl NumberOnly { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -3845,6 +4111,7 @@ pub struct ObjectContainingObjectWithOnlyAdditionalProperties { } impl ObjectContainingObjectWithOnlyAdditionalProperties { + #[allow(clippy::new_without_default)] pub fn new() -> ObjectContainingObjectWithOnlyAdditionalProperties { ObjectContainingObjectWithOnlyAdditionalProperties { inner: None, @@ -3857,10 +4124,12 @@ impl ObjectContainingObjectWithOnlyAdditionalProperties { /// Should be implemented in a serde serializer impl std::string::ToString for ObjectContainingObjectWithOnlyAdditionalProperties { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - // Skipping inner in query parameter serialization + let params: Vec> = vec![ + // Skipping inner in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -3871,8 +4140,9 @@ impl std::str::FromStr for ObjectContainingObjectWithOnlyAdditionalProperties { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub inner: Vec, } @@ -3880,7 +4150,7 @@ impl std::str::FromStr for ObjectContainingObjectWithOnlyAdditionalProperties { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -3890,8 +4160,10 @@ impl std::str::FromStr for ObjectContainingObjectWithOnlyAdditionalProperties { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "inner" => intermediate_rep.inner.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "inner" => intermediate_rep.inner.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectContainingObjectWithOnlyAdditionalProperties".to_string()) } } @@ -3950,7 +4222,7 @@ impl ObjectContainingObjectWithOnlyAdditionalProperties { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4009,7 +4281,7 @@ impl ObjectWithOnlyAdditionalProperties { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4047,6 +4319,7 @@ pub struct Order { } impl Order { + #[allow(clippy::new_without_default)] pub fn new() -> Order { Order { id: None, @@ -4064,40 +4337,52 @@ impl Order { /// Should be implemented in a serde serializer impl std::string::ToString for Order { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref id) = self.id { - params.push("id".to_string()); - params.push(id.to_string()); - } + self.id.as_ref().map(|id| { + vec![ + "id".to_string(), + id.to_string(), + ].join(",") + }), - if let Some(ref pet_id) = self.pet_id { - params.push("petId".to_string()); - params.push(pet_id.to_string()); - } + self.pet_id.as_ref().map(|pet_id| { + vec![ + "petId".to_string(), + pet_id.to_string(), + ].join(",") + }), - if let Some(ref quantity) = self.quantity { - params.push("quantity".to_string()); - params.push(quantity.to_string()); - } + self.quantity.as_ref().map(|quantity| { + vec![ + "quantity".to_string(), + quantity.to_string(), + ].join(",") + }), - // Skipping shipDate in query parameter serialization + // Skipping shipDate in query parameter serialization - if let Some(ref status) = self.status { - params.push("status".to_string()); - params.push(status.to_string()); - } + self.status.as_ref().map(|status| { + vec![ + "status".to_string(), + status.to_string(), + ].join(",") + }), - if let Some(ref complete) = self.complete { - params.push("complete".to_string()); - params.push(complete.to_string()); - } + self.complete.as_ref().map(|complete| { + vec![ + "complete".to_string(), + complete.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -4108,8 +4393,9 @@ impl std::str::FromStr for Order { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub id: Vec, pub pet_id: Vec, @@ -4122,7 +4408,7 @@ impl std::str::FromStr for Order { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -4132,13 +4418,20 @@ impl std::str::FromStr for Order { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), - "petId" => intermediate_rep.pet_id.push(::from_str(val).map_err(|x| format!("{}", x))?), - "quantity" => intermediate_rep.quantity.push(::from_str(val).map_err(|x| format!("{}", x))?), - "shipDate" => intermediate_rep.ship_date.push( as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), - "status" => intermediate_rep.status.push(::from_str(val).map_err(|x| format!("{}", x))?), - "complete" => intermediate_rep.complete.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "petId" => intermediate_rep.pet_id.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "quantity" => intermediate_rep.quantity.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "shipDate" => intermediate_rep.ship_date.push( as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "status" => intermediate_rep.status.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "complete" => intermediate_rep.complete.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Order".to_string()) } } @@ -4202,7 +4495,7 @@ impl Order { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4241,7 +4534,7 @@ impl OuterBoolean { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4264,6 +4557,7 @@ pub struct OuterComposite { } impl OuterComposite { + #[allow(clippy::new_without_default)] pub fn new() -> OuterComposite { OuterComposite { my_number: None, @@ -4278,26 +4572,34 @@ impl OuterComposite { /// Should be implemented in a serde serializer impl std::string::ToString for OuterComposite { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref my_number) = self.my_number { - params.push("my_number".to_string()); - params.push(my_number.to_string()); - } + self.my_number.as_ref().map(|my_number| { + vec![ + "my_number".to_string(), + my_number.to_string(), + ].join(",") + }), - if let Some(ref my_string) = self.my_string { - params.push("my_string".to_string()); - params.push(my_string.to_string()); - } + self.my_string.as_ref().map(|my_string| { + vec![ + "my_string".to_string(), + my_string.to_string(), + ].join(",") + }), - if let Some(ref my_boolean) = self.my_boolean { - params.push("my_boolean".to_string()); - params.push(my_boolean.to_string()); - } + self.my_boolean.as_ref().map(|my_boolean| { + vec![ + "my_boolean".to_string(), + my_boolean.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -4308,8 +4610,9 @@ impl std::str::FromStr for OuterComposite { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub my_number: Vec, pub my_string: Vec, @@ -4319,7 +4622,7 @@ impl std::str::FromStr for OuterComposite { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -4329,10 +4632,14 @@ impl std::str::FromStr for OuterComposite { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "my_number" => intermediate_rep.my_number.push(::from_str(val).map_err(|x| format!("{}", x))?), - "my_string" => intermediate_rep.my_string.push(::from_str(val).map_err(|x| format!("{}", x))?), - "my_boolean" => intermediate_rep.my_boolean.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "my_number" => intermediate_rep.my_number.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "my_string" => intermediate_rep.my_string.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "my_boolean" => intermediate_rep.my_boolean.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing OuterComposite".to_string()) } } @@ -4393,7 +4700,7 @@ impl OuterComposite { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4417,9 +4724,9 @@ pub enum OuterEnum { impl std::fmt::Display for OuterEnum { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self { - OuterEnum::Placed => write!(f, "{}", "placed"), - OuterEnum::Approved => write!(f, "{}", "approved"), - OuterEnum::Delivered => write!(f, "{}", "delivered"), + OuterEnum::Placed => write!(f, "placed"), + OuterEnum::Approved => write!(f, "approved"), + OuterEnum::Delivered => write!(f, "delivered"), } } } @@ -4441,7 +4748,7 @@ impl OuterEnum { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4480,7 +4787,7 @@ impl OuterNumber { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4532,7 +4839,7 @@ impl OuterString { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4568,12 +4875,13 @@ pub struct Pet { } impl Pet { + #[allow(clippy::new_without_default)] pub fn new(name: String, photo_urls: Vec, ) -> Pet { Pet { id: None, category: None, - name: name, - photo_urls: photo_urls, + name, + photo_urls, tags: None, status: None, } @@ -4585,32 +4893,38 @@ impl Pet { /// Should be implemented in a serde serializer impl std::string::ToString for Pet { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref id) = self.id { - params.push("id".to_string()); - params.push(id.to_string()); - } + self.id.as_ref().map(|id| { + vec![ + "id".to_string(), + id.to_string(), + ].join(",") + }), - // Skipping category in query parameter serialization + // Skipping category in query parameter serialization - params.push("name".to_string()); - params.push(self.name.to_string()); + Some("name".to_string()), + Some(self.name.to_string()), - params.push("photoUrls".to_string()); - params.push(self.photo_urls.iter().map(|x| x.to_string()).collect::>().join(",").to_string()); + Some("photoUrls".to_string()), + Some(self.photo_urls.iter().map(|x| x.to_string()).collect::>().join(",")), - // Skipping tags in query parameter serialization + // Skipping tags in query parameter serialization - if let Some(ref status) = self.status { - params.push("status".to_string()); - params.push(status.to_string()); - } + self.status.as_ref().map(|status| { + vec![ + "status".to_string(), + status.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -4621,8 +4935,9 @@ impl std::str::FromStr for Pet { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub id: Vec, pub category: Vec, @@ -4635,7 +4950,7 @@ impl std::str::FromStr for Pet { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -4645,13 +4960,18 @@ impl std::str::FromStr for Pet { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), - "category" => intermediate_rep.category.push(::from_str(val).map_err(|x| format!("{}", x))?), - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "category" => intermediate_rep.category.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), "photoUrls" => return std::result::Result::Err("Parsing a container in this style is not supported in Pet".to_string()), "tags" => return std::result::Result::Err("Parsing a container in this style is not supported in Pet".to_string()), - "status" => intermediate_rep.status.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "status" => intermediate_rep.status.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Pet".to_string()) } } @@ -4664,8 +4984,8 @@ impl std::str::FromStr for Pet { std::result::Result::Ok(Pet { id: intermediate_rep.id.into_iter().next(), category: intermediate_rep.category.into_iter().next(), - name: intermediate_rep.name.into_iter().next().ok_or("name missing in Pet".to_string())?, - photo_urls: intermediate_rep.photo_urls.into_iter().next().ok_or("photoUrls missing in Pet".to_string())?, + name: intermediate_rep.name.into_iter().next().ok_or_else(|| "name missing in Pet".to_string())?, + photo_urls: intermediate_rep.photo_urls.into_iter().next().ok_or_else(|| "photoUrls missing in Pet".to_string())?, tags: intermediate_rep.tags.into_iter().next(), status: intermediate_rep.status.into_iter().next(), }) @@ -4715,7 +5035,7 @@ impl Pet { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4734,6 +5054,7 @@ pub struct ReadOnlyFirst { } impl ReadOnlyFirst { + #[allow(clippy::new_without_default)] pub fn new() -> ReadOnlyFirst { ReadOnlyFirst { bar: None, @@ -4747,20 +5068,26 @@ impl ReadOnlyFirst { /// Should be implemented in a serde serializer impl std::string::ToString for ReadOnlyFirst { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref bar) = self.bar { - params.push("bar".to_string()); - params.push(bar.to_string()); - } + self.bar.as_ref().map(|bar| { + vec![ + "bar".to_string(), + bar.to_string(), + ].join(",") + }), - if let Some(ref baz) = self.baz { - params.push("baz".to_string()); - params.push(baz.to_string()); - } + self.baz.as_ref().map(|baz| { + vec![ + "baz".to_string(), + baz.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -4771,8 +5098,9 @@ impl std::str::FromStr for ReadOnlyFirst { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub bar: Vec, pub baz: Vec, @@ -4781,7 +5109,7 @@ impl std::str::FromStr for ReadOnlyFirst { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -4791,9 +5119,12 @@ impl std::str::FromStr for ReadOnlyFirst { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "bar" => intermediate_rep.bar.push(::from_str(val).map_err(|x| format!("{}", x))?), - "baz" => intermediate_rep.baz.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "bar" => intermediate_rep.bar.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "baz" => intermediate_rep.baz.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ReadOnlyFirst".to_string()) } } @@ -4853,7 +5184,7 @@ impl ReadOnlyFirst { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4870,6 +5201,7 @@ pub struct Return { } impl Return { + #[allow(clippy::new_without_default)] pub fn new() -> Return { Return { r#return: None, @@ -4882,14 +5214,18 @@ impl Return { /// Should be implemented in a serde serializer impl std::string::ToString for Return { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref r#return) = self.r#return { - params.push("return".to_string()); - params.push(r#return.to_string()); - } + self.r#return.as_ref().map(|r#return| { + vec![ + "return".to_string(), + r#return.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -4900,8 +5236,9 @@ impl std::str::FromStr for Return { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub r#return: Vec, } @@ -4909,7 +5246,7 @@ impl std::str::FromStr for Return { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -4919,8 +5256,10 @@ impl std::str::FromStr for Return { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "return" => intermediate_rep.r#return.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "return" => intermediate_rep.r#return.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Return".to_string()) } } @@ -4979,7 +5318,7 @@ impl Return { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -4999,6 +5338,7 @@ pub struct Tag { } impl Tag { + #[allow(clippy::new_without_default)] pub fn new() -> Tag { Tag { id: None, @@ -5012,20 +5352,26 @@ impl Tag { /// Should be implemented in a serde serializer impl std::string::ToString for Tag { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref id) = self.id { - params.push("id".to_string()); - params.push(id.to_string()); - } + self.id.as_ref().map(|id| { + vec![ + "id".to_string(), + id.to_string(), + ].join(",") + }), - if let Some(ref name) = self.name { - params.push("name".to_string()); - params.push(name.to_string()); - } + self.name.as_ref().map(|name| { + vec![ + "name".to_string(), + name.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -5036,8 +5382,9 @@ impl std::str::FromStr for Tag { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub id: Vec, pub name: Vec, @@ -5046,7 +5393,7 @@ impl std::str::FromStr for Tag { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -5056,9 +5403,12 @@ impl std::str::FromStr for Tag { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), - "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "name" => intermediate_rep.name.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing Tag".to_string()) } } @@ -5118,7 +5468,7 @@ impl Tag { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } @@ -5163,6 +5513,7 @@ pub struct User { } impl User { + #[allow(clippy::new_without_default)] pub fn new() -> User { User { id: None, @@ -5182,56 +5533,74 @@ impl User { /// Should be implemented in a serde serializer impl std::string::ToString for User { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref id) = self.id { - params.push("id".to_string()); - params.push(id.to_string()); - } + self.id.as_ref().map(|id| { + vec![ + "id".to_string(), + id.to_string(), + ].join(",") + }), - if let Some(ref username) = self.username { - params.push("username".to_string()); - params.push(username.to_string()); - } + self.username.as_ref().map(|username| { + vec![ + "username".to_string(), + username.to_string(), + ].join(",") + }), - if let Some(ref first_name) = self.first_name { - params.push("firstName".to_string()); - params.push(first_name.to_string()); - } + self.first_name.as_ref().map(|first_name| { + vec![ + "firstName".to_string(), + first_name.to_string(), + ].join(",") + }), - if let Some(ref last_name) = self.last_name { - params.push("lastName".to_string()); - params.push(last_name.to_string()); - } + self.last_name.as_ref().map(|last_name| { + vec![ + "lastName".to_string(), + last_name.to_string(), + ].join(",") + }), - if let Some(ref email) = self.email { - params.push("email".to_string()); - params.push(email.to_string()); - } + self.email.as_ref().map(|email| { + vec![ + "email".to_string(), + email.to_string(), + ].join(",") + }), - if let Some(ref password) = self.password { - params.push("password".to_string()); - params.push(password.to_string()); - } + self.password.as_ref().map(|password| { + vec![ + "password".to_string(), + password.to_string(), + ].join(",") + }), - if let Some(ref phone) = self.phone { - params.push("phone".to_string()); - params.push(phone.to_string()); - } + self.phone.as_ref().map(|phone| { + vec![ + "phone".to_string(), + phone.to_string(), + ].join(",") + }), - if let Some(ref user_status) = self.user_status { - params.push("userStatus".to_string()); - params.push(user_status.to_string()); - } + self.user_status.as_ref().map(|user_status| { + vec![ + "userStatus".to_string(), + user_status.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -5242,8 +5611,9 @@ impl std::str::FromStr for User { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub id: Vec, pub username: Vec, @@ -5258,7 +5628,7 @@ impl std::str::FromStr for User { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -5268,15 +5638,24 @@ impl std::str::FromStr for User { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), - "username" => intermediate_rep.username.push(::from_str(val).map_err(|x| format!("{}", x))?), - "firstName" => intermediate_rep.first_name.push(::from_str(val).map_err(|x| format!("{}", x))?), - "lastName" => intermediate_rep.last_name.push(::from_str(val).map_err(|x| format!("{}", x))?), - "email" => intermediate_rep.email.push(::from_str(val).map_err(|x| format!("{}", x))?), - "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| format!("{}", x))?), - "phone" => intermediate_rep.phone.push(::from_str(val).map_err(|x| format!("{}", x))?), - "userStatus" => intermediate_rep.user_status.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "username" => intermediate_rep.username.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "firstName" => intermediate_rep.first_name.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "lastName" => intermediate_rep.last_name.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "email" => intermediate_rep.email.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "phone" => intermediate_rep.phone.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "userStatus" => intermediate_rep.user_status.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing User".to_string()) } } @@ -5342,7 +5721,7 @@ impl User { /// Helper function to allow us to convert this model to an XML string. /// Will panic if serialisation fails. #[allow(dead_code)] - pub(crate) fn to_xml(&self) -> String { + pub(crate) fn as_xml(&self) -> String { serde_xml_rs::to_string(&self).expect("impossible to fail to serialize") } } diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs index 20736c124020..e2366ba364d4 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs @@ -102,6 +102,7 @@ mod paths { pub(crate) static ID_FAKE_HYPHENPARAM_HYPHEN_PARAM: usize = 3; lazy_static! { pub static ref REGEX_FAKE_HYPHENPARAM_HYPHEN_PARAM: regex::Regex = + #[allow(clippy::invalid_regex)] regex::Regex::new(r"^/v2/fake/hyphenParam/(?P[^/?#]*)$") .expect("Unable to create regex for FAKE_HYPHENPARAM_HYPHEN_PARAM"); } @@ -120,12 +121,14 @@ mod paths { pub(crate) static ID_PET_PETID: usize = 16; lazy_static! { pub static ref REGEX_PET_PETID: regex::Regex = + #[allow(clippy::invalid_regex)] regex::Regex::new(r"^/v2/pet/(?P[^/?#]*)$") .expect("Unable to create regex for PET_PETID"); } pub(crate) static ID_PET_PETID_UPLOADIMAGE: usize = 17; lazy_static! { pub static ref REGEX_PET_PETID_UPLOADIMAGE: regex::Regex = + #[allow(clippy::invalid_regex)] regex::Regex::new(r"^/v2/pet/(?P[^/?#]*)/uploadImage$") .expect("Unable to create regex for PET_PETID_UPLOADIMAGE"); } @@ -134,6 +137,7 @@ mod paths { pub(crate) static ID_STORE_ORDER_ORDER_ID: usize = 20; lazy_static! { pub static ref REGEX_STORE_ORDER_ORDER_ID: regex::Regex = + #[allow(clippy::invalid_regex)] regex::Regex::new(r"^/v2/store/order/(?P[^/?#]*)$") .expect("Unable to create regex for STORE_ORDER_ORDER_ID"); } @@ -145,6 +149,7 @@ mod paths { pub(crate) static ID_USER_USERNAME: usize = 26; lazy_static! { pub static ref REGEX_USER_USERNAME: regex::Regex = + #[allow(clippy::invalid_regex)] regex::Regex::new(r"^/v2/user/(?P[^/?#]*)$") .expect("Unable to create regex for USER_USERNAME"); } @@ -211,7 +216,7 @@ impl Service where { pub fn new(api_impl: T) -> Self { Service { - api_impl: api_impl, + api_impl, marker: PhantomData } } @@ -224,7 +229,7 @@ impl Clone for Service where fn clone(&self) -> Self { Service { api_impl: self.api_impl.clone(), - marker: self.marker.clone(), + marker: self.marker, } } } @@ -250,10 +255,10 @@ impl hyper::service::Service<(Request, C)> for Service where let (method, uri, headers) = (parts.method, parts.uri, parts.headers); let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); - match &method { + match method { // TestSpecialTags - PATCH /another-fake/dummy - &hyper::Method::PATCH if path.matched(paths::ID_ANOTHER_FAKE_DUMMY) => { + hyper::Method::PATCH if path.matched(paths::ID_ANOTHER_FAKE_DUMMY) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -291,7 +296,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -333,14 +338,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // Call123example - GET /fake/operation-with-numeric-id - &hyper::Method::GET if path.matched(paths::ID_FAKE_OPERATION_WITH_NUMERIC_ID) => { + hyper::Method::GET if path.matched(paths::ID_FAKE_OPERATION_WITH_NUMERIC_ID) => { let result = api_impl.call123example( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -362,7 +367,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // FakeOuterBooleanSerialize - POST /fake/outer/boolean - &hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_BOOLEAN) => { + hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_BOOLEAN) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -390,7 +395,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -432,7 +437,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // FakeOuterCompositeSerialize - POST /fake/outer/composite - &hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_COMPOSITE) => { + hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_COMPOSITE) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -460,7 +465,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -502,7 +507,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // FakeOuterNumberSerialize - POST /fake/outer/number - &hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_NUMBER) => { + hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_NUMBER) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -530,7 +535,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -572,7 +577,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // FakeOuterStringSerialize - POST /fake/outer/string - &hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_STRING) => { + hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_STRING) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -600,7 +605,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -642,14 +647,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // FakeResponseWithNumericalDescription - GET /fake/response-with-numerical-description - &hyper::Method::GET if path.matched(paths::ID_FAKE_RESPONSE_WITH_NUMERICAL_DESCRIPTION) => { + hyper::Method::GET if path.matched(paths::ID_FAKE_RESPONSE_WITH_NUMERICAL_DESCRIPTION) => { let result = api_impl.fake_response_with_numerical_description( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -671,12 +676,12 @@ impl hyper::service::Service<(Request, C)> for Service where }, // HyphenParam - GET /fake/hyphenParam/{hyphen-param} - &hyper::Method::GET if path.matched(paths::ID_FAKE_HYPHENPARAM_HYPHEN_PARAM) => { + hyper::Method::GET if path.matched(paths::ID_FAKE_HYPHENPARAM_HYPHEN_PARAM) => { // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_FAKE_HYPHENPARAM_HYPHEN_PARAM - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE FAKE_HYPHENPARAM_HYPHEN_PARAM in set but failed match against \"{}\"", path, paths::REGEX_FAKE_HYPHENPARAM_HYPHEN_PARAM.as_str()) ); @@ -702,7 +707,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -724,11 +729,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // TestBodyWithQueryParams - PUT /fake/body-with-query-params - &hyper::Method::PUT if path.matched(paths::ID_FAKE_BODY_WITH_QUERY_PARAMS) => { + hyper::Method::PUT if path.matched(paths::ID_FAKE_BODY_WITH_QUERY_PARAMS) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::>(); let param_query = query_params.iter().filter(|e| e.0 == "query").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_query = match param_query { Some(param_query) => { let param_query = @@ -790,7 +795,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -825,7 +830,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // TestClientModel - PATCH /fake - &hyper::Method::PATCH if path.matched(paths::ID_FAKE) => { + hyper::Method::PATCH if path.matched(paths::ID_FAKE) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -863,7 +868,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -905,11 +910,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // TestEndpointParameters - POST /fake - &hyper::Method::POST if path.matched(paths::ID_FAKE) => { + hyper::Method::POST if path.matched(paths::ID_FAKE) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -952,7 +957,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -978,7 +983,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // TestEnumParameters - GET /fake - &hyper::Method::GET if path.matched(paths::ID_FAKE) => { + hyper::Method::GET if path.matched(paths::ID_FAKE) => { // Header parameters let param_enum_header_string_array = headers.get(HeaderName::from_static("enum_header_string_array")); @@ -1028,7 +1033,7 @@ impl hyper::service::Service<(Request, C)> for Service where None }; let param_enum_query_string = query_params.iter().filter(|e| e.0 == "enum_query_string").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_enum_query_string = match param_enum_query_string { Some(param_enum_query_string) => { let param_enum_query_string = @@ -1045,7 +1050,7 @@ impl hyper::service::Service<(Request, C)> for Service where None => None, }; let param_enum_query_integer = query_params.iter().filter(|e| e.0 == "enum_query_integer").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_enum_query_integer = match param_enum_query_integer { Some(param_enum_query_integer) => { let param_enum_query_integer = @@ -1062,7 +1067,7 @@ impl hyper::service::Service<(Request, C)> for Service where None => None, }; let param_enum_query_double = query_params.iter().filter(|e| e.0 == "enum_query_double").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_enum_query_double = match param_enum_query_double { Some(param_enum_query_double) => { let param_enum_query_double = @@ -1095,7 +1100,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1121,7 +1126,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // TestInlineAdditionalProperties - POST /fake/inline-additionalProperties - &hyper::Method::POST if path.matched(paths::ID_FAKE_INLINE_ADDITIONALPROPERTIES) => { + hyper::Method::POST if path.matched(paths::ID_FAKE_INLINE_ADDITIONALPROPERTIES) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1159,7 +1164,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1194,7 +1199,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // TestJsonFormData - GET /fake/jsonFormData - &hyper::Method::GET if path.matched(paths::ID_FAKE_JSONFORMDATA) => { + hyper::Method::GET if path.matched(paths::ID_FAKE_JSONFORMDATA) => { // Form parameters let param_param = "param_example".to_string(); let param_param2 = "param2_example".to_string(); @@ -1207,7 +1212,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1229,11 +1234,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // TestClassname - PATCH /fake_classname_test - &hyper::Method::PATCH if path.matched(paths::ID_FAKE_CLASSNAME_TEST) => { + hyper::Method::PATCH if path.matched(paths::ID_FAKE_CLASSNAME_TEST) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -1277,7 +1282,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1319,11 +1324,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // AddPet - POST /pet - &hyper::Method::POST if path.matched(paths::ID_PET) => { + hyper::Method::POST if path.matched(paths::ID_PET) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -1387,7 +1392,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1422,11 +1427,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // DeletePet - DELETE /pet/{petId} - &hyper::Method::DELETE if path.matched(paths::ID_PET_PETID) => { + hyper::Method::DELETE if path.matched(paths::ID_PET_PETID) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -1454,10 +1459,10 @@ impl hyper::service::Service<(Request, C)> for Service where } // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_PET_PETID - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE PET_PETID in set but failed match against \"{}\"", path, paths::REGEX_PET_PETID.as_str()) ); @@ -1504,7 +1509,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1526,11 +1531,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // FindPetsByStatus - GET /pet/findByStatus - &hyper::Method::GET if path.matched(paths::ID_PET_FINDBYSTATUS) => { + hyper::Method::GET if path.matched(paths::ID_PET_FINDBYSTATUS) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -1570,7 +1575,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1603,11 +1608,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // FindPetsByTags - GET /pet/findByTags - &hyper::Method::GET if path.matched(paths::ID_PET_FINDBYTAGS) => { + hyper::Method::GET if path.matched(paths::ID_PET_FINDBYTAGS) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -1647,7 +1652,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1680,11 +1685,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // GetPetById - GET /pet/{petId} - &hyper::Method::GET if path.matched(paths::ID_PET_PETID) => { + hyper::Method::GET if path.matched(paths::ID_PET_PETID) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -1692,10 +1697,10 @@ impl hyper::service::Service<(Request, C)> for Service where } // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_PET_PETID - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE PET_PETID in set but failed match against \"{}\"", path, paths::REGEX_PET_PETID.as_str()) ); @@ -1721,7 +1726,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1758,11 +1763,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // UpdatePet - PUT /pet - &hyper::Method::PUT if path.matched(paths::ID_PET) => { + hyper::Method::PUT if path.matched(paths::ID_PET) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -1826,7 +1831,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -1869,11 +1874,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // UpdatePetWithForm - POST /pet/{petId} - &hyper::Method::POST if path.matched(paths::ID_PET_PETID) => { + hyper::Method::POST if path.matched(paths::ID_PET_PETID) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -1901,10 +1906,10 @@ impl hyper::service::Service<(Request, C)> for Service where } // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_PET_PETID - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE PET_PETID in set but failed match against \"{}\"", path, paths::REGEX_PET_PETID.as_str()) ); @@ -1936,7 +1941,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -1958,11 +1963,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // UploadFile - POST /pet/{petId}/uploadImage - &hyper::Method::POST if path.matched(paths::ID_PET_PETID_UPLOADIMAGE) => { + hyper::Method::POST if path.matched(paths::ID_PET_PETID_UPLOADIMAGE) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -1998,10 +2003,10 @@ impl hyper::service::Service<(Request, C)> for Service where }; // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_PET_PETID_UPLOADIMAGE - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE PET_PETID_UPLOADIMAGE in set but failed match against \"{}\"", path, paths::REGEX_PET_PETID_UPLOADIMAGE.as_str()) ); @@ -2036,7 +2041,7 @@ impl hyper::service::Service<(Request, C)> for Service where _ => { return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Unable to process all message parts"))) + .body(Body::from("Unable to process all message parts".to_string())) .expect("Unable to create Bad Request response due to failure to process all message")) }, }; @@ -2097,7 +2102,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -2126,18 +2131,18 @@ impl hyper::service::Service<(Request, C)> for Service where }, Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) - .body(Body::from(format!("Couldn't read multipart body"))) + .body(Body::from("Couldn't read multipart body".to_string())) .expect("Unable to create Bad Request response due to unable read multipart body")), } }, // DeleteOrder - DELETE /store/order/{order_id} - &hyper::Method::DELETE if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => { + hyper::Method::DELETE if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => { // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_STORE_ORDER_ORDER_ID - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE STORE_ORDER_ORDER_ID in set but failed match against \"{}\"", path, paths::REGEX_STORE_ORDER_ORDER_ID.as_str()) ); @@ -2163,7 +2168,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -2189,11 +2194,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // GetInventory - GET /store/inventory - &hyper::Method::GET if path.matched(paths::ID_STORE_INVENTORY) => { + hyper::Method::GET if path.matched(paths::ID_STORE_INVENTORY) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -2206,7 +2211,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -2235,12 +2240,12 @@ impl hyper::service::Service<(Request, C)> for Service where }, // GetOrderById - GET /store/order/{order_id} - &hyper::Method::GET if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => { + hyper::Method::GET if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => { // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_STORE_ORDER_ORDER_ID - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE STORE_ORDER_ORDER_ID in set but failed match against \"{}\"", path, paths::REGEX_STORE_ORDER_ORDER_ID.as_str()) ); @@ -2266,7 +2271,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -2303,7 +2308,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // PlaceOrder - POST /store/order - &hyper::Method::POST if path.matched(paths::ID_STORE_ORDER) => { + hyper::Method::POST if path.matched(paths::ID_STORE_ORDER) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -2341,7 +2346,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -2387,7 +2392,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // CreateUser - POST /user - &hyper::Method::POST if path.matched(paths::ID_USER) => { + hyper::Method::POST if path.matched(paths::ID_USER) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -2425,7 +2430,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -2460,7 +2465,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // CreateUsersWithArrayInput - POST /user/createWithArray - &hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHARRAY) => { + hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHARRAY) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -2498,7 +2503,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -2533,7 +2538,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // CreateUsersWithListInput - POST /user/createWithList - &hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHLIST) => { + hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHLIST) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -2571,7 +2576,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -2606,12 +2611,12 @@ impl hyper::service::Service<(Request, C)> for Service where }, // DeleteUser - DELETE /user/{username} - &hyper::Method::DELETE if path.matched(paths::ID_USER_USERNAME) => { + hyper::Method::DELETE if path.matched(paths::ID_USER_USERNAME) => { // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_USER_USERNAME - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE USER_USERNAME in set but failed match against \"{}\"", path, paths::REGEX_USER_USERNAME.as_str()) ); @@ -2637,7 +2642,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -2663,12 +2668,12 @@ impl hyper::service::Service<(Request, C)> for Service where }, // GetUserByName - GET /user/{username} - &hyper::Method::GET if path.matched(paths::ID_USER_USERNAME) => { + hyper::Method::GET if path.matched(paths::ID_USER_USERNAME) => { // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_USER_USERNAME - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE USER_USERNAME in set but failed match against \"{}\"", path, paths::REGEX_USER_USERNAME.as_str()) ); @@ -2694,7 +2699,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -2731,11 +2736,11 @@ impl hyper::service::Service<(Request, C)> for Service where }, // LoginUser - GET /user/login - &hyper::Method::GET if path.matched(paths::ID_USER_LOGIN) => { + hyper::Method::GET if path.matched(paths::ID_USER_LOGIN) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::>(); let param_username = query_params.iter().filter(|e| e.0 == "username").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_username = match param_username { Some(param_username) => { let param_username = @@ -2759,7 +2764,7 @@ impl hyper::service::Service<(Request, C)> for Service where .expect("Unable to create Bad Request response for missing query parameter username")), }; let param_password = query_params.iter().filter(|e| e.0 == "password").map(|e| e.1.to_owned()) - .nth(0); + .next(); let param_password = match param_password { Some(param_password) => { let param_password = @@ -2791,7 +2796,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -2860,14 +2865,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // LogoutUser - GET /user/logout - &hyper::Method::GET if path.matched(paths::ID_USER_LOGOUT) => { + hyper::Method::GET if path.matched(paths::ID_USER_LOGOUT) => { let result = api_impl.logout_user( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -2889,12 +2894,12 @@ impl hyper::service::Service<(Request, C)> for Service where }, // UpdateUser - PUT /user/{username} - &hyper::Method::PUT if path.matched(paths::ID_USER_USERNAME) => { + hyper::Method::PUT if path.matched(paths::ID_USER_USERNAME) => { // Path parameters - let path: &str = &uri.path().to_string(); + let path: &str = uri.path(); let path_params = paths::REGEX_USER_USERNAME - .captures(&path) + .captures(path) .unwrap_or_else(|| panic!("Path {} matched RE USER_USERNAME in set but failed match against \"{}\"", path, paths::REGEX_USER_USERNAME.as_str()) ); @@ -2951,7 +2956,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -3028,77 +3033,77 @@ pub struct ApiRequestParser; impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Option<&'static str> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); - match request.method() { + match *request.method() { // TestSpecialTags - PATCH /another-fake/dummy - &hyper::Method::PATCH if path.matched(paths::ID_ANOTHER_FAKE_DUMMY) => Some("TestSpecialTags"), + hyper::Method::PATCH if path.matched(paths::ID_ANOTHER_FAKE_DUMMY) => Some("TestSpecialTags"), // Call123example - GET /fake/operation-with-numeric-id - &hyper::Method::GET if path.matched(paths::ID_FAKE_OPERATION_WITH_NUMERIC_ID) => Some("Call123example"), + hyper::Method::GET if path.matched(paths::ID_FAKE_OPERATION_WITH_NUMERIC_ID) => Some("Call123example"), // FakeOuterBooleanSerialize - POST /fake/outer/boolean - &hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_BOOLEAN) => Some("FakeOuterBooleanSerialize"), + hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_BOOLEAN) => Some("FakeOuterBooleanSerialize"), // FakeOuterCompositeSerialize - POST /fake/outer/composite - &hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_COMPOSITE) => Some("FakeOuterCompositeSerialize"), + hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_COMPOSITE) => Some("FakeOuterCompositeSerialize"), // FakeOuterNumberSerialize - POST /fake/outer/number - &hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_NUMBER) => Some("FakeOuterNumberSerialize"), + hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_NUMBER) => Some("FakeOuterNumberSerialize"), // FakeOuterStringSerialize - POST /fake/outer/string - &hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_STRING) => Some("FakeOuterStringSerialize"), + hyper::Method::POST if path.matched(paths::ID_FAKE_OUTER_STRING) => Some("FakeOuterStringSerialize"), // FakeResponseWithNumericalDescription - GET /fake/response-with-numerical-description - &hyper::Method::GET if path.matched(paths::ID_FAKE_RESPONSE_WITH_NUMERICAL_DESCRIPTION) => Some("FakeResponseWithNumericalDescription"), + hyper::Method::GET if path.matched(paths::ID_FAKE_RESPONSE_WITH_NUMERICAL_DESCRIPTION) => Some("FakeResponseWithNumericalDescription"), // HyphenParam - GET /fake/hyphenParam/{hyphen-param} - &hyper::Method::GET if path.matched(paths::ID_FAKE_HYPHENPARAM_HYPHEN_PARAM) => Some("HyphenParam"), + hyper::Method::GET if path.matched(paths::ID_FAKE_HYPHENPARAM_HYPHEN_PARAM) => Some("HyphenParam"), // TestBodyWithQueryParams - PUT /fake/body-with-query-params - &hyper::Method::PUT if path.matched(paths::ID_FAKE_BODY_WITH_QUERY_PARAMS) => Some("TestBodyWithQueryParams"), + hyper::Method::PUT if path.matched(paths::ID_FAKE_BODY_WITH_QUERY_PARAMS) => Some("TestBodyWithQueryParams"), // TestClientModel - PATCH /fake - &hyper::Method::PATCH if path.matched(paths::ID_FAKE) => Some("TestClientModel"), + hyper::Method::PATCH if path.matched(paths::ID_FAKE) => Some("TestClientModel"), // TestEndpointParameters - POST /fake - &hyper::Method::POST if path.matched(paths::ID_FAKE) => Some("TestEndpointParameters"), + hyper::Method::POST if path.matched(paths::ID_FAKE) => Some("TestEndpointParameters"), // TestEnumParameters - GET /fake - &hyper::Method::GET if path.matched(paths::ID_FAKE) => Some("TestEnumParameters"), + hyper::Method::GET if path.matched(paths::ID_FAKE) => Some("TestEnumParameters"), // TestInlineAdditionalProperties - POST /fake/inline-additionalProperties - &hyper::Method::POST if path.matched(paths::ID_FAKE_INLINE_ADDITIONALPROPERTIES) => Some("TestInlineAdditionalProperties"), + hyper::Method::POST if path.matched(paths::ID_FAKE_INLINE_ADDITIONALPROPERTIES) => Some("TestInlineAdditionalProperties"), // TestJsonFormData - GET /fake/jsonFormData - &hyper::Method::GET if path.matched(paths::ID_FAKE_JSONFORMDATA) => Some("TestJsonFormData"), + hyper::Method::GET if path.matched(paths::ID_FAKE_JSONFORMDATA) => Some("TestJsonFormData"), // TestClassname - PATCH /fake_classname_test - &hyper::Method::PATCH if path.matched(paths::ID_FAKE_CLASSNAME_TEST) => Some("TestClassname"), + hyper::Method::PATCH if path.matched(paths::ID_FAKE_CLASSNAME_TEST) => Some("TestClassname"), // AddPet - POST /pet - &hyper::Method::POST if path.matched(paths::ID_PET) => Some("AddPet"), + hyper::Method::POST if path.matched(paths::ID_PET) => Some("AddPet"), // DeletePet - DELETE /pet/{petId} - &hyper::Method::DELETE if path.matched(paths::ID_PET_PETID) => Some("DeletePet"), + hyper::Method::DELETE if path.matched(paths::ID_PET_PETID) => Some("DeletePet"), // FindPetsByStatus - GET /pet/findByStatus - &hyper::Method::GET if path.matched(paths::ID_PET_FINDBYSTATUS) => Some("FindPetsByStatus"), + hyper::Method::GET if path.matched(paths::ID_PET_FINDBYSTATUS) => Some("FindPetsByStatus"), // FindPetsByTags - GET /pet/findByTags - &hyper::Method::GET if path.matched(paths::ID_PET_FINDBYTAGS) => Some("FindPetsByTags"), + hyper::Method::GET if path.matched(paths::ID_PET_FINDBYTAGS) => Some("FindPetsByTags"), // GetPetById - GET /pet/{petId} - &hyper::Method::GET if path.matched(paths::ID_PET_PETID) => Some("GetPetById"), + hyper::Method::GET if path.matched(paths::ID_PET_PETID) => Some("GetPetById"), // UpdatePet - PUT /pet - &hyper::Method::PUT if path.matched(paths::ID_PET) => Some("UpdatePet"), + hyper::Method::PUT if path.matched(paths::ID_PET) => Some("UpdatePet"), // UpdatePetWithForm - POST /pet/{petId} - &hyper::Method::POST if path.matched(paths::ID_PET_PETID) => Some("UpdatePetWithForm"), + hyper::Method::POST if path.matched(paths::ID_PET_PETID) => Some("UpdatePetWithForm"), // UploadFile - POST /pet/{petId}/uploadImage - &hyper::Method::POST if path.matched(paths::ID_PET_PETID_UPLOADIMAGE) => Some("UploadFile"), + hyper::Method::POST if path.matched(paths::ID_PET_PETID_UPLOADIMAGE) => Some("UploadFile"), // DeleteOrder - DELETE /store/order/{order_id} - &hyper::Method::DELETE if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => Some("DeleteOrder"), + hyper::Method::DELETE if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => Some("DeleteOrder"), // GetInventory - GET /store/inventory - &hyper::Method::GET if path.matched(paths::ID_STORE_INVENTORY) => Some("GetInventory"), + hyper::Method::GET if path.matched(paths::ID_STORE_INVENTORY) => Some("GetInventory"), // GetOrderById - GET /store/order/{order_id} - &hyper::Method::GET if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => Some("GetOrderById"), + hyper::Method::GET if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => Some("GetOrderById"), // PlaceOrder - POST /store/order - &hyper::Method::POST if path.matched(paths::ID_STORE_ORDER) => Some("PlaceOrder"), + hyper::Method::POST if path.matched(paths::ID_STORE_ORDER) => Some("PlaceOrder"), // CreateUser - POST /user - &hyper::Method::POST if path.matched(paths::ID_USER) => Some("CreateUser"), + hyper::Method::POST if path.matched(paths::ID_USER) => Some("CreateUser"), // CreateUsersWithArrayInput - POST /user/createWithArray - &hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHARRAY) => Some("CreateUsersWithArrayInput"), + hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHARRAY) => Some("CreateUsersWithArrayInput"), // CreateUsersWithListInput - POST /user/createWithList - &hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHLIST) => Some("CreateUsersWithListInput"), + hyper::Method::POST if path.matched(paths::ID_USER_CREATEWITHLIST) => Some("CreateUsersWithListInput"), // DeleteUser - DELETE /user/{username} - &hyper::Method::DELETE if path.matched(paths::ID_USER_USERNAME) => Some("DeleteUser"), + hyper::Method::DELETE if path.matched(paths::ID_USER_USERNAME) => Some("DeleteUser"), // GetUserByName - GET /user/{username} - &hyper::Method::GET if path.matched(paths::ID_USER_USERNAME) => Some("GetUserByName"), + hyper::Method::GET if path.matched(paths::ID_USER_USERNAME) => Some("GetUserByName"), // LoginUser - GET /user/login - &hyper::Method::GET if path.matched(paths::ID_USER_LOGIN) => Some("LoginUser"), + hyper::Method::GET if path.matched(paths::ID_USER_LOGIN) => Some("LoginUser"), // LogoutUser - GET /user/logout - &hyper::Method::GET if path.matched(paths::ID_USER_LOGOUT) => Some("LogoutUser"), + hyper::Method::GET if path.matched(paths::ID_USER_LOGOUT) => Some("LogoutUser"), // UpdateUser - PUT /user/{username} - &hyper::Method::PUT if path.matched(paths::ID_USER_USERNAME) => Some("UpdateUser"), + hyper::Method::PUT if path.matched(paths::ID_USER_USERNAME) => Some("UpdateUser"), _ => None, } } diff --git a/samples/server/petstore/rust-server/output/ping-bearer-auth/examples/server/server.rs b/samples/server/petstore/rust-server/output/ping-bearer-auth/examples/server/server.rs index 19af14b7782a..3383a22e1ad7 100644 --- a/samples/server/petstore/rust-server/output/ping-bearer-auth/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/ping-bearer-auth/examples/server/server.rs @@ -32,6 +32,7 @@ pub async fn create(addr: &str, https: bool) { let service = MakeAllowAllAuthenticator::new(service, "cosmo"); + #[allow(unused_mut)] let mut service = ping_bearer_auth::server::context::MakeAddContext::<_, EmptyContext>::new( service diff --git a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs index 854dd41f33fa..9ce229a207f5 100644 --- a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs @@ -419,8 +419,10 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); + #[allow(clippy::collapsible_match)] if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported + #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); diff --git a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/context.rs b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/context.rs index 6f0300532522..ac1c07864b89 100644 --- a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/context.rs +++ b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/context.rs @@ -107,7 +107,7 @@ impl Service> for AddContext(&headers) { + if let Some(bearer) = swagger::auth::from_headers::(headers) { let auth_data = AuthData::Bearer(bearer); let context = context.push(Some(auth_data)); let context = context.push(None::); diff --git a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/lib.rs b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/lib.rs index 4c5d7e2de9dc..5a5c46ba33cc 100644 --- a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/lib.rs +++ b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/lib.rs @@ -1,5 +1,6 @@ #![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] -#![allow(unused_imports)] +#![allow(unused_imports, unused_attributes)] +#![allow(clippy::derive_partial_eq_without_eq, clippy::blacklisted_name)] use async_trait::async_trait; use futures::Stream; @@ -21,6 +22,7 @@ pub enum PingGetResponse { /// API #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait Api { fn poll_ready(&self, _cx: &mut Context) -> Poll>> { Poll::Ready(Ok(())) @@ -34,6 +36,7 @@ pub trait Api { /// API where `Context` isn't passed on every API call #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait ApiNoContext { fn poll_ready(&self, _cx: &mut Context) -> Poll>>; diff --git a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/server/mod.rs b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/server/mod.rs index c62110ced8f8..0657f06dd602 100644 --- a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/server/mod.rs @@ -98,7 +98,7 @@ impl Service where { pub fn new(api_impl: T) -> Self { Service { - api_impl: api_impl, + api_impl, marker: PhantomData } } @@ -111,7 +111,7 @@ impl Clone for Service where fn clone(&self) -> Self { Service { api_impl: self.api_impl.clone(), - marker: self.marker.clone(), + marker: self.marker, } } } @@ -137,14 +137,14 @@ impl hyper::service::Service<(Request, C)> for Service where let (method, uri, headers) = (parts.method, parts.uri, parts.headers); let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); - match &method { + match method { // PingGet - GET /ping - &hyper::Method::GET if path.matched(paths::ID_PING) => { + hyper::Method::GET if path.matched(paths::ID_PING) => { { - let authorization = match (&context as &dyn Has>).get() { - &Some(ref authorization) => authorization, - &None => return Ok(Response::builder() + let authorization = match *(&context as &dyn Has>).get() { + Some(ref authorization) => authorization, + None => return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) .expect("Unable to create Authentication Forbidden response")), @@ -157,7 +157,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -191,9 +191,9 @@ pub struct ApiRequestParser; impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Option<&'static str> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); - match request.method() { + match *request.method() { // PingGet - GET /ping - &hyper::Method::GET if path.matched(paths::ID_PING) => Some("PingGet"), + hyper::Method::GET if path.matched(paths::ID_PING) => Some("PingGet"), _ => None, } } diff --git a/samples/server/petstore/rust-server/output/rust-server-test/examples/server/server.rs b/samples/server/petstore/rust-server/output/rust-server-test/examples/server/server.rs index 143e17a051d0..ab9e383866b2 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/examples/server/server.rs @@ -32,6 +32,7 @@ pub async fn create(addr: &str, https: bool) { let service = MakeAllowAllAuthenticator::new(service, "cosmo"); + #[allow(unused_mut)] let mut service = rust_server_test::server::context::MakeAddContext::<_, EmptyContext>::new( service diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs index eb37814cb8f5..9d9c1f711c32 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs @@ -1,5 +1,6 @@ #![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] -#![allow(unused_imports)] +#![allow(unused_imports, unused_attributes)] +#![allow(clippy::derive_partial_eq_without_eq, clippy::blacklisted_name)] use async_trait::async_trait; use futures::Stream; @@ -74,6 +75,7 @@ pub enum SoloObjectPostResponse { /// API #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait Api { fn poll_ready(&self, _cx: &mut Context) -> Poll>> { Poll::Ready(Ok(())) @@ -128,6 +130,7 @@ pub trait Api { /// API where `Context` isn't passed on every API call #[async_trait] +#[allow(clippy::too_many_arguments, clippy::ptr_arg)] pub trait ApiNoContext { fn poll_ready(&self, _cx: &mut Context) -> Poll>>; diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs index 381b7632a6a0..98527d6d9ac0 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs @@ -19,10 +19,11 @@ pub struct ANullableContainer { } impl ANullableContainer { + #[allow(clippy::new_without_default)] pub fn new(required_nullable_thing: swagger::Nullable, ) -> ANullableContainer { ANullableContainer { nullable_thing: None, - required_nullable_thing: required_nullable_thing, + required_nullable_thing, } } } @@ -32,18 +33,22 @@ impl ANullableContainer { /// Should be implemented in a serde serializer impl std::string::ToString for ANullableContainer { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref nullable_thing) = self.nullable_thing { - params.push("NullableThing".to_string()); - params.push(nullable_thing.as_ref().map_or("null".to_string(), |x| x.to_string())); - } + self.nullable_thing.as_ref().map(|nullable_thing| { + vec![ + "NullableThing".to_string(), + nullable_thing.as_ref().map_or("null".to_string(), |x| x.to_string()), + ].join(",") + }), - params.push("RequiredNullableThing".to_string()); - params.push(self.required_nullable_thing.as_ref().map_or("null".to_string(), |x| x.to_string())); + Some("RequiredNullableThing".to_string()), + Some(self.required_nullable_thing.as_ref().map_or("null".to_string(), |x| x.to_string())), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -54,8 +59,9 @@ impl std::str::FromStr for ANullableContainer { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub nullable_thing: Vec, pub required_nullable_thing: Vec, @@ -64,7 +70,7 @@ impl std::str::FromStr for ANullableContainer { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -74,6 +80,7 @@ impl std::str::FromStr for ANullableContainer { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { "NullableThing" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in ANullableContainer".to_string()), "RequiredNullableThing" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in ANullableContainer".to_string()), @@ -197,6 +204,7 @@ pub struct AllOfObject { } impl AllOfObject { + #[allow(clippy::new_without_default)] pub fn new() -> AllOfObject { AllOfObject { sample_property: None, @@ -210,20 +218,26 @@ impl AllOfObject { /// Should be implemented in a serde serializer impl std::string::ToString for AllOfObject { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref sample_property) = self.sample_property { - params.push("sampleProperty".to_string()); - params.push(sample_property.to_string()); - } + self.sample_property.as_ref().map(|sample_property| { + vec![ + "sampleProperty".to_string(), + sample_property.to_string(), + ].join(",") + }), - if let Some(ref sample_base_propery) = self.sample_base_propery { - params.push("sampleBasePropery".to_string()); - params.push(sample_base_propery.to_string()); - } + self.sample_base_propery.as_ref().map(|sample_base_propery| { + vec![ + "sampleBasePropery".to_string(), + sample_base_propery.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -234,8 +248,9 @@ impl std::str::FromStr for AllOfObject { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub sample_property: Vec, pub sample_base_propery: Vec, @@ -244,7 +259,7 @@ impl std::str::FromStr for AllOfObject { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -254,9 +269,12 @@ impl std::str::FromStr for AllOfObject { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "sampleProperty" => intermediate_rep.sample_property.push(::from_str(val).map_err(|x| format!("{}", x))?), - "sampleBasePropery" => intermediate_rep.sample_base_propery.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "sampleProperty" => intermediate_rep.sample_property.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "sampleBasePropery" => intermediate_rep.sample_base_propery.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing AllOfObject".to_string()) } } @@ -322,6 +340,7 @@ pub struct BaseAllOf { } impl BaseAllOf { + #[allow(clippy::new_without_default)] pub fn new() -> BaseAllOf { BaseAllOf { sample_base_propery: None, @@ -334,14 +353,18 @@ impl BaseAllOf { /// Should be implemented in a serde serializer impl std::string::ToString for BaseAllOf { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref sample_base_propery) = self.sample_base_propery { - params.push("sampleBasePropery".to_string()); - params.push(sample_base_propery.to_string()); - } + self.sample_base_propery.as_ref().map(|sample_base_propery| { + vec![ + "sampleBasePropery".to_string(), + sample_base_propery.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -352,8 +375,9 @@ impl std::str::FromStr for BaseAllOf { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub sample_base_propery: Vec, } @@ -361,7 +385,7 @@ impl std::str::FromStr for BaseAllOf { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -371,8 +395,10 @@ impl std::str::FromStr for BaseAllOf { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "sampleBasePropery" => intermediate_rep.sample_base_propery.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "sampleBasePropery" => intermediate_rep.sample_base_propery.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing BaseAllOf".to_string()) } } @@ -440,9 +466,10 @@ pub struct DummyPutRequest { } impl DummyPutRequest { + #[allow(clippy::new_without_default)] pub fn new(id: String, ) -> DummyPutRequest { DummyPutRequest { - id: id, + id, password: None, } } @@ -453,18 +480,22 @@ impl DummyPutRequest { /// Should be implemented in a serde serializer impl std::string::ToString for DummyPutRequest { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - params.push("id".to_string()); - params.push(self.id.to_string()); + Some("id".to_string()), + Some(self.id.to_string()), - if let Some(ref password) = self.password { - params.push("password".to_string()); - params.push(password.to_string()); - } + self.password.as_ref().map(|password| { + vec![ + "password".to_string(), + password.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -475,8 +506,9 @@ impl std::str::FromStr for DummyPutRequest { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub id: Vec, pub password: Vec, @@ -485,7 +517,7 @@ impl std::str::FromStr for DummyPutRequest { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -495,9 +527,12 @@ impl std::str::FromStr for DummyPutRequest { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| format!("{}", x))?), - "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "id" => intermediate_rep.id.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "password" => intermediate_rep.password.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing DummyPutRequest".to_string()) } } @@ -508,7 +543,7 @@ impl std::str::FromStr for DummyPutRequest { // Use the intermediate representation to return the struct std::result::Result::Ok(DummyPutRequest { - id: intermediate_rep.id.into_iter().next().ok_or("id missing in DummyPutRequest".to_string())?, + id: intermediate_rep.id.into_iter().next().ok_or_else(|| "id missing in DummyPutRequest".to_string())?, password: intermediate_rep.password.into_iter().next(), }) } @@ -565,6 +600,7 @@ pub struct GetYamlResponse { } impl GetYamlResponse { + #[allow(clippy::new_without_default)] pub fn new() -> GetYamlResponse { GetYamlResponse { value: None, @@ -577,14 +613,18 @@ impl GetYamlResponse { /// Should be implemented in a serde serializer impl std::string::ToString for GetYamlResponse { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - if let Some(ref value) = self.value { - params.push("value".to_string()); - params.push(value.to_string()); - } + self.value.as_ref().map(|value| { + vec![ + "value".to_string(), + value.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -595,8 +635,9 @@ impl std::str::FromStr for GetYamlResponse { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub value: Vec, } @@ -604,7 +645,7 @@ impl std::str::FromStr for GetYamlResponse { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -614,8 +655,10 @@ impl std::str::FromStr for GetYamlResponse { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "value" => intermediate_rep.value.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "value" => intermediate_rep.value.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing GetYamlResponse".to_string()) } } @@ -681,6 +724,7 @@ pub struct ObjectOfObjects { } impl ObjectOfObjects { + #[allow(clippy::new_without_default)] pub fn new() -> ObjectOfObjects { ObjectOfObjects { inner: None, @@ -693,10 +737,12 @@ impl ObjectOfObjects { /// Should be implemented in a serde serializer impl std::string::ToString for ObjectOfObjects { fn to_string(&self) -> String { - let mut params: Vec = vec![]; - // Skipping inner in query parameter serialization + let params: Vec> = vec![ + // Skipping inner in query parameter serialization - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -707,8 +753,9 @@ impl std::str::FromStr for ObjectOfObjects { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub inner: Vec, } @@ -716,7 +763,7 @@ impl std::str::FromStr for ObjectOfObjects { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -726,8 +773,10 @@ impl std::str::FromStr for ObjectOfObjects { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "inner" => intermediate_rep.inner.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "inner" => intermediate_rep.inner.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectOfObjects".to_string()) } } @@ -795,9 +844,10 @@ pub struct ObjectOfObjectsInner { } impl ObjectOfObjectsInner { + #[allow(clippy::new_without_default)] pub fn new(required_thing: String, ) -> ObjectOfObjectsInner { ObjectOfObjectsInner { - required_thing: required_thing, + required_thing, optional_thing: None, } } @@ -808,18 +858,22 @@ impl ObjectOfObjectsInner { /// Should be implemented in a serde serializer impl std::string::ToString for ObjectOfObjectsInner { fn to_string(&self) -> String { - let mut params: Vec = vec![]; + let params: Vec> = vec![ - params.push("required_thing".to_string()); - params.push(self.required_thing.to_string()); + Some("required_thing".to_string()), + Some(self.required_thing.to_string()), - if let Some(ref optional_thing) = self.optional_thing { - params.push("optional_thing".to_string()); - params.push(optional_thing.to_string()); - } + self.optional_thing.as_ref().map(|optional_thing| { + vec![ + "optional_thing".to_string(), + optional_thing.to_string(), + ].join(",") + }), - params.join(",").to_string() + ]; + + params.into_iter().flatten().collect::>().join(",") } } @@ -830,8 +884,9 @@ impl std::str::FromStr for ObjectOfObjectsInner { type Err = String; fn from_str(s: &str) -> std::result::Result { + /// An intermediate representation of the struct to use for parsing. #[derive(Default)] - // An intermediate representation of the struct to use for parsing. + #[allow(dead_code)] struct IntermediateRep { pub required_thing: Vec, pub optional_thing: Vec, @@ -840,7 +895,7 @@ impl std::str::FromStr for ObjectOfObjectsInner { let mut intermediate_rep = IntermediateRep::default(); // Parse into intermediate representation - let mut string_iter = s.split(',').into_iter(); + let mut string_iter = s.split(','); let mut key_result = string_iter.next(); while key_result.is_some() { @@ -850,9 +905,12 @@ impl std::str::FromStr for ObjectOfObjectsInner { }; if let Some(key) = key_result { + #[allow(clippy::match_single_binding)] match key { - "required_thing" => intermediate_rep.required_thing.push(::from_str(val).map_err(|x| format!("{}", x))?), - "optional_thing" => intermediate_rep.optional_thing.push(::from_str(val).map_err(|x| format!("{}", x))?), + #[allow(clippy::redundant_clone)] + "required_thing" => intermediate_rep.required_thing.push(::from_str(val).map_err(|x| x.to_string())?), + #[allow(clippy::redundant_clone)] + "optional_thing" => intermediate_rep.optional_thing.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectOfObjectsInner".to_string()) } } @@ -863,7 +921,7 @@ impl std::str::FromStr for ObjectOfObjectsInner { // Use the intermediate representation to return the struct std::result::Result::Ok(ObjectOfObjectsInner { - required_thing: intermediate_rep.required_thing.into_iter().next().ok_or("required_thing missing in ObjectOfObjectsInner".to_string())?, + required_thing: intermediate_rep.required_thing.into_iter().next().ok_or_else(|| "required_thing missing in ObjectOfObjectsInner".to_string())?, optional_thing: intermediate_rep.optional_thing.into_iter().next(), }) } diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs index 2b63c4e1d2c8..52df96f3ef60 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs @@ -120,7 +120,7 @@ impl Service where { pub fn new(api_impl: T) -> Self { Service { - api_impl: api_impl, + api_impl, marker: PhantomData } } @@ -133,7 +133,7 @@ impl Clone for Service where fn clone(&self) -> Self { Service { api_impl: self.api_impl.clone(), - marker: self.marker.clone(), + marker: self.marker, } } } @@ -159,17 +159,17 @@ impl hyper::service::Service<(Request, C)> for Service where let (method, uri, headers) = (parts.method, parts.uri, parts.headers); let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); - match &method { + match method { // AllOfGet - GET /allOf - &hyper::Method::GET if path.matched(paths::ID_ALLOF) => { + hyper::Method::GET if path.matched(paths::ID_ALLOF) => { let result = api_impl.all_of_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -198,14 +198,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // DummyGet - GET /dummy - &hyper::Method::GET if path.matched(paths::ID_DUMMY) => { + hyper::Method::GET if path.matched(paths::ID_DUMMY) => { let result = api_impl.dummy_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -227,7 +227,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // DummyPut - PUT /dummy - &hyper::Method::PUT if path.matched(paths::ID_DUMMY) => { + hyper::Method::PUT if path.matched(paths::ID_DUMMY) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -265,7 +265,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -300,14 +300,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // FileResponseGet - GET /file_response - &hyper::Method::GET if path.matched(paths::ID_FILE_RESPONSE) => { + hyper::Method::GET if path.matched(paths::ID_FILE_RESPONSE) => { let result = api_impl.file_response_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -336,14 +336,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // GetStructuredYaml - GET /get-structured-yaml - &hyper::Method::GET if path.matched(paths::ID_GET_STRUCTURED_YAML) => { + hyper::Method::GET if path.matched(paths::ID_GET_STRUCTURED_YAML) => { let result = api_impl.get_structured_yaml( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -372,7 +372,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // HtmlPost - POST /html - &hyper::Method::POST if path.matched(paths::ID_HTML) => { + hyper::Method::POST if path.matched(paths::ID_HTML) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -405,7 +405,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -440,7 +440,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // PostYaml - POST /post-yaml - &hyper::Method::POST if path.matched(paths::ID_POST_YAML) => { + hyper::Method::POST if path.matched(paths::ID_POST_YAML) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -473,7 +473,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -501,14 +501,14 @@ impl hyper::service::Service<(Request, C)> for Service where }, // RawJsonGet - GET /raw_json - &hyper::Method::GET if path.matched(paths::ID_RAW_JSON) => { + hyper::Method::GET if path.matched(paths::ID_RAW_JSON) => { let result = api_impl.raw_json_get( &context ).await; let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); match result { @@ -537,7 +537,7 @@ impl hyper::service::Service<(Request, C)> for Service where }, // SoloObjectPost - POST /solo-object - &hyper::Method::POST if path.matched(paths::ID_SOLO_OBJECT) => { + hyper::Method::POST if path.matched(paths::ID_SOLO_OBJECT) => { // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -575,7 +575,7 @@ impl hyper::service::Service<(Request, C)> for Service where let mut response = Response::new(Body::empty()); response.headers_mut().insert( HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has).get().0.clone().to_string().as_str()) + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) .expect("Unable to create X-Span-ID header value")); if !unused_elements.is_empty() { @@ -629,25 +629,25 @@ pub struct ApiRequestParser; impl RequestParser for ApiRequestParser { fn parse_operation_id(request: &Request) -> Option<&'static str> { let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path()); - match request.method() { + match *request.method() { // AllOfGet - GET /allOf - &hyper::Method::GET if path.matched(paths::ID_ALLOF) => Some("AllOfGet"), + hyper::Method::GET if path.matched(paths::ID_ALLOF) => Some("AllOfGet"), // DummyGet - GET /dummy - &hyper::Method::GET if path.matched(paths::ID_DUMMY) => Some("DummyGet"), + hyper::Method::GET if path.matched(paths::ID_DUMMY) => Some("DummyGet"), // DummyPut - PUT /dummy - &hyper::Method::PUT if path.matched(paths::ID_DUMMY) => Some("DummyPut"), + hyper::Method::PUT if path.matched(paths::ID_DUMMY) => Some("DummyPut"), // FileResponseGet - GET /file_response - &hyper::Method::GET if path.matched(paths::ID_FILE_RESPONSE) => Some("FileResponseGet"), + hyper::Method::GET if path.matched(paths::ID_FILE_RESPONSE) => Some("FileResponseGet"), // GetStructuredYaml - GET /get-structured-yaml - &hyper::Method::GET if path.matched(paths::ID_GET_STRUCTURED_YAML) => Some("GetStructuredYaml"), + hyper::Method::GET if path.matched(paths::ID_GET_STRUCTURED_YAML) => Some("GetStructuredYaml"), // HtmlPost - POST /html - &hyper::Method::POST if path.matched(paths::ID_HTML) => Some("HtmlPost"), + hyper::Method::POST if path.matched(paths::ID_HTML) => Some("HtmlPost"), // PostYaml - POST /post-yaml - &hyper::Method::POST if path.matched(paths::ID_POST_YAML) => Some("PostYaml"), + hyper::Method::POST if path.matched(paths::ID_POST_YAML) => Some("PostYaml"), // RawJsonGet - GET /raw_json - &hyper::Method::GET if path.matched(paths::ID_RAW_JSON) => Some("RawJsonGet"), + hyper::Method::GET if path.matched(paths::ID_RAW_JSON) => Some("RawJsonGet"), // SoloObjectPost - POST /solo-object - &hyper::Method::POST if path.matched(paths::ID_SOLO_OBJECT) => Some("SoloObjectPost"), + hyper::Method::POST if path.matched(paths::ID_SOLO_OBJECT) => Some("SoloObjectPost"), _ => None, } } diff --git a/samples/server/petstore/rust-server/pom.xml b/samples/server/petstore/rust-server/pom.xml index eeefcb808a5b..61e50dcc15a0 100644 --- a/samples/server/petstore/rust-server/pom.xml +++ b/samples/server/petstore/rust-server/pom.xml @@ -53,6 +53,19 @@ + + clippy + integration-test + + exec + + + cargo + + clippy + + +