Skip to content

Commit d3c7919

Browse files
Fix formatting for CI rustfmt compatibility
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 14bf4b0 commit d3c7919

9 files changed

Lines changed: 75 additions & 25 deletions

File tree

src/analysis.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3541,7 +3541,9 @@ impl SchemaAnalyzer {
35413541
for param in path_params {
35423542
let resolved = self.resolve_parameter(param);
35433543
if let Some(param_info) = self.analyze_parameter(&resolved)? {
3544-
if !existing_keys.contains(&(param_info.name.clone(), param_info.location.clone())) {
3544+
if !existing_keys
3545+
.contains(&(param_info.name.clone(), param_info.location.clone()))
3546+
{
35453547
op_info.parameters.push(param_info);
35463548
}
35473549
}

src/bin/openapi-to-rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clap::{Parser, Subcommand};
2+
use openapi_to_rust::cli::{json_from_str_lossy, yaml_to_json_value};
23
use openapi_to_rust::{CodeGenerator, ConfigFile, SchemaAnalyzer};
3-
use openapi_to_rust::cli::{yaml_to_json_value, json_from_str_lossy};
44
use std::path::PathBuf;
55

66
#[derive(Parser)]

src/cli.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,10 @@ fn try_sanitize_integer_line(line: &str) -> Option<String> {
373373
// Check if it overflows i64/u64
374374
let overflows = if is_negative {
375375
// Check if |value| > i64::MAX + 1 = 9223372036854775808
376-
digit_part.len() > 19
377-
|| (digit_part.len() == 19 && digit_part > "9223372036854775808")
376+
digit_part.len() > 19 || (digit_part.len() == 19 && digit_part > "9223372036854775808")
378377
} else {
379378
// Check if value > u64::MAX = 18446744073709551615
380-
digit_part.len() > 20
381-
|| (digit_part.len() == 20 && digit_part > "18446744073709551615")
379+
digit_part.len() > 20 || (digit_part.len() == 20 && digit_part > "18446744073709551615")
382380
};
383381

384382
if overflows {

src/client_generator.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,5 +773,4 @@ impl CodeGenerator {
773773
snake_case
774774
}
775775
}
776-
777776
}

src/generator.rs

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,9 @@ impl CodeGenerator {
12521252
// Generate rename attribute if field name differs from Rust identifier
12531253
// Strip r# prefix for comparison since serde handles raw idents transparently
12541254
let rust_field_name = self.to_rust_field_name(field_name);
1255-
let comparison_name = rust_field_name.strip_prefix("r#").unwrap_or(&rust_field_name);
1255+
let comparison_name = rust_field_name
1256+
.strip_prefix("r#")
1257+
.unwrap_or(&rust_field_name);
12561258
if comparison_name != field_name {
12571259
attrs.push(quote! { rename = #field_name });
12581260
}
@@ -1624,13 +1626,51 @@ impl CodeGenerator {
16241626
pub fn is_rust_keyword(s: &str) -> bool {
16251627
matches!(
16261628
s,
1627-
"type" | "match" | "fn" | "struct" | "enum" | "impl" | "trait" | "mod"
1628-
| "use" | "pub" | "const" | "static" | "let" | "mut" | "ref" | "move"
1629-
| "return" | "if" | "else" | "while" | "for" | "loop" | "break"
1630-
| "continue" | "self" | "super" | "crate" | "async" | "await"
1631-
| "override" | "box" | "dyn" | "where" | "in"
1632-
| "abstract" | "become" | "do" | "final" | "macro" | "priv" | "try"
1633-
| "typeof" | "unsized" | "virtual" | "yield"
1629+
"type"
1630+
| "match"
1631+
| "fn"
1632+
| "struct"
1633+
| "enum"
1634+
| "impl"
1635+
| "trait"
1636+
| "mod"
1637+
| "use"
1638+
| "pub"
1639+
| "const"
1640+
| "static"
1641+
| "let"
1642+
| "mut"
1643+
| "ref"
1644+
| "move"
1645+
| "return"
1646+
| "if"
1647+
| "else"
1648+
| "while"
1649+
| "for"
1650+
| "loop"
1651+
| "break"
1652+
| "continue"
1653+
| "self"
1654+
| "super"
1655+
| "crate"
1656+
| "async"
1657+
| "await"
1658+
| "override"
1659+
| "box"
1660+
| "dyn"
1661+
| "where"
1662+
| "in"
1663+
| "abstract"
1664+
| "become"
1665+
| "do"
1666+
| "final"
1667+
| "macro"
1668+
| "priv"
1669+
| "try"
1670+
| "typeof"
1671+
| "unsized"
1672+
| "virtual"
1673+
| "yield"
16341674
)
16351675
}
16361676

src/openapi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ pub struct MediaType {
515515
}
516516

517517
#[cfg(test)]
518+
#[allow(clippy::unwrap_used)]
518519
mod tests {
519520
use super::*;
520521
use serde_json::json;

src/patterns.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ fn find_common_discriminator_field(_variant_refs: &[String]) -> Option<String> {
159159
}
160160

161161
#[cfg(test)]
162+
#[allow(clippy::unwrap_used)]
162163
mod tests {
163164
use super::*;
164165
use serde_json::json;

src/registry_generator.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,16 @@ impl CodeGenerator {
207207
.collect();
208208

209209
// Sanitize operation ID to a valid Rust identifier for the static name
210-
let sanitized_id: String = op.operation_id
210+
let sanitized_id: String = op
211+
.operation_id
211212
.chars()
212-
.map(|c| if c.is_ascii_alphanumeric() { c.to_ascii_uppercase() } else { '_' })
213+
.map(|c| {
214+
if c.is_ascii_alphanumeric() {
215+
c.to_ascii_uppercase()
216+
} else {
217+
'_'
218+
}
219+
})
213220
.collect();
214221
let params_static_name = syn::Ident::new(
215222
&format!("PARAMS_{sanitized_id}"),
@@ -227,12 +234,14 @@ impl CodeGenerator {
227234
Some(rb) => {
228235
use crate::analysis::RequestBodyContent;
229236
let (content_type, schema_name) = match rb {
230-
RequestBodyContent::Json { schema_name } => {
231-
(quote! { BodyContentType::Json }, quote! { Some(#schema_name) })
232-
}
233-
RequestBodyContent::FormUrlEncoded { schema_name } => {
234-
(quote! { BodyContentType::FormUrlEncoded }, quote! { Some(#schema_name) })
235-
}
237+
RequestBodyContent::Json { schema_name } => (
238+
quote! { BodyContentType::Json },
239+
quote! { Some(#schema_name) },
240+
),
241+
RequestBodyContent::FormUrlEncoded { schema_name } => (
242+
quote! { BodyContentType::FormUrlEncoded },
243+
quote! { Some(#schema_name) },
244+
),
236245
RequestBodyContent::Multipart => {
237246
(quote! { BodyContentType::Multipart }, quote! { None })
238247
}

tests/operation_generation_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ fn test_multiple_operations() {
479479
method: "POST".to_string(),
480480
path: "/users".to_string(),
481481
summary: None,
482-
description: None,
483-
request_body: Some(RequestBodyContent::Json {
482+
description: None,
483+
request_body: Some(RequestBodyContent::Json {
484484
schema_name: "CreateUserRequest".to_string(),
485485
}),
486486
response_schemas: {

0 commit comments

Comments
 (0)