Skip to content

Commit da22a60

Browse files
committed
Appease clippy lints in rust 1.88
1 parent 8cf7c56 commit da22a60

85 files changed

Lines changed: 4101 additions & 5707 deletions

File tree

Some content is hidden

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

modules/openapi-generator/src/main/resources/rust-server-deprecated/client-mod.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ fn into_base_path(input: impl TryInto<Uri, Error=hyper::http::uri::InvalidUri>,
2222
}
2323

2424
let host = uri.host().ok_or(ClientInitError::MissingHost)?;
25-
let port = uri.port_u16().map(|x| format!(":{}", x)).unwrap_or_default();
26-
Ok(format!("{}://{}{}{}", scheme, host, port, uri.path().trim_end_matches('/')))
25+
let port = uri.port_u16().map(|x| format!(":{x}")).unwrap_or_default();
26+
Ok(format!("{scheme}://{host}{port}{}", uri.path().trim_end_matches('/')))
2727
}
2828

2929
/// A client that implements the API by making HTTP calls out to a server.

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
context: &C) -> Result<{{{operationId}}}Response, ApiError>
1212
{
1313
let mut client_service = self.client_service.clone();
14+
#[allow(clippy::uninlined_format_args)]
1415
let mut uri = format!(
1516
{{#isCallbackRequest}}
1617
"{{vendorExtensions.x-path-format-string}}"
@@ -41,7 +42,7 @@
4142
{{#x-consumes-json}}
4243
&match serde_json::to_string(&param_{{{paramName}}}) {
4344
Ok(str) => str,
44-
Err(e) => return Err(ApiError(format!("Unable to serialize {{{paramName}}} to string: {}", e))),
45+
Err(e) => return Err(ApiError(format!("Unable to serialize {{{paramName}}} to string: {e}"))),
4546
});
4647
{{/x-consumes-json}}
4748
{{^x-consumes-json}}
@@ -75,21 +76,21 @@
7576

7677
let uri = match Uri::from_str(&uri) {
7778
Ok(uri) => uri,
78-
Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
79+
Err(err) => return Err(ApiError(format!("Unable to build URI: {err}"))),
7980
};
8081

8182
let mut request = match Request::builder()
8283
.method("{{{vendorExtensions.x-http-method}}}")
8384
.uri(uri)
8485
.body(Body::empty()) {
8586
Ok(req) => req,
86-
Err(e) => return Err(ApiError(format!("Unable to create request: {}", e)))
87+
Err(e) => return Err(ApiError(format!("Unable to create request: {e}")))
8788
};
8889
{{>client-request-body-instance}}
8990
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
9091
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
9192
Ok(h) => h,
92-
Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e)))
93+
Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {e}")))
9394
});
9495

9596
{{#hasAuthMethods}}
@@ -102,9 +103,9 @@
102103
{{#isBasicBasic}}
103104
AuthData::Basic(basic_header) => {
104105
let auth = swagger::auth::Header(basic_header.clone());
105-
let header = match HeaderValue::from_str(&format!("{}", auth)) {
106+
let header = match HeaderValue::from_str(&format!("{auth}")) {
106107
Ok(h) => h,
107-
Err(e) => return Err(ApiError(format!("Unable to create Authorization header: {}", e)))
108+
Err(e) => return Err(ApiError(format!("Unable to create Authorization header: {e}")))
108109
};
109110
request.headers_mut().insert(
110111
hyper::header::AUTHORIZATION,
@@ -114,9 +115,9 @@
114115
{{#isBasicBearer}}
115116
AuthData::Bearer(bearer_header) => {
116117
let auth = swagger::auth::Header(bearer_header.clone());
117-
let header = match HeaderValue::from_str(&format!("{}", auth)) {
118+
let header = match HeaderValue::from_str(&format!("{auth}")) {
118119
Ok(h) => h,
119-
Err(e) => return Err(ApiError(format!("Unable to create Authorization header: {}", e)))
120+
Err(e) => return Err(ApiError(format!("Unable to create Authorization header: {e}")))
120121
};
121122
request.headers_mut().insert(
122123
hyper::header::AUTHORIZATION,
@@ -127,9 +128,9 @@
127128
{{^isBasicBearer}}
128129
AuthData::Bearer(bearer_header) => {
129130
let auth = swagger::auth::Header(bearer_header.clone());
130-
let header = match HeaderValue::from_str(&format!("{}", auth)) {
131+
let header = match HeaderValue::from_str(&format!("{auth}")) {
131132
Ok(h) => h,
132-
Err(e) => return Err(ApiError(format!("Unable to create Authorization header: {}", e)))
133+
Err(e) => return Err(ApiError(format!("Unable to create Authorization header: {e}")))
133134
};
134135
request.headers_mut().insert(
135136
hyper::header::AUTHORIZATION,
@@ -160,7 +161,7 @@
160161
Ok(header) => header,
161162
Err(e) => {
162163
return Err(ApiError(format!(
163-
"Invalid header {{{paramName}}} - {}", e)));
164+
"Invalid header {{{paramName}}} - {e}")));
164165
},
165166
});
166167
{{^required}}
@@ -175,7 +176,7 @@
175176

176177
{{/headerParams}}
177178
let response = client_service.call((request, context.clone()))
178-
.map_err(|e| ApiError(format!("No response received: {}", e))).await?;
179+
.map_err(|e| ApiError(format!("No response received: {e}"))).await?;
179180

180181
match response.status().as_u16() {
181182
{{#responses}}
@@ -187,7 +188,7 @@
187188
let response_{{{name}}} = match TryInto::<header::IntoHeaderValue<{{{dataType}}}>>::try_into(response_{{{name}}}) {
188189
Ok(value) => value,
189190
Err(e) => {
190-
return Err(ApiError(format!("Invalid response header {{baseName}} for response {{code}} - {}", e)));
191+
return Err(ApiError(format!("Invalid response header {{baseName}} for response {{code}} - {e}")));
191192
},
192193
};
193194
{{#required}}
@@ -210,7 +211,7 @@
210211
let body = response.into_body();
211212
let body = body
212213
.into_raw()
213-
.map_err(|e| ApiError(format!("Failed to read response: {}", e))).await?;
214+
.map_err(|e| ApiError(format!("Failed to read response: {e}"))).await?;
214215

215216
{{>client-response-body-instance}}
216217

@@ -251,15 +252,13 @@
251252
let body = response.into_body()
252253
.take(100)
253254
.into_raw().await;
254-
Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
255-
code,
256-
headers,
255+
Err(ApiError(format!("Unexpected response code {code}:\n{headers:?}\n\n{}",
257256
match body {
258257
Ok(body) => match String::from_utf8(body) {
259258
Ok(body) => body,
260-
Err(e) => format!("<Body was not UTF8: {:?}>", e),
259+
Err(e) => format!("<Body was not UTF8: {e:?}>"),
261260
},
262-
Err(e) => format!("<Failed to read body: {}>", e),
261+
Err(e) => format!("<Failed to read body: {e}>"),
263262
}
264263
)))
265264
}

modules/openapi-generator/src/main/resources/rust-server-deprecated/client-request-body-instance.mustache

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
&[header.as_bytes(), "; boundary=".as_bytes(), &boundary, "; type=\"application/json\"".as_bytes()].concat()
1818
) {
1919
Ok(h) => h,
20-
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
20+
Err(e) => return Err(ApiError(format!("Unable to create header: {header} - {e}")))
2121
});
2222

2323
// Add the message body to the request object.
@@ -37,6 +37,7 @@
3737
// style=form,explode=true
3838
for param_{{{paramName}}} in param_{{{paramName}}} {
3939
{{/isArray}}
40+
#[allow(clippy::uninlined_format_args)]
4041
params.push(("{{{baseName}}}",
4142
{{^isString}}
4243
format!("{{{vendorExtensions.x-format-string}}}", param_{{{paramName}}})
@@ -65,7 +66,7 @@
6566
let header = "{{#consumes}}{{#-first}}{{{mediaType}}}{{/-first}}{{/consumes}}{{^consumes}}application/json{{/consumes}}";
6667
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
6768
Ok(h) => h,
68-
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
69+
Err(e) => return Err(ApiError(format!("Unable to create header: {header} - {e}")))
6970
});
7071
{{/-last}}
7172
{{/formParams}}
@@ -102,7 +103,7 @@
102103
let header = "{{#consumes}}{{#-first}}{{{mediaType}}}{{/-first}}{{/consumes}}{{^consumes}}application/json{{/consumes}}";
103104
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
104105
Ok(h) => h,
105-
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", header, e)))
106+
Err(e) => return Err(ApiError(format!("Unable to create header: {header} - {e}")))
106107
});
107108
{{/bodyParam}}
108109
{{/x-consumes-basic}}

modules/openapi-generator/src/main/resources/rust-server-deprecated/client-request-body-multipart-form.mustache

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{{#jsonSchema}}
1212
let {{{paramName}}}_str = match serde_json::to_string(&param_{{{paramName}}}) {
1313
Ok(str) => str,
14-
Err(e) => return Err(ApiError(format!("Unable to serialize {{{paramName}}} to string: {}", e))),
14+
Err(e) => return Err(ApiError(format!("Unable to serialize {{{paramName}}} to string: {e}"))),
1515
};
1616

1717
let {{{paramName}}}_vec = {{{paramName}}}_str.as_bytes().to_vec();
@@ -27,7 +27,7 @@
2727

2828
let {{{paramName}}}_mime = match mime_0_2::Mime::from_str("application/octet-stream") {
2929
Ok(mime) => mime,
30-
Err(err) => return Err(ApiError(format!("Unable to get mime type: {:?}", err))),
30+
Err(err) => return Err(ApiError(format!("Unable to get mime type: {err:?}"))),
3131
};
3232

3333
let {{{paramName}}}_cursor = Cursor::new({{{paramName}}}_vec);
@@ -40,19 +40,19 @@
4040

4141
let mut fields = match multipart.prepare() {
4242
Ok(fields) => fields,
43-
Err(err) => return Err(ApiError(format!("Unable to build request: {}", err))),
43+
Err(err) => return Err(ApiError(format!("Unable to build request: {err}"))),
4444
};
4545

4646
let mut body_string = String::new();
4747

4848
match fields.read_to_string(&mut body_string) {
4949
Ok(_) => (),
50-
Err(err) => return Err(ApiError(format!("Unable to build body: {}", err))),
50+
Err(err) => return Err(ApiError(format!("Unable to build body: {err}"))),
5151
}
5252

5353
let boundary = fields.boundary();
5454

55-
let multipart_header = format!("multipart/form-data;boundary={}", boundary);
55+
let multipart_header = format!("multipart/form-data;{boundary}");
5656

5757
(body_string, multipart_header)
5858
};
@@ -61,5 +61,5 @@
6161

6262
request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(&multipart_header) {
6363
Ok(h) => h,
64-
Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", multipart_header, e)))
64+
Err(e) => return Err(ApiError(format!("Unable to create header: {multipart_header} - {e}")))
6565
});

modules/openapi-generator/src/main/resources/rust-server-deprecated/client-response-body-instance.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
{{/x-produces-bytes}}
55
{{^x-produces-bytes}}
66
let body = str::from_utf8(&body)
7-
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
7+
.map_err(|e| ApiError(format!("Response was not valid UTF8: {e}")))?;
88
{{#x-produces-xml}}
99
// ToDo: this will move to swagger-rs and become a standard From conversion trait
1010
// once https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
1111
let body = serde_xml_rs::from_str::<{{{dataType}}}>(body)
12-
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
12+
.map_err(|e| ApiError(format!("Response body did not match the schema: {e}")))?;
1313
{{/x-produces-xml}}
1414
{{#x-produces-json}}
1515
let body = serde_json::from_str::<{{{dataType}}}>(body)
16-
.map_err(|e| ApiError(format!("Response body did not match the schema: {}", e)))?;
16+
.map_err(|e| ApiError(format!("Response body did not match the schema: {e}")))?;
1717
{{/x-produces-json}}
1818
{{#x-produces-plain-text}}
1919
let body = body.to_string();

modules/openapi-generator/src/main/resources/rust-server-deprecated/client-response-body-multipart-related.mustache

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let multipart_headers = match swagger::multipart::related::create_multipart_head
1111
let nodes = match read_multipart_body(&mut&*body, &multipart_headers, false) {
1212
Ok(nodes) => nodes,
1313
Err(e) => {
14-
return Err(ApiError(format!("Could not read multipart body for {{operationId}}: {}", e)));
14+
return Err(ApiError(format!("Could not read multipart body for {{operationId}}: {e}")));
1515
}
1616
};
1717

@@ -21,18 +21,18 @@ let mut param_{{{paramName}}} = None;
2121

2222
for node in nodes {
2323
if let Node::Part(part) = node {
24-
let content_type = part.content_type().map(|x| format!("{}",x));
24+
let content_type = part.content_type().map(|x| format!("{x}"));
2525
match content_type.as_ref().map(|x| x.as_str()) {
2626
{{#formParams}}
2727
{{^isBinary}}
2828
Some("{{{contentType}}}") if param_{{{paramName}}}.is_none() => {
2929
// Extract JSON part.
3030
let deserializer = &mut serde_json::Deserializer::from_slice(part.body.as_slice());
3131
let json_data: {{{dataType}}} = match serde_ignored::deserialize(deserializer, |path| {
32-
warn!("Ignoring unknown field in JSON part: {}", path);
32+
warn!("Ignoring unknown field in JSON part: {path}");
3333
}) {
3434
Ok(json_data) => json_data,
35-
Err(e) => return Err(ApiError(format!("Couldn't parse body parameter {{dataType}} - doesn't match schema: {}", e)))
35+
Err(e) => return Err(ApiError(format!("Couldn't parse body parameter {{dataType}} - doesn't match schema: {e}")))
3636
};
3737
// Push JSON part to return object.
3838
param_{{{paramName}}}.get_or_insert(json_data);
@@ -45,14 +45,14 @@ for node in nodes {
4545
{{/isBinary}}
4646
{{/formParams}}
4747
Some(content_type) => {
48-
warn!("Ignoring unexpected content type: {}", content_type);
48+
warn!("Ignoring unexpected content type: {content_type}");
4949
},
5050
None => {
5151
warn!("Missing content type");
5252
},
5353
}
5454
} else {
55-
return Err(ApiError(format!("Unexpected part in multipart body for {{operationId}}: {:?}", node)));
55+
return Err(ApiError(format!("Unexpected part in multipart body for {{operationId}}: {node:?}")));
5656
}
5757
}
5858
{{#formParams}}

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ macro_rules! ihv_generate {
3434
Err(e) => Err(format!("Unable to parse {} as a string: {}",
3535
stringify!($t), e)),
3636
},
37-
Err(e) => Err(format!("Unable to parse header {:?} as a string - {}",
38-
hdr_value, e)),
37+
Err(e) => Err(format!("Unable to parse header {hdr_value:?} as a string - {e}")),
3938
}
4039
}
4140
}
@@ -76,8 +75,7 @@ impl TryFrom<HeaderValue> for IntoHeaderValue<Vec<String>> {
7675
y => Some(y.to_string()),
7776
})
7877
.collect())),
79-
Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}",
80-
hdr_value, e)),
78+
Err(e) => Err(format!("Unable to parse header: {hdr_value:?} as a string - {e}")),
8179
}
8280
}
8381
}
@@ -88,8 +86,7 @@ impl TryFrom<IntoHeaderValue<Vec<String>>> for HeaderValue {
8886
fn try_from(hdr_value: IntoHeaderValue<Vec<String>>) -> Result<Self, Self::Error> {
8987
match HeaderValue::from_str(&hdr_value.0.join(", ")) {
9088
Ok(hdr_value) => Ok(hdr_value),
91-
Err(e) => Err(format!("Unable to convert {:?} into a header - {}",
92-
hdr_value, e))
89+
Err(e) => Err(format!("Unable to convert {hdr_value:?} into a header - {e}"))
9390
}
9491
}
9592
}
@@ -102,8 +99,7 @@ impl TryFrom<HeaderValue> for IntoHeaderValue<String> {
10299
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
103100
match hdr_value.to_str() {
104101
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())),
105-
Err(e) => Err(format!("Unable to convert header {:?} to {}",
106-
hdr_value, e)),
102+
Err(e) => Err(format!("Unable to convert header {hdr_value:?} to {e}")),
107103
}
108104
}
109105
}
@@ -114,8 +110,7 @@ impl TryFrom<IntoHeaderValue<String>> for HeaderValue {
114110
fn try_from(hdr_value: IntoHeaderValue<String>) -> Result<Self, Self::Error> {
115111
match HeaderValue::from_str(&hdr_value.0) {
116112
Ok(hdr_value) => Ok(hdr_value),
117-
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
118-
hdr_value, e))
113+
Err(e) => Err(format!("Unable to convert {hdr_value:?} from a header {e}"))
119114
}
120115
}
121116
}
@@ -128,11 +123,9 @@ impl TryFrom<HeaderValue> for IntoHeaderValue<bool> {
128123
match hdr_value.to_str() {
129124
Ok(hdr_value) => match hdr_value.parse() {
130125
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
131-
Err(e) => Err(format!("Unable to parse bool from {} - {}",
132-
hdr_value, e)),
126+
Err(e) => Err(format!("Unable to parse bool from {hdr_value} - {e}")),
133127
},
134-
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
135-
hdr_value, e)),
128+
Err(e) => Err(format!("Unable to convert {hdr_value:?} from a header {e}")),
136129
}
137130
}
138131
}
@@ -143,8 +136,7 @@ impl TryFrom<IntoHeaderValue<bool>> for HeaderValue {
143136
fn try_from(hdr_value: IntoHeaderValue<bool>) -> Result<Self, Self::Error> {
144137
match HeaderValue::from_str(&hdr_value.0.to_string()) {
145138
Ok(hdr_value) => Ok(hdr_value),
146-
Err(e) => Err(format!("Unable to convert: {:?} into a header: {}",
147-
hdr_value, e))
139+
Err(e) => Err(format!("Unable to convert: {hdr_value:?} into a header: {e}"))
148140
}
149141
}
150142
}
@@ -158,11 +150,9 @@ impl TryFrom<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
158150
match hdr_value.to_str() {
159151
Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) {
160152
Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))),
161-
Err(e) => Err(format!("Unable to parse: {} as date - {}",
162-
hdr_value, e)),
153+
Err(e) => Err(format!("Unable to parse: {hdr_value} as date - {e}")),
163154
},
164-
Err(e) => Err(format!("Unable to convert header {:?} to string {}",
165-
hdr_value, e)),
155+
Err(e) => Err(format!("Unable to convert header {hdr_value:?} to string {e}")),
166156
}
167157
}
168158
}
@@ -173,8 +163,7 @@ impl TryFrom<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
173163
fn try_from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Result<Self, Self::Error> {
174164
match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) {
175165
Ok(hdr_value) => Ok(hdr_value),
176-
Err(e) => Err(format!("Unable to convert {:?} to a header: {}",
177-
hdr_value, e)),
166+
Err(e) => Err(format!("Unable to convert {hdr_value:?} to a header: {e}")),
178167
}
179168
}
180169
}

0 commit comments

Comments
 (0)