Skip to content

Commit

Permalink
Add back AsCursor trait and clean up Expandable removed id method
Browse files Browse the repository at this point in the history
  • Loading branch information
mzeitlin11 committed Dec 17, 2023
1 parent 9930853 commit ccb9570
Show file tree
Hide file tree
Showing 142 changed files with 369 additions and 318 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ implementations. Please let us know if such implementations are useful, and they
they stay up to date, preventing errors error deserialization errors like (https://github.com/arlyon/async-stripe/issues/381) and (https://github.com/arlyon/async-stripe/issues/384)
- The main user-facing change will be `StripeError::Stripe(RequestError)` -> `StripeError::Stripe(ApiErrors, StatusCode)` since the autogenerated `ApiErrors`
does not include the status code.
- The `id` method on `Expandable<T>` now returns a reference: `&T::Id`. All id types implement `Clone` so
to achieve the previous behavior, use `.id().clone()`.

Since most of these changes are related to code generation, it is likely there are some
breaking changes we missed here. If so, please open an issue (especially for changes that degrade library ergonomics).
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ edition = "2021"
[workspace.dependencies]
serde = {version = ">=1.0.79", features = ["derive"] } # we use `serde(other)` which was introduced in 1.0.79
http-types = { version = "2.12.0", default-features = false }
smol_str = "0.2.0"
smol_str = { version = "0.2.0", features = ["serde"] }
serde_json = "1.0"
7 changes: 4 additions & 3 deletions async-stripe/src/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(clippy::missing_errors_doc)]
use serde::de::DeserializeOwned;
use serde::Serialize;
use stripe_types::{List, Object};
use stripe_types::{AsCursorOpt, List, Object};

use crate::{Client, Response};

Expand All @@ -27,6 +27,7 @@ pub trait PaginationExt<T> {
impl<T> PaginationExt<T> for List<T>
where
T: Object + DeserializeOwned + Send + Sync + 'static,
T::Id: ToString,
{
fn into_paginator(self) -> ListPaginator<T> {
let mut paginator = ListPaginator {
Expand All @@ -37,7 +38,7 @@ where
total_count: self.total_count,
params: Default::default(),
};
if let Some(curr_cursor) = paginator.data.last().and_then(|t| t.id()) {
if let Some(curr_cursor) = paginator.data.last().and_then(|t| t.id().as_cursor_opt()) {
paginator.update_cursor(curr_cursor.to_string());
}
paginator
Expand Down Expand Up @@ -147,7 +148,7 @@ where
fn update_with_new_data(&mut self, list: List<T>) {
self.has_more = list.has_more;
self.total_count = list.total_count;
if let Some(new_cursor) = list.data.last().and_then(|l| l.id()) {
if let Some(new_cursor) = list.data.last().and_then(|l| l.id().as_cursor_opt()) {
self.update_cursor(new_cursor.to_string());
} else {
self.has_more = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub struct BillingPortalConfiguration {
}
impl stripe_types::Object for BillingPortalConfiguration {
type Id = stripe_billing::billing_portal_configuration::BillingPortalConfigurationId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(BillingPortalConfigurationId, "bpc_");
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_billing/src/billing_portal_session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ impl<'de> serde::Deserialize<'de> for BillingPortalSessionLocale {
}
impl stripe_types::Object for BillingPortalSession {
type Id = stripe_billing::billing_portal_session::BillingPortalSessionId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(BillingPortalSessionId, "bps_");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub quantity: Option<u64>,
}
impl stripe_types::Object for PortalFlowsSubscriptionUpdateConfirmItem {
type Id = Option<stripe_billing::portal_flows_subscription_update_confirm_item::PortalFlowsSubscriptionUpdateConfirmItemId>;
fn id(&self) -> Option<&str> {
self.id.as_deref()
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(PortalFlowsSubscriptionUpdateConfirmItemId);
4 changes: 2 additions & 2 deletions generated/stripe_billing/src/usage_record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub struct UsageRecord {
}
impl stripe_types::Object for UsageRecord {
type Id = stripe_billing::usage_record::UsageRecordId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(UsageRecordId, "mbur_");
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_checkout/src/checkout_session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,8 @@ impl<'de> serde::Deserialize<'de> for CheckoutSessionUiMode {
}
impl stripe_types::Object for CheckoutSession {
type Id = stripe_checkout::checkout_session::CheckoutSessionId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(CheckoutSessionId, "cs_");
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_connect/src/apps_secret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub struct AppsSecret {
}
impl stripe_types::Object for AppsSecret {
type Id = stripe_connect::apps_secret::AppsSecretId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(AppsSecretId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_connect/src/country_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub struct CountrySpec {
}
impl stripe_types::Object for CountrySpec {
type Id = stripe_connect::country_spec::CountrySpecId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(CountrySpecId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_core/src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub struct Token {
}
impl stripe_types::Object for Token {
type Id = stripe_core::token::TokenId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(TokenId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_fraud/src/deleted_radar_value_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct DeletedRadarValueList {
}
impl stripe_types::Object for DeletedRadarValueList {
type Id = stripe_fraud::radar_value_list::RadarValueListId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct DeletedRadarValueListItem {
}
impl stripe_types::Object for DeletedRadarValueListItem {
type Id = stripe_fraud::radar_value_list_item::RadarValueListItemId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
4 changes: 2 additions & 2 deletions generated/stripe_fraud/src/radar_early_fraud_warning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub struct RadarEarlyFraudWarning {
}
impl stripe_types::Object for RadarEarlyFraudWarning {
type Id = stripe_fraud::radar_early_fraud_warning::RadarEarlyFraudWarningId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(RadarEarlyFraudWarningId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_fraud/src/radar_value_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ impl<'de> serde::Deserialize<'de> for RadarValueListItemType {
}
impl stripe_types::Object for RadarValueList {
type Id = stripe_fraud::radar_value_list::RadarValueListId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(RadarValueListId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_fraud/src/radar_value_list_item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct RadarValueListItem {
}
impl stripe_types::Object for RadarValueListItem {
type Id = stripe_fraud::radar_value_list_item::RadarValueListItemId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(RadarValueListItemId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/apple_pay_domain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub struct ApplePayDomain {
}
impl stripe_types::Object for ApplePayDomain {
type Id = stripe_misc::apple_pay_domain::ApplePayDomainId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(ApplePayDomainId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/deleted_apple_pay_domain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct DeletedApplePayDomain {
}
impl stripe_types::Object for DeletedApplePayDomain {
type Id = stripe_misc::apple_pay_domain::ApplePayDomainId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/deleted_webhook_endpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct DeletedWebhookEndpoint {
}
impl stripe_types::Object for DeletedWebhookEndpoint {
type Id = stripe_misc::webhook_endpoint::WebhookEndpointId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/ephemeral_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct EphemeralKey {
}
impl stripe_types::Object for EphemeralKey {
type Id = stripe_misc::ephemeral_key::EphemeralKeyId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(EphemeralKeyId, "ephkey_");
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/exchange_rate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub struct ExchangeRate {
}
impl stripe_types::Object for ExchangeRate {
type Id = stripe_misc::exchange_rate::ExchangeRateId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(ExchangeRateId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ impl<'de> serde::Deserialize<'de> for FinancialConnectionsAccountSupportedPaymen
}
impl stripe_types::Object for FinancialConnectionsAccount {
type Id = stripe_misc::financial_connections_account::FinancialConnectionsAccountId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(FinancialConnectionsAccountId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub struct FinancialConnectionsAccountOwner {
}
impl stripe_types::Object for FinancialConnectionsAccountOwner {
type Id = stripe_misc::financial_connections_account_owner::FinancialConnectionsAccountOwnerId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(FinancialConnectionsAccountOwnerId);
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub owners: stripe_types::List<stripe_misc::FinancialConnectionsAccountOwner>,
}
impl stripe_types::Object for FinancialConnectionsAccountOwnership {
type Id = stripe_misc::financial_connections_account_ownership::FinancialConnectionsAccountOwnershipId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(FinancialConnectionsAccountOwnershipId);
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ impl<'de> serde::Deserialize<'de> for FinancialConnectionsSessionPrefetch {
}
impl stripe_types::Object for FinancialConnectionsSession {
type Id = stripe_misc::financial_connections_session::FinancialConnectionsSessionId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(FinancialConnectionsSessionId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/identity_verification_report/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl<'de> serde::Deserialize<'de> for IdentityVerificationReportType {
}
impl stripe_types::Object for IdentityVerificationReport {
type Id = stripe_misc::identity_verification_report::IdentityVerificationReportId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(IdentityVerificationReportId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ impl<'de> serde::Deserialize<'de> for IdentityVerificationSessionType {
}
impl stripe_types::Object for IdentityVerificationSession {
type Id = stripe_misc::identity_verification_session::IdentityVerificationSessionId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(IdentityVerificationSessionId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/reporting_report_run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub struct ReportingReportRun {
}
impl stripe_types::Object for ReportingReportRun {
type Id = stripe_misc::reporting_report_run::ReportingReportRunId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(ReportingReportRunId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/reporting_report_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub struct ReportingReportType {
}
impl stripe_types::Object for ReportingReportType {
type Id = stripe_misc::reporting_report_type::ReportingReportTypeId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(ReportingReportTypeId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/scheduled_query_run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub struct ScheduledQueryRun {
}
impl stripe_types::Object for ScheduledQueryRun {
type Id = stripe_misc::scheduled_query_run::ScheduledQueryRunId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(ScheduledQueryRunId, "sqr_");
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/tax_calculation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub struct TaxCalculation {
}
impl stripe_types::Object for TaxCalculation {
type Id = Option<stripe_misc::tax_calculation::TaxCalculationId>;
fn id(&self) -> Option<&str> {
self.id.as_deref()
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(TaxCalculationId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/tax_calculation_line_item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ impl<'de> serde::Deserialize<'de> for TaxCalculationLineItemTaxBehavior {
}
impl stripe_types::Object for TaxCalculationLineItem {
type Id = stripe_misc::tax_calculation_line_item::TaxCalculationLineItemId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(TaxCalculationLineItemId);
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/tax_registration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl<'de> serde::Deserialize<'de> for TaxRegistrationStatus {
}
impl stripe_types::Object for TaxRegistration {
type Id = stripe_misc::tax_registration::TaxRegistrationId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(TaxRegistrationId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/tax_transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ impl<'de> serde::Deserialize<'de> for TaxTransactionType {
}
impl stripe_types::Object for TaxTransaction {
type Id = stripe_misc::tax_transaction::TaxTransactionId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(TaxTransactionId);
Expand Down
4 changes: 2 additions & 2 deletions generated/stripe_misc/src/tax_transaction_line_item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ impl<'de> serde::Deserialize<'de> for TaxTransactionLineItemType {
}
impl stripe_types::Object for TaxTransactionLineItem {
type Id = stripe_misc::tax_transaction_line_item::TaxTransactionLineItemId;
fn id(&self) -> Option<&str> {
Some(self.id.as_str())
fn id(&self) -> &Self::Id {
&self.id
}
}
stripe_types::def_id!(TaxTransactionLineItemId);
Loading

0 comments on commit ccb9570

Please sign in to comment.