Skip to content

Commit

Permalink
Merge pull request #612 from lasantosr/feature/keep-unknown-variants
Browse files Browse the repository at this point in the history
feat(next): keep original string on unknown variants
  • Loading branch information
mzeitlin11 authored Nov 2, 2024
2 parents 1af8bc9 + feb39af commit 40caf23
Show file tree
Hide file tree
Showing 68 changed files with 792 additions and 765 deletions.
8 changes: 4 additions & 4 deletions async-stripe-webhook/src/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Webhook {
account: base_evt.account,
api_version: base_evt
.api_version
.map(|s| ApiVersion::from_str(&s).unwrap_or(ApiVersion::Unknown)),
.map(|s| ApiVersion::from_str(&s).unwrap_or(ApiVersion::Unknown(s))),
created: base_evt.created,
data: EventData {
object: event_obj,
Expand Down Expand Up @@ -230,7 +230,7 @@ mod tests {
format!("t={timestamp},v1={v1}")
}

fn mock_webhook_event(event_type: EventType, data: Value) -> Value {
fn mock_webhook_event(event_type: &EventType, data: Value) -> Value {
json!({
"id": "evt_123",
"object": "event",
Expand All @@ -253,7 +253,7 @@ mod tests {
#[track_caller]
fn parse_mock_webhook_event(event_type: EventType, data: Value) -> EventObject {
let now = Utc::now().timestamp();
let payload = mock_webhook_event(event_type, data).to_string();
let payload = mock_webhook_event(&event_type, data).to_string();
let sig = get_mock_stripe_sig(&payload, now);

let webhook = Webhook { current_timestamp: now };
Expand Down Expand Up @@ -283,7 +283,7 @@ mod tests {
"proration": false,
"quantity": 3
});
let payload = mock_webhook_event(EventType::InvoiceitemCreated, object);
let payload = mock_webhook_event(&EventType::InvoiceitemCreated, object);
let event_timestamp = 1533204620;
let signature = format!("t={event_timestamp},v1=5a81ebe328da1df19581cbc6c7377920947ffd30b56eebcc7ba9a6938a090965,v0=63f3a72374a733066c4be69ed7f8e5ac85c22c9f0a6a612ab9a025a9e4ee7eef");

Expand Down
7 changes: 6 additions & 1 deletion async-stripe/tests/it/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@ async fn user_error_transfers() {
// NB: `Unknown` here because the error code reported in the issue is not
// present in the OpenAPI spec. Reporting unknown instead of an error seems
// better regardless so that stripe adding new variants is not a breaking change
assert_eq!(err.code, Some(ApiErrorsCode::Unknown));
assert_eq!(
err.code,
Some(ApiErrorsCode::Unknown(String::from(
"insufficient_capabilities_for_transfer"
)))
);
}
_ => panic!("Expected stripe error, got {:?}", res),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const _: () = {
self.flow.take(),
self.id.take(),
self.livemode,
self.locale,
self.locale.take(),
self.on_behalf_of.take(),
self.return_url.take(),
self.url.take(),
Expand Down Expand Up @@ -239,7 +239,7 @@ impl stripe_types::Object for BillingPortalSession {
}
}
stripe_types::def_id!(BillingPortalSessionId);
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum BillingPortalSessionLocale {
Auto,
Expand Down Expand Up @@ -290,10 +290,10 @@ pub enum BillingPortalSessionLocale {
ZhMinusHk,
ZhMinusTw,
/// An unrecognized value from Stripe. Should not be used as a request parameter.
Unknown,
Unknown(String),
}
impl BillingPortalSessionLocale {
pub fn as_str(self) -> &'static str {
pub fn as_str(&self) -> &str {
use BillingPortalSessionLocale::*;
match self {
Auto => "auto",
Expand Down Expand Up @@ -343,7 +343,7 @@ impl BillingPortalSessionLocale {
Zh => "zh",
ZhMinusHk => "zh-HK",
ZhMinusTw => "zh-TW",
Unknown => "unknown",
Unknown(v) => v,
}
}
}
Expand Down Expand Up @@ -400,7 +400,7 @@ impl std::str::FromStr for BillingPortalSessionLocale {
"zh" => Ok(Zh),
"zh-HK" => Ok(ZhMinusHk),
"zh-TW" => Ok(ZhMinusTw),
_ => Ok(Self::Unknown),
v => Ok(Unknown(v.to_owned())),
}
}
}
Expand Down
50 changes: 25 additions & 25 deletions generated/async-stripe-billing/src/invoice/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ impl UpcomingInvoiceCustomerDetailsTaxIds {
}
}
/// Type of the tax ID, one of `ad_nrt`, `ae_trn`, `ar_cuit`, `au_abn`, `au_arn`, `bg_uic`, `bh_vat`, `bo_tin`, `br_cnpj`, `br_cpf`, `ca_bn`, `ca_gst_hst`, `ca_pst_bc`, `ca_pst_mb`, `ca_pst_sk`, `ca_qst`, `ch_vat`, `cl_tin`, `cn_tin`, `co_nit`, `cr_tin`, `do_rcn`, `ec_ruc`, `eg_tin`, `es_cif`, `eu_oss_vat`, `eu_vat`, `gb_vat`, `ge_vat`, `hk_br`, `hu_tin`, `id_npwp`, `il_vat`, `in_gst`, `is_vat`, `jp_cn`, `jp_rn`, `jp_trn`, `ke_pin`, `kr_brn`, `kz_bin`, `li_uid`, `mx_rfc`, `my_frp`, `my_itn`, `my_sst`, `ng_tin`, `no_vat`, `no_voec`, `nz_gst`, `om_vat`, `pe_ruc`, `ph_tin`, `ro_tin`, `rs_pib`, `ru_inn`, `ru_kpp`, `sa_vat`, `sg_gst`, `sg_uen`, `si_tin`, `sv_nit`, `th_vat`, `tr_tin`, `tw_vat`, `ua_vat`, `us_ein`, `uy_ruc`, `ve_rif`, `vn_tin`, or `za_vat`.
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum UpcomingInvoiceCustomerDetailsTaxIdsType {
AdNrt,
Expand Down Expand Up @@ -678,10 +678,10 @@ pub enum UpcomingInvoiceCustomerDetailsTaxIdsType {
VnTin,
ZaVat,
/// An unrecognized value from Stripe. Should not be used as a request parameter.
Unknown,
Unknown(String),
}
impl UpcomingInvoiceCustomerDetailsTaxIdsType {
pub fn as_str(self) -> &'static str {
pub fn as_str(&self) -> &str {
use UpcomingInvoiceCustomerDetailsTaxIdsType::*;
match self {
AdNrt => "ad_nrt",
Expand Down Expand Up @@ -755,7 +755,7 @@ impl UpcomingInvoiceCustomerDetailsTaxIdsType {
VeRif => "ve_rif",
VnTin => "vn_tin",
ZaVat => "za_vat",
Unknown => "unknown",
Unknown(v) => v,
}
}
}
Expand Down Expand Up @@ -836,7 +836,7 @@ impl std::str::FromStr for UpcomingInvoiceCustomerDetailsTaxIdsType {
"ve_rif" => Ok(VeRif),
"vn_tin" => Ok(VnTin),
"za_vat" => Ok(ZaVat),
_ => Ok(Self::Unknown),
v => Ok(Unknown(v.to_owned())),
}
}
}
Expand Down Expand Up @@ -3620,7 +3620,7 @@ impl UpcomingLinesInvoiceCustomerDetailsTaxIds {
}
}
/// Type of the tax ID, one of `ad_nrt`, `ae_trn`, `ar_cuit`, `au_abn`, `au_arn`, `bg_uic`, `bh_vat`, `bo_tin`, `br_cnpj`, `br_cpf`, `ca_bn`, `ca_gst_hst`, `ca_pst_bc`, `ca_pst_mb`, `ca_pst_sk`, `ca_qst`, `ch_vat`, `cl_tin`, `cn_tin`, `co_nit`, `cr_tin`, `do_rcn`, `ec_ruc`, `eg_tin`, `es_cif`, `eu_oss_vat`, `eu_vat`, `gb_vat`, `ge_vat`, `hk_br`, `hu_tin`, `id_npwp`, `il_vat`, `in_gst`, `is_vat`, `jp_cn`, `jp_rn`, `jp_trn`, `ke_pin`, `kr_brn`, `kz_bin`, `li_uid`, `mx_rfc`, `my_frp`, `my_itn`, `my_sst`, `ng_tin`, `no_vat`, `no_voec`, `nz_gst`, `om_vat`, `pe_ruc`, `ph_tin`, `ro_tin`, `rs_pib`, `ru_inn`, `ru_kpp`, `sa_vat`, `sg_gst`, `sg_uen`, `si_tin`, `sv_nit`, `th_vat`, `tr_tin`, `tw_vat`, `ua_vat`, `us_ein`, `uy_ruc`, `ve_rif`, `vn_tin`, or `za_vat`.
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum UpcomingLinesInvoiceCustomerDetailsTaxIdsType {
AdNrt,
Expand Down Expand Up @@ -3695,10 +3695,10 @@ pub enum UpcomingLinesInvoiceCustomerDetailsTaxIdsType {
VnTin,
ZaVat,
/// An unrecognized value from Stripe. Should not be used as a request parameter.
Unknown,
Unknown(String),
}
impl UpcomingLinesInvoiceCustomerDetailsTaxIdsType {
pub fn as_str(self) -> &'static str {
pub fn as_str(&self) -> &str {
use UpcomingLinesInvoiceCustomerDetailsTaxIdsType::*;
match self {
AdNrt => "ad_nrt",
Expand Down Expand Up @@ -3772,7 +3772,7 @@ impl UpcomingLinesInvoiceCustomerDetailsTaxIdsType {
VeRif => "ve_rif",
VnTin => "vn_tin",
ZaVat => "za_vat",
Unknown => "unknown",
Unknown(v) => v,
}
}
}
Expand Down Expand Up @@ -3853,7 +3853,7 @@ impl std::str::FromStr for UpcomingLinesInvoiceCustomerDetailsTaxIdsType {
"ve_rif" => Ok(VeRif),
"vn_tin" => Ok(VnTin),
"za_vat" => Ok(ZaVat),
_ => Ok(Self::Unknown),
v => Ok(Unknown(v.to_owned())),
}
}
}
Expand Down Expand Up @@ -7540,7 +7540,7 @@ impl<'de> serde::Deserialize<'de>
/// The list of payment method types (e.g.
/// card) to provide to the invoice’s PaymentIntent.
/// If not set, Stripe attempts to automatically determine the types to use by looking at the invoice’s default payment method, the subscription’s default payment method, the customer’s default payment method, and your [invoice template settings](https://dashboard.stripe.com/settings/billing/invoice).
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum CreateInvoicePaymentSettingsPaymentMethodTypes {
AchCreditTransfer,
Expand Down Expand Up @@ -7572,10 +7572,10 @@ pub enum CreateInvoicePaymentSettingsPaymentMethodTypes {
UsBankAccount,
WechatPay,
/// An unrecognized value from Stripe. Should not be used as a request parameter.
Unknown,
Unknown(String),
}
impl CreateInvoicePaymentSettingsPaymentMethodTypes {
pub fn as_str(self) -> &'static str {
pub fn as_str(&self) -> &str {
use CreateInvoicePaymentSettingsPaymentMethodTypes::*;
match self {
AchCreditTransfer => "ach_credit_transfer",
Expand Down Expand Up @@ -7606,7 +7606,7 @@ impl CreateInvoicePaymentSettingsPaymentMethodTypes {
Sofort => "sofort",
UsBankAccount => "us_bank_account",
WechatPay => "wechat_pay",
Unknown => "unknown",
Unknown(v) => v,
}
}
}
Expand Down Expand Up @@ -7644,7 +7644,7 @@ impl std::str::FromStr for CreateInvoicePaymentSettingsPaymentMethodTypes {
"sofort" => Ok(Sofort),
"us_bank_account" => Ok(UsBankAccount),
"wechat_pay" => Ok(WechatPay),
_ => Ok(Self::Unknown),
v => Ok(Unknown(v.to_owned())),
}
}
}
Expand Down Expand Up @@ -9715,7 +9715,7 @@ impl<'de> serde::Deserialize<'de>
/// The list of payment method types (e.g.
/// card) to provide to the invoice’s PaymentIntent.
/// If not set, Stripe attempts to automatically determine the types to use by looking at the invoice’s default payment method, the subscription’s default payment method, the customer’s default payment method, and your [invoice template settings](https://dashboard.stripe.com/settings/billing/invoice).
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum UpdateInvoicePaymentSettingsPaymentMethodTypes {
AchCreditTransfer,
Expand Down Expand Up @@ -9747,10 +9747,10 @@ pub enum UpdateInvoicePaymentSettingsPaymentMethodTypes {
UsBankAccount,
WechatPay,
/// An unrecognized value from Stripe. Should not be used as a request parameter.
Unknown,
Unknown(String),
}
impl UpdateInvoicePaymentSettingsPaymentMethodTypes {
pub fn as_str(self) -> &'static str {
pub fn as_str(&self) -> &str {
use UpdateInvoicePaymentSettingsPaymentMethodTypes::*;
match self {
AchCreditTransfer => "ach_credit_transfer",
Expand Down Expand Up @@ -9781,7 +9781,7 @@ impl UpdateInvoicePaymentSettingsPaymentMethodTypes {
Sofort => "sofort",
UsBankAccount => "us_bank_account",
WechatPay => "wechat_pay",
Unknown => "unknown",
Unknown(v) => v,
}
}
}
Expand Down Expand Up @@ -9819,7 +9819,7 @@ impl std::str::FromStr for UpdateInvoicePaymentSettingsPaymentMethodTypes {
"sofort" => Ok(Sofort),
"us_bank_account" => Ok(UsBankAccount),
"wechat_pay" => Ok(WechatPay),
_ => Ok(Self::Unknown),
v => Ok(Unknown(v.to_owned())),
}
}
}
Expand Down Expand Up @@ -11324,7 +11324,7 @@ impl CreatePreviewInvoiceCustomerDetailsTaxIds {
}
}
/// Type of the tax ID, one of `ad_nrt`, `ae_trn`, `ar_cuit`, `au_abn`, `au_arn`, `bg_uic`, `bh_vat`, `bo_tin`, `br_cnpj`, `br_cpf`, `ca_bn`, `ca_gst_hst`, `ca_pst_bc`, `ca_pst_mb`, `ca_pst_sk`, `ca_qst`, `ch_vat`, `cl_tin`, `cn_tin`, `co_nit`, `cr_tin`, `do_rcn`, `ec_ruc`, `eg_tin`, `es_cif`, `eu_oss_vat`, `eu_vat`, `gb_vat`, `ge_vat`, `hk_br`, `hu_tin`, `id_npwp`, `il_vat`, `in_gst`, `is_vat`, `jp_cn`, `jp_rn`, `jp_trn`, `ke_pin`, `kr_brn`, `kz_bin`, `li_uid`, `mx_rfc`, `my_frp`, `my_itn`, `my_sst`, `ng_tin`, `no_vat`, `no_voec`, `nz_gst`, `om_vat`, `pe_ruc`, `ph_tin`, `ro_tin`, `rs_pib`, `ru_inn`, `ru_kpp`, `sa_vat`, `sg_gst`, `sg_uen`, `si_tin`, `sv_nit`, `th_vat`, `tr_tin`, `tw_vat`, `ua_vat`, `us_ein`, `uy_ruc`, `ve_rif`, `vn_tin`, or `za_vat`.
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum CreatePreviewInvoiceCustomerDetailsTaxIdsType {
AdNrt,
Expand Down Expand Up @@ -11399,10 +11399,10 @@ pub enum CreatePreviewInvoiceCustomerDetailsTaxIdsType {
VnTin,
ZaVat,
/// An unrecognized value from Stripe. Should not be used as a request parameter.
Unknown,
Unknown(String),
}
impl CreatePreviewInvoiceCustomerDetailsTaxIdsType {
pub fn as_str(self) -> &'static str {
pub fn as_str(&self) -> &str {
use CreatePreviewInvoiceCustomerDetailsTaxIdsType::*;
match self {
AdNrt => "ad_nrt",
Expand Down Expand Up @@ -11476,7 +11476,7 @@ impl CreatePreviewInvoiceCustomerDetailsTaxIdsType {
VeRif => "ve_rif",
VnTin => "vn_tin",
ZaVat => "za_vat",
Unknown => "unknown",
Unknown(v) => v,
}
}
}
Expand Down Expand Up @@ -11557,7 +11557,7 @@ impl std::str::FromStr for CreatePreviewInvoiceCustomerDetailsTaxIdsType {
"ve_rif" => Ok(VeRif),
"vn_tin" => Ok(VnTin),
"za_vat" => Ok(ZaVat),
_ => Ok(Self::Unknown),
v => Ok(Unknown(v.to_owned())),
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions generated/async-stripe-billing/src/subscription/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ impl<'de> serde::Deserialize<'de>
/// The list of payment method types (e.g.
/// card) to provide to the invoice’s PaymentIntent.
/// If not set, Stripe attempts to automatically determine the types to use by looking at the invoice’s default payment method, the subscription’s default payment method, the customer’s default payment method, and your [invoice template settings](https://dashboard.stripe.com/settings/billing/invoice).
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum CreateSubscriptionPaymentSettingsPaymentMethodTypes {
AchCreditTransfer,
Expand Down Expand Up @@ -2311,10 +2311,10 @@ pub enum CreateSubscriptionPaymentSettingsPaymentMethodTypes {
UsBankAccount,
WechatPay,
/// An unrecognized value from Stripe. Should not be used as a request parameter.
Unknown,
Unknown(String),
}
impl CreateSubscriptionPaymentSettingsPaymentMethodTypes {
pub fn as_str(self) -> &'static str {
pub fn as_str(&self) -> &str {
use CreateSubscriptionPaymentSettingsPaymentMethodTypes::*;
match self {
AchCreditTransfer => "ach_credit_transfer",
Expand Down Expand Up @@ -2345,7 +2345,7 @@ impl CreateSubscriptionPaymentSettingsPaymentMethodTypes {
Sofort => "sofort",
UsBankAccount => "us_bank_account",
WechatPay => "wechat_pay",
Unknown => "unknown",
Unknown(v) => v,
}
}
}
Expand Down Expand Up @@ -2383,7 +2383,7 @@ impl std::str::FromStr for CreateSubscriptionPaymentSettingsPaymentMethodTypes {
"sofort" => Ok(Sofort),
"us_bank_account" => Ok(UsBankAccount),
"wechat_pay" => Ok(WechatPay),
_ => Ok(Self::Unknown),
v => Ok(Unknown(v.to_owned())),
}
}
}
Expand Down Expand Up @@ -5084,7 +5084,7 @@ impl<'de> serde::Deserialize<'de>
/// The list of payment method types (e.g.
/// card) to provide to the invoice’s PaymentIntent.
/// If not set, Stripe attempts to automatically determine the types to use by looking at the invoice’s default payment method, the subscription’s default payment method, the customer’s default payment method, and your [invoice template settings](https://dashboard.stripe.com/settings/billing/invoice).
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum UpdateSubscriptionPaymentSettingsPaymentMethodTypes {
AchCreditTransfer,
Expand Down Expand Up @@ -5116,10 +5116,10 @@ pub enum UpdateSubscriptionPaymentSettingsPaymentMethodTypes {
UsBankAccount,
WechatPay,
/// An unrecognized value from Stripe. Should not be used as a request parameter.
Unknown,
Unknown(String),
}
impl UpdateSubscriptionPaymentSettingsPaymentMethodTypes {
pub fn as_str(self) -> &'static str {
pub fn as_str(&self) -> &str {
use UpdateSubscriptionPaymentSettingsPaymentMethodTypes::*;
match self {
AchCreditTransfer => "ach_credit_transfer",
Expand Down Expand Up @@ -5150,7 +5150,7 @@ impl UpdateSubscriptionPaymentSettingsPaymentMethodTypes {
Sofort => "sofort",
UsBankAccount => "us_bank_account",
WechatPay => "wechat_pay",
Unknown => "unknown",
Unknown(v) => v,
}
}
}
Expand Down Expand Up @@ -5188,7 +5188,7 @@ impl std::str::FromStr for UpdateSubscriptionPaymentSettingsPaymentMethodTypes {
"sofort" => Ok(Sofort),
"us_bank_account" => Ok(UsBankAccount),
"wechat_pay" => Ok(WechatPay),
_ => Ok(Self::Unknown),
v => Ok(Unknown(v.to_owned())),
}
}
}
Expand Down
Loading

0 comments on commit 40caf23

Please sign in to comment.