Skip to content

Commit

Permalink
Merge pull request #557 from arlyon/clippy
Browse files Browse the repository at this point in the history
Clippy: leftovers, codegen
  • Loading branch information
jwiesler committed May 24, 2024
2 parents c000481 + c63c197 commit 9347c1b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 23 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
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
//! > Want to implement your own? If it is a common strategy, please consider opening a PR to add it to the library.
//! Otherwise, we are open to turning this into an open trait so that you can implement your own strategy.

#![allow(clippy::map_clone, clippy::large_enum_variant)]
#![warn(clippy::unwrap_used, clippy::missing_panics_doc)]
#![allow(clippy::large_enum_variant)]
#![warn(clippy::missing_panics_doc)]
#![forbid(unsafe_code)]
// Workaround
#![allow(ambiguous_glob_reexports)]
Expand Down
2 changes: 1 addition & 1 deletion src/resources/checkout_session_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ impl CheckoutSession {
id: &CheckoutSessionId,
params: &RetrieveCheckoutSessionLineItems,
) -> Response<List<CheckoutSessionItem>> {
client.get_query(&format!("/checkout/sessions/{}/line_items", id), &params)
client.get_query(&format!("/checkout/sessions/{}/line_items", id), params)
}
}
12 changes: 3 additions & 9 deletions src/resources/customer_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::resources::{
BankAccount, Customer, PaymentMethod, PaymentSource, PaymentSourceParams, Source,
};

#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
#[derive(Clone, Debug, Serialize, Default, Eq, PartialEq)]
pub struct CustomerPaymentMethodRetrieval<'a> {
/// A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list.
///For instance, if you make a list request and receive 100 objects, starting with `obj_bar`,
Expand Down Expand Up @@ -37,13 +37,7 @@ pub struct CustomerPaymentMethodRetrieval<'a> {

impl<'a> CustomerPaymentMethodRetrieval<'a> {
pub fn new() -> Self {
CustomerPaymentMethodRetrieval {
ending_before: None,
expand: &[],
limit: None,
starting_after: None,
type_: None,
}
CustomerPaymentMethodRetrieval::default()
}
}

Expand Down Expand Up @@ -83,7 +77,7 @@ pub struct CustomerSearchParams<'a> {

impl<'a> CustomerSearchParams<'a> {
pub fn new() -> CustomerSearchParams<'a> {
CustomerSearchParams { query: String::new(), limit: None, page: None, expand: &[] }
CustomerSearchParams::default()
}
}

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 9347c1b

Please sign in to comment.