Skip to content

Commit

Permalink
Merge pull request #548 from arlyon/clippy
Browse files Browse the repository at this point in the history
Clippy
  • Loading branch information
jwiesler committed Apr 26, 2024
2 parents a94ffb4 + bfd19fc commit 9c5909c
Show file tree
Hide file tree
Showing 69 changed files with 202 additions and 104 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/async-stripe.yml
Expand Up @@ -52,6 +52,8 @@ jobs:
clippy:
runs-on: ubuntu-20.04
env:
RUSTFLAGS: -D warnings
strategy:
matrix:
runtime:
Expand Down
6 changes: 4 additions & 2 deletions openapi/src/codegen.rs
Expand Up @@ -1387,7 +1387,7 @@ pub fn gen_impl_requests(
let query_path = segments.join("/");
writedoc!(&mut out, r#"
pub fn list(client: &Client, params: &{params_name}<'_>) -> Response<List<{rust_struct}>> {{
client.get_query("/{query_path}", &params)
client.get_query("/{query_path}", params)
}}
"#).unwrap();
methods.insert(MethodTypes::List, out);
Expand All @@ -1414,7 +1414,7 @@ pub fn gen_impl_requests(
out.push_str("> {\n");
out.push_str(" client.get_query(");
out.push_str(&format!("&format!(\"/{}/{{}}\", id)", segments[0]));
out.push_str(", &Expand { expand })\n");
out.push_str(", Expand { expand })\n");
} else {
out.push_str(") -> Response<");
out.push_str(&rust_struct);
Expand Down Expand Up @@ -1473,6 +1473,7 @@ pub fn gen_impl_requests(
out.push_str("<'_>) -> Response<");
out.push_str(&return_type);
out.push_str("> {\n");
out.push_str(" #[allow(clippy::needless_borrows_for_generic_args)]\n");
out.push_str(" client.post_form(\"/");
out.push_str(&segments.join("/"));
out.push_str("\", &params)\n");
Expand Down Expand Up @@ -1513,6 +1514,7 @@ pub fn gen_impl_requests(
out.push_str("<'_>) -> Response<");
out.push_str(&return_type);
out.push_str("> {\n");
out.push_str(" #[allow(clippy::needless_borrows_for_generic_args)]\n");
out.push_str(" client.post_form(");
out.push_str(&format!("&format!(\"/{}/{{}}\", id)", segments[0]));
out.push_str(", &params)\n");
Expand Down
6 changes: 6 additions & 0 deletions src/client/base/async_std.rs
Expand Up @@ -27,6 +27,12 @@ pub struct AsyncStdClient {
client: surf::Client,
}

impl Default for AsyncStdClient {
fn default() -> Self {
Self::new()
}
}

impl AsyncStdClient {
/// Creates a new client pointed to `https://api.stripe.com/`
pub fn new() -> Self {
Expand Down
6 changes: 6 additions & 0 deletions src/client/base/tokio_blocking.rs
Expand Up @@ -28,6 +28,12 @@ pub struct TokioBlockingClient {
runtime: Arc<tokio::runtime::Runtime>,
}

impl Default for TokioBlockingClient {
fn default() -> Self {
Self::new()
}
}

impl TokioBlockingClient {
/// Creates a new client pointed to `https://api.stripe.com/`
pub fn new() -> TokioBlockingClient {
Expand Down
8 changes: 7 additions & 1 deletion src/client/stripe.rs
Expand Up @@ -29,6 +29,9 @@ impl Client {
}

/// Create a new account pointed at a specific URL. This is useful for testing.
///
/// # Panics
/// If the url can't be parsed
pub fn from_url<'a>(url: impl Into<&'a str>, secret_key: impl Into<String>) -> Self {
Client {
client: BaseClient::new(),
Expand Down Expand Up @@ -76,7 +79,7 @@ impl Client {
url: Option<String>,
) -> Self {
let app_info = AppInfo { name, version, url };
self.headers.user_agent = format!("{} {}", USER_AGENT, app_info.to_string());
self.headers.user_agent = format!("{} {}", USER_AGENT, app_info);
self.app_info = Some(app_info);
self
}
Expand Down Expand Up @@ -126,6 +129,9 @@ impl Client {
}

/// Make a `POST` http request with urlencoded body
///
/// # Panics
/// If the form is not serialized to an utf8 string.
pub fn post_form<T: DeserializeOwned + Send + 'static, F: Serialize>(
&self,
path: &str,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -53,7 +53,7 @@
//! 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_errors_doc, clippy::missing_panics_doc)]
#![warn(clippy::unwrap_used, clippy::missing_panics_doc)]
#![forbid(unsafe_code)]
// Workaround
#![allow(ambiguous_glob_reexports)]
Expand Down
19 changes: 10 additions & 9 deletions src/params.rs
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::fmt::Display;

use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
Expand All @@ -20,16 +21,16 @@ pub struct AppInfo {
pub version: Option<String>,
}

impl ToString for AppInfo {
/// Formats a plugin's 'App Info' into a string that can be added to the end of an User-Agent string.
impl Display for AppInfo {
/// Formats a plugin's 'App Info' that can be added to the end of a User-Agent string.
///
/// This formatting matches that of other libraries, and if changed then it should be changed everywhere.
fn to_string(&self) -> String {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match (&self.version, &self.url) {
(Some(a), Some(b)) => format!("{}/{} ({})", &self.name, a, b),
(Some(a), None) => format!("{}/{}", &self.name, a),
(None, Some(b)) => format!("{} ({})", &self.name, b),
_ => self.name.to_string(),
(Some(a), Some(b)) => write!(f, "{}/{} ({})", &self.name, a, b),
(Some(a), None) => write!(f, "{}/{}", &self.name, a),
(None, Some(b)) => write!(f, "{} ({})", &self.name, b),
_ => write!(f, "{}", self.name),
}
}
}
Expand Down Expand Up @@ -327,11 +328,11 @@ where
let mut paginator = self;
loop {
if !paginator.page.has_more() {
data.extend(paginator.page.get_data_mut().drain(..));
data.append(paginator.page.get_data_mut());
break;
}
let next_paginator = paginator.next(client)?;
data.extend(paginator.page.get_data_mut().drain(..));
data.append(paginator.page.get_data_mut());
paginator = next_paginator
}
Ok(data)
Expand Down
3 changes: 2 additions & 1 deletion src/resources.rs
Expand Up @@ -7,8 +7,9 @@
//! some are generated.

mod currency;
#[allow(clippy::module_inception)]
#[allow(clippy::new_without_default)]
pub mod generated;
mod placeholders;
mod types;

#[path = "resources"]
Expand Down
2 changes: 1 addition & 1 deletion src/resources/checkout_session_ext.rs
Expand Up @@ -12,7 +12,7 @@ impl CheckoutSession {
id: &CheckoutSessionId,
expand: &[&str],
) -> Response<CheckoutSession> {
client.get_query(&format!("/checkout/sessions/{}", id), &Expand { expand })
client.get_query(&format!("/checkout/sessions/{}", id), Expand { expand })
}

/// Expires a checkout session.
Expand Down
5 changes: 4 additions & 1 deletion src/resources/customer_balance_transaction_ext.rs
Expand Up @@ -97,6 +97,7 @@ impl Customer {
customer_id: &CustomerId,
params: ListCustomerBalanceTransactions<'_>,
) -> Response<List<CustomerBalanceTransaction>> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.get_query(&format!("/customers/{}/balance_transactions", customer_id), &params)
}

Expand All @@ -106,6 +107,7 @@ impl Customer {
customer_id: &CustomerId,
params: CreateCustomerBalanceTransaction<'_>,
) -> Response<CustomerBalanceTransaction> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form(&format!("/customers/{}/balance_transactions", customer_id), &params)
}

Expand All @@ -118,7 +120,7 @@ impl Customer {
) -> Response<CustomerBalanceTransaction> {
client.get_query(
&format!("/customers/{}/balance_transactions/{}", customer_id, id),
&Expand { expand },
Expand { expand },
)
}

Expand All @@ -131,6 +133,7 @@ impl Customer {
id: &CustomerBalanceTransactionId,
params: UpdateCustomerBalanceTransaction<'_>,
) -> Response<CustomerBalanceTransaction> {
#[allow(clippy::needless_borrows_for_generic_args)]
client
.post_form(&format!("/customers/{}/balance_transactions/{}", customer_id, id), &params)
}
Expand Down
1 change: 1 addition & 0 deletions src/resources/customer_ext.rs
Expand Up @@ -146,6 +146,7 @@ impl Customer {
customer_id: &CustomerId,
params: CustomerPaymentMethodRetrieval<'_>,
) -> Response<List<PaymentMethod>> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.get_query(&format!("/customers/{}/payment_methods", customer_id), &params)
}

Expand Down
6 changes: 4 additions & 2 deletions src/resources/generated/account.rs
Expand Up @@ -122,7 +122,7 @@ impl Account {
///
/// If you’re not a platform, the list is empty.
pub fn list(client: &Client, params: &ListAccounts<'_>) -> Response<List<Account>> {
client.get_query("/accounts", &params)
client.get_query("/accounts", params)
}

/// With [Connect](https://stripe.com/docs/connect), you can create Stripe accounts for your users.
Expand All @@ -133,12 +133,13 @@ impl Account {
///
/// Connect Onboarding won’t ask for the prefilled information during account onboarding. You can prefill any information on the account.
pub fn create(client: &Client, params: CreateAccount<'_>) -> Response<Account> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/accounts", &params)
}

/// Retrieves the details of an account.
pub fn retrieve(client: &Client, id: &AccountId, expand: &[&str]) -> Response<Account> {
client.get_query(&format!("/accounts/{}", id), &Expand { expand })
client.get_query(&format!("/accounts/{}", id), Expand { expand })
}

/// Updates a [connected account](https://stripe.com/docs/connect/accounts) by setting the values of the parameters passed.
Expand All @@ -148,6 +149,7 @@ impl Account {
/// Once you create an [Account Link](https://stripe.com/docs/api/account_links) or [Account Session](https://stripe.com/docs/api/account_sessions), some properties can only be changed or updated for Custom accounts. To update your own account, use the [Dashboard](https://dashboard.stripe.com/settings/account).
/// Refer to our [Connect](https://stripe.com/docs/connect/updating-accounts) documentation to learn more about updating accounts.
pub fn update(client: &Client, id: &AccountId, params: UpdateAccount<'_>) -> Response<Account> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form(&format!("/accounts/{}", id), &params)
}

Expand Down
1 change: 1 addition & 0 deletions src/resources/generated/account_link.rs
Expand Up @@ -28,6 +28,7 @@ pub struct AccountLink {
impl AccountLink {
/// Creates an AccountLink object that includes a single-use Stripe URL that the platform can redirect their user to in order to take them through the Connect Onboarding flow.
pub fn create(client: &Client, params: CreateAccountLink<'_>) -> Response<AccountLink> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/account_links", &params)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/resources/generated/account_session.rs
Expand Up @@ -36,6 +36,7 @@ impl AccountSession {

/// Creates a AccountSession object that includes a single-use token that the platform can use on their front-end to grant client-side API access.
pub fn create(client: &Client, params: CreateAccountSession<'_>) -> Response<AccountSession> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/account_sessions", &params)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/application_fee.rs
Expand Up @@ -70,7 +70,7 @@ impl ApplicationFee {
client: &Client,
params: &ListApplicationFees<'_>,
) -> Response<List<ApplicationFee>> {
client.get_query("/application_fees", &params)
client.get_query("/application_fees", params)
}

/// Retrieves the details of an application fee that your account has collected.
Expand All @@ -81,7 +81,7 @@ impl ApplicationFee {
id: &ApplicationFeeId,
expand: &[&str],
) -> Response<ApplicationFee> {
client.get_query(&format!("/application_fees/{}", id), &Expand { expand })
client.get_query(&format!("/application_fees/{}", id), Expand { expand })
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/balance_transaction.rs
Expand Up @@ -88,7 +88,7 @@ impl BalanceTransaction {
client: &Client,
params: &ListBalanceTransactions<'_>,
) -> Response<List<BalanceTransaction>> {
client.get_query("/balance_transactions", &params)
client.get_query("/balance_transactions", params)
}

/// Retrieves the balance transaction with the given ID.
Expand All @@ -99,7 +99,7 @@ impl BalanceTransaction {
id: &BalanceTransactionId,
expand: &[&str],
) -> Response<BalanceTransaction> {
client.get_query(&format!("/balance_transactions/{}", id), &Expand { expand })
client.get_query(&format!("/balance_transactions/{}", id), Expand { expand })
}
}

Expand Down
1 change: 1 addition & 0 deletions src/resources/generated/billing_portal_session.rs
Expand Up @@ -59,6 +59,7 @@ impl BillingPortalSession {
client: &Client,
params: CreateBillingPortalSession<'_>,
) -> Response<BillingPortalSession> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/billing_portal/sessions", &params)
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/resources/generated/charge.rs
Expand Up @@ -213,14 +213,15 @@ impl Charge {
///
/// The charges are returned in sorted order, with the most recent charges appearing first.
pub fn list(client: &Client, params: &ListCharges<'_>) -> Response<List<Charge>> {
client.get_query("/charges", &params)
client.get_query("/charges", params)
}

/// This method is no longer recommended—use the [Payment Intents API](https://stripe.com/docs/api/payment_intents)
/// to initiate a new payment instead.
///
/// Confirmation of the PaymentIntent creates the `Charge` object used to request payment.
pub fn create(client: &Client, params: CreateCharge<'_>) -> Response<Charge> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/charges", &params)
}

Expand All @@ -229,13 +230,14 @@ impl Charge {
/// Supply the unique charge ID that was returned from your previous request, and Stripe will return the corresponding charge information.
/// The same information is returned when creating or refunding the charge.
pub fn retrieve(client: &Client, id: &ChargeId, expand: &[&str]) -> Response<Charge> {
client.get_query(&format!("/charges/{}", id), &Expand { expand })
client.get_query(&format!("/charges/{}", id), Expand { expand })
}

/// Updates the specified charge by setting the values of the parameters passed.
///
/// Any parameters not provided will be left unchanged.
pub fn update(client: &Client, id: &ChargeId, params: UpdateCharge<'_>) -> Response<Charge> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form(&format!("/charges/{}", id), &params)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/resources/generated/checkout_session.rs
Expand Up @@ -235,11 +235,12 @@ impl CheckoutSession {
client: &Client,
params: &ListCheckoutSessions<'_>,
) -> Response<List<CheckoutSession>> {
client.get_query("/checkout/sessions", &params)
client.get_query("/checkout/sessions", params)
}

/// Creates a Session object.
pub fn create(client: &Client, params: CreateCheckoutSession<'_>) -> Response<CheckoutSession> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/checkout/sessions", &params)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/country_spec.rs
Expand Up @@ -45,13 +45,13 @@ impl CountrySpec {

/// Lists all Country Spec objects available in the API.
pub fn list(client: &Client, params: &ListCountrySpecs<'_>) -> Response<List<CountrySpec>> {
client.get_query("/country_specs", &params)
client.get_query("/country_specs", params)
}


/// Returns a Country Spec for a given Country code.
pub fn retrieve(client: &Client, id: &CountrySpecId, expand: &[&str]) -> Response<CountrySpec> {
client.get_query(&format!("/country_specs/{}", id), &Expand { expand })
client.get_query(&format!("/country_specs/{}", id), Expand { expand })
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/resources/generated/coupon.rs
Expand Up @@ -98,7 +98,7 @@ pub struct Coupon {
impl Coupon {
/// Returns a list of your coupons.
pub fn list(client: &Client, params: &ListCoupons<'_>) -> Response<List<Coupon>> {
client.get_query("/coupons", &params)
client.get_query("/coupons", params)
}

/// You can create coupons easily via the [coupon management](https://dashboard.stripe.com/coupons) page of the Stripe dashboard.
Expand All @@ -107,18 +107,20 @@ impl Coupon {
/// If you set an `amount_off`, that amount will be subtracted from any invoice’s subtotal.
/// For example, an invoice with a subtotal of $100 will have a final total of $0 if a coupon with an `amount_off` of 20000 is applied to it and an invoice with a subtotal of $300 will have a final total of $100 if a coupon with an `amount_off` of 20000 is applied to it.
pub fn create(client: &Client, params: CreateCoupon<'_>) -> Response<Coupon> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/coupons", &params)
}

/// Retrieves the coupon with the given ID.
pub fn retrieve(client: &Client, id: &CouponId, expand: &[&str]) -> Response<Coupon> {
client.get_query(&format!("/coupons/{}", id), &Expand { expand })
client.get_query(&format!("/coupons/{}", id), Expand { expand })
}

/// Updates the metadata of a coupon.
///
/// Other coupon details (currency, duration, amount_off) are, by design, not editable.
pub fn update(client: &Client, id: &CouponId, params: UpdateCoupon<'_>) -> Response<Coupon> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form(&format!("/coupons/{}", id), &params)
}

Expand Down

0 comments on commit 9c5909c

Please sign in to comment.