Skip to content

Commit

Permalink
fix: Run clippy on openapi generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiesler committed May 24, 2024
1 parent 888307d commit c63c197
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/async-stripe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions openapi/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -575,7 +575,7 @@ pub fn gen_inferred_params(
self.starting_after = Some(item.id());
}",
);
out.push_str("}");
out.push('}');
}
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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::<Vec<_>>();
Expand Down
5 changes: 2 additions & 3 deletions openapi/src/file_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::{
url_finder::UrlFinder,
};

///
#[derive(Default, Debug)]
pub struct FileGenerator {
pub name: String,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -235,7 +234,7 @@ impl Eq for FileGenerator {}

impl PartialOrd for FileGenerator {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.name.partial_cmp(&other.name)
Some(self.cmp(other))
}
}

Expand Down
1 change: 1 addition & 0 deletions openapi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions openapi/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(&self, out_path: T)
Expand All @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion openapi/src/url_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() })
Expand Down
1 change: 1 addition & 0 deletions src/resources/setup_intent_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl SetupIntent {
setup_id: &SetupIntentId,
params: VerifyMicrodeposits,
) -> Response<SetupIntent> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form(&format!("/setup_intents/{}/verify_microdeposits", setup_id), &params)
}

Expand Down

0 comments on commit c63c197

Please sign in to comment.