From c63c197e7cd6f73c0183345c82be77ef2a4c06f5 Mon Sep 17 00:00:00 2001 From: Julian Wiesler Date: Fri, 24 May 2024 17:02:53 +0200 Subject: [PATCH] fix: Run clippy on openapi generator --- .github/workflows/async-stripe.yml | 12 ++++++++++++ openapi/src/codegen.rs | 10 +++++----- openapi/src/file_generator.rs | 5 ++--- openapi/src/main.rs | 1 + openapi/src/metadata.rs | 4 ++-- openapi/src/url_finder.rs | 2 +- src/resources/setup_intent_ext.rs | 1 + 7 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/async-stripe.yml b/.github/workflows/async-stripe.yml index 25538d8d0..62a2f5bac 100644 --- a/.github/workflows/async-stripe.yml +++ b/.github/workflows/async-stripe.yml @@ -50,6 +50,18 @@ jobs: echo "Some files changed after code generation: $CHANGED_FILES" exit 1 + clippy-codegen: + runs-on: ubuntu-20.04 + env: + RUSTFLAGS: -D warnings + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + components: clippy + - run: cargo clippy -p stripe-openapi-codegen --tests + clippy: runs-on: ubuntu-20.04 env: diff --git a/openapi/src/codegen.rs b/openapi/src/codegen.rs index 97582ea42..dc695b00a 100644 --- a/openapi/src/codegen.rs +++ b/openapi/src/codegen.rs @@ -46,7 +46,7 @@ pub fn gen_struct( let obj = as_object_type(schema).expect("Expected object type"); let schema_title = schema.schema_data.title.as_ref().unwrap_or_else(|| { tracing::warn!("{} has no title", object); - &object + object }); let deleted_schema = meta.spec.component_schemas().get(&format!("deleted_{}", object)); @@ -575,7 +575,7 @@ pub fn gen_inferred_params( self.starting_after = Some(item.id()); }", ); - out.push_str("}"); + out.push('}'); } } } @@ -716,8 +716,8 @@ pub fn gen_variant_name(wire_name: &str, meta: &Metadata) -> String { "*" => "All".to_string(), "self" => "Self_".to_string(), n => { - if n.chars().next().unwrap().is_digit(10) { - format!("V{}", n.to_string().replace('-', "_").replace('.', "_")) + if n.chars().next().unwrap().is_ascii_digit() { + format!("V{}", n.to_string().replace(['-', '.'], "_")) } else { meta.schema_to_rust_type(wire_name) } @@ -1341,7 +1341,7 @@ pub fn gen_impl_requests( // from the spec already let request = meta .spec - .get_request_unwrapped(*path) + .get_request_unwrapped(path) .as_item() .expect("Expected item, not path reference"); let segments = path.trim_start_matches("/v1/").split('/').collect::>(); diff --git a/openapi/src/file_generator.rs b/openapi/src/file_generator.rs index f0fe0cf62..af32e2989 100644 --- a/openapi/src/file_generator.rs +++ b/openapi/src/file_generator.rs @@ -24,7 +24,6 @@ use crate::{ url_finder::UrlFinder, }; -/// #[derive(Default, Debug)] pub struct FileGenerator { pub name: String, @@ -206,7 +205,7 @@ impl FileGenerator { pub fn add_use(&mut self, use_path: &str) { for path in use_path.split(',') { - match path.into() { + match path { "" | "String" => {} "Metadata" => { self.use_params.insert("Metadata"); @@ -235,7 +234,7 @@ impl Eq for FileGenerator {} impl PartialOrd for FileGenerator { fn partial_cmp(&self, other: &Self) -> Option { - self.name.partial_cmp(&other.name) + Some(self.cmp(other)) } } diff --git a/openapi/src/main.rs b/openapi/src/main.rs index 46d60ee74..b23274061 100644 --- a/openapi/src/main.rs +++ b/openapi/src/main.rs @@ -7,6 +7,7 @@ use crate::spec::Spec; use crate::spec_fetch::fetch_spec; use crate::{metadata::Metadata, url_finder::UrlFinder}; +#[allow(clippy::too_many_arguments)] mod codegen; mod file_generator; mod mappings; diff --git a/openapi/src/metadata.rs b/openapi/src/metadata.rs index af290c21b..f87a5a99b 100644 --- a/openapi/src/metadata.rs +++ b/openapi/src/metadata.rs @@ -137,7 +137,7 @@ impl<'a> Metadata<'a> { out.push_str("}\n"); } - write(&out_path.as_ref().join("placeholders.rs"), out.as_bytes()).unwrap(); + write(out_path.as_ref().join("placeholders.rs"), out.as_bytes()).unwrap(); } pub fn write_version(&self, out_path: T) @@ -151,7 +151,7 @@ impl<'a> Metadata<'a> { self.spec.version().replace('-', "_") )); - write(&out_path.as_ref().join("version.rs"), out.as_bytes()).unwrap(); + write(out_path.as_ref().join("version.rs"), out.as_bytes()).unwrap(); } #[tracing::instrument(skip_all)] diff --git a/openapi/src/url_finder.rs b/openapi/src/url_finder.rs index f80651f81..70b2608d2 100644 --- a/openapi/src/url_finder.rs +++ b/openapi/src/url_finder.rs @@ -23,7 +23,7 @@ impl UrlFinder { let initial_state: StripeInitialState = serde_json::from_str( line.trim() .trim_start_matches("window.__INITIAL_STATE__ = ") - .trim_end_matches(";"), + .trim_end_matches(';'), ) .expect("should be valid json"); Ok(Self { url_lookup: initial_state.into() }) diff --git a/src/resources/setup_intent_ext.rs b/src/resources/setup_intent_ext.rs index b177ba430..8a3bc6b46 100644 --- a/src/resources/setup_intent_ext.rs +++ b/src/resources/setup_intent_ext.rs @@ -81,6 +81,7 @@ impl SetupIntent { setup_id: &SetupIntentId, params: VerifyMicrodeposits, ) -> Response { + #[allow(clippy::needless_borrows_for_generic_args)] client.post_form(&format!("/setup_intents/{}/verify_microdeposits", setup_id), ¶ms) }