From 0124c6c206ea7b2eb4a0d1cc06e75a671c268842 Mon Sep 17 00:00:00 2001 From: Luis Alberto Santos Date: Tue, 3 Sep 2024 18:27:06 +0200 Subject: [PATCH 1/2] fix enum serialization --- .../src/invoice/requests.rs | 75 ++++++++++++------- .../async-stripe-billing/src/plan/requests.rs | 7 +- .../src/quote/requests.rs | 6 +- .../src/subscription/requests.rs | 6 +- .../src/subscription_schedule/requests.rs | 20 +++-- .../src/usage_record/requests.rs | 3 +- .../src/account/requests.rs | 6 +- .../src/file_link/requests.rs | 3 +- .../src/payment_intent/requests.rs | 14 ++-- .../src/setup_intent/requests.rs | 4 +- .../async-stripe-core/src/token/requests.rs | 4 +- .../src/tax_registration/requests.rs | 9 ++- .../src/payment_method/requests.rs | 4 +- .../src/price/requests.rs | 9 ++- .../src/product/requests.rs | 3 +- openapi/src/templates/enums.rs | 5 +- tests/tests/it/enums.rs | 7 ++ 17 files changed, 123 insertions(+), 62 deletions(-) diff --git a/generated/async-stripe-billing/src/invoice/requests.rs b/generated/async-stripe-billing/src/invoice/requests.rs index e1706ad56..3863f5d0d 100644 --- a/generated/async-stripe-billing/src/invoice/requests.rs +++ b/generated/async-stripe-billing/src/invoice/requests.rs @@ -1681,10 +1681,11 @@ impl<'de> serde::Deserialize<'de> for UpcomingInvoiceScheduleDetailsPhasesBillin /// The date at which this phase of the subscription schedule ends. /// If set, `iterations` must not be set. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingInvoiceScheduleDetailsPhasesEndDate { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// All invoices will be billed using the specified settings. #[derive(Copy, Clone, Debug, serde::Serialize)] @@ -2095,18 +2096,20 @@ impl<'de> serde::Deserialize<'de> for UpcomingInvoiceScheduleDetailsPhasesProrat /// The date at which this phase of the subscription schedule starts or `now`. /// Must be set on the first phase. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingInvoiceScheduleDetailsPhasesStartDate { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// Sets the phase to trialing from the start date to this date. /// Must be before the phase end date, can not be combined with `trial`. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingInvoiceScheduleDetailsPhasesTrialEnd { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// In cases where the `schedule_details` params update the currently active phase, specifies if and how to prorate at the time of the request. #[derive(Copy, Clone, Eq, PartialEq)] @@ -2175,10 +2178,11 @@ impl<'de> serde::Deserialize<'de> for UpcomingInvoiceScheduleDetailsProrationBeh /// This field has been deprecated and will be removed in a future API version. /// Use `subscription_details.billing_cycle_anchor` instead. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingInvoiceSubscriptionBillingCycleAnchor { Now, Unchanged, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// The subscription creation or modification params to apply as a preview. @@ -2255,10 +2259,11 @@ impl<'a> Default for UpcomingInvoiceSubscriptionDetails<'a> { /// This is used to determine the date of the first full invoice, and, for plans with `month` or `year` intervals, the day of the month for subsequent invoices. /// For existing subscriptions, the value can only be set to `now` or `unchanged`. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingInvoiceSubscriptionDetailsBillingCycleAnchor { Now, Unchanged, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// A list of up to 20 subscription items, each with an attached price. @@ -2630,9 +2635,10 @@ impl<'de> serde::Deserialize<'de> for UpcomingInvoiceSubscriptionDetailsResumeAt /// If provided, the invoice returned will preview updating or creating a subscription with that trial end. /// If set, one of `subscription_details.items` or `subscription` is required. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingInvoiceSubscriptionDetailsTrialEnd { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// A list of up to 20 subscription items, each with an attached price. @@ -3012,9 +3018,10 @@ impl<'de> serde::Deserialize<'de> for UpcomingInvoiceSubscriptionResumeAt { /// This field has been deprecated and will be removed in a future API version. /// Use `subscription_details.trial_end` instead. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingInvoiceSubscriptionTrialEnd { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// At any time, you can preview the upcoming invoice for a customer. @@ -4672,10 +4679,11 @@ impl<'de> serde::Deserialize<'de> for UpcomingLinesInvoiceScheduleDetailsPhasesB /// The date at which this phase of the subscription schedule ends. /// If set, `iterations` must not be set. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingLinesInvoiceScheduleDetailsPhasesEndDate { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// All invoices will be billed using the specified settings. #[derive(Copy, Clone, Debug, serde::Serialize)] @@ -5082,18 +5090,20 @@ impl<'de> serde::Deserialize<'de> for UpcomingLinesInvoiceScheduleDetailsPhasesP /// The date at which this phase of the subscription schedule starts or `now`. /// Must be set on the first phase. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingLinesInvoiceScheduleDetailsPhasesStartDate { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// Sets the phase to trialing from the start date to this date. /// Must be before the phase end date, can not be combined with `trial`. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingLinesInvoiceScheduleDetailsPhasesTrialEnd { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// In cases where the `schedule_details` params update the currently active phase, specifies if and how to prorate at the time of the request. #[derive(Copy, Clone, Eq, PartialEq)] @@ -5162,10 +5172,11 @@ impl<'de> serde::Deserialize<'de> for UpcomingLinesInvoiceScheduleDetailsProrati /// This field has been deprecated and will be removed in a future API version. /// Use `subscription_details.billing_cycle_anchor` instead. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingLinesInvoiceSubscriptionBillingCycleAnchor { Now, Unchanged, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// The subscription creation or modification params to apply as a preview. @@ -5242,10 +5253,11 @@ impl<'a> Default for UpcomingLinesInvoiceSubscriptionDetails<'a> { /// This is used to determine the date of the first full invoice, and, for plans with `month` or `year` intervals, the day of the month for subsequent invoices. /// For existing subscriptions, the value can only be set to `now` or `unchanged`. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingLinesInvoiceSubscriptionDetailsBillingCycleAnchor { Now, Unchanged, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// A list of up to 20 subscription items, each with an attached price. @@ -5617,9 +5629,10 @@ impl<'de> serde::Deserialize<'de> for UpcomingLinesInvoiceSubscriptionDetailsRes /// If provided, the invoice returned will preview updating or creating a subscription with that trial end. /// If set, one of `subscription_details.items` or `subscription` is required. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingLinesInvoiceSubscriptionDetailsTrialEnd { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// A list of up to 20 subscription items, each with an attached price. @@ -6001,9 +6014,10 @@ impl<'de> serde::Deserialize<'de> for UpcomingLinesInvoiceSubscriptionResumeAt { /// This field has been deprecated and will be removed in a future API version. /// Use `subscription_details.trial_end` instead. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpcomingLinesInvoiceSubscriptionTrialEnd { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// When retrieving an upcoming invoice, you’ll get a **lines** property containing the total count of line items and the first handful of those items. @@ -12328,10 +12342,11 @@ impl<'de> serde::Deserialize<'de> for CreatePreviewInvoiceScheduleDetailsPhasesB /// The date at which this phase of the subscription schedule ends. /// If set, `iterations` must not be set. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePreviewInvoiceScheduleDetailsPhasesEndDate { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// All invoices will be billed using the specified settings. #[derive(Copy, Clone, Debug, serde::Serialize)] @@ -12738,18 +12753,20 @@ impl<'de> serde::Deserialize<'de> for CreatePreviewInvoiceScheduleDetailsPhasesP /// The date at which this phase of the subscription schedule starts or `now`. /// Must be set on the first phase. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePreviewInvoiceScheduleDetailsPhasesStartDate { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// Sets the phase to trialing from the start date to this date. /// Must be before the phase end date, can not be combined with `trial`. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePreviewInvoiceScheduleDetailsPhasesTrialEnd { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// In cases where the `schedule_details` params update the currently active phase, specifies if and how to prorate at the time of the request. #[derive(Copy, Clone, Eq, PartialEq)] @@ -12886,10 +12903,11 @@ impl<'a> Default for CreatePreviewInvoiceSubscriptionDetails<'a> { /// This is used to determine the date of the first full invoice, and, for plans with `month` or `year` intervals, the day of the month for subsequent invoices. /// For existing subscriptions, the value can only be set to `now` or `unchanged`. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePreviewInvoiceSubscriptionDetailsBillingCycleAnchor { Now, Unchanged, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// A list of up to 20 subscription items, each with an attached price. @@ -13261,9 +13279,10 @@ impl<'de> serde::Deserialize<'de> for CreatePreviewInvoiceSubscriptionDetailsRes /// If provided, the invoice returned will preview updating or creating a subscription with that trial end. /// If set, one of `subscription_details.items` or `subscription` is required. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePreviewInvoiceSubscriptionDetailsTrialEnd { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// At any time, you can preview the upcoming invoice for a customer. diff --git a/generated/async-stripe-billing/src/plan/requests.rs b/generated/async-stripe-billing/src/plan/requests.rs index b84bcb3f3..82f79bba3 100644 --- a/generated/async-stripe-billing/src/plan/requests.rs +++ b/generated/async-stripe-billing/src/plan/requests.rs @@ -275,9 +275,11 @@ impl<'a> CreatePlanBuilder<'a> { } } #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePlanProduct<'a> { + #[serde(untagged)] InlineProductParams(CreatePlanInlineProductParams<'a>), + #[serde(untagged)] Id(&'a str), } #[derive(Copy, Clone, Debug, serde::Serialize)] @@ -366,9 +368,10 @@ impl<'a> CreatePlanTiers<'a> { /// The lower bound of a tier is the upper bound of the previous tier adding one. /// Use `inf` to define a fallback tier. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePlanTiersUpTo { Inf, + #[serde(untagged)] I64(i64), } /// Apply a transformation to the reported usage or set quantity before computing the billed price. diff --git a/generated/async-stripe-billing/src/quote/requests.rs b/generated/async-stripe-billing/src/quote/requests.rs index 57fb04e54..f66d16bd9 100644 --- a/generated/async-stripe-billing/src/quote/requests.rs +++ b/generated/async-stripe-billing/src/quote/requests.rs @@ -883,9 +883,10 @@ impl<'a> Default for CreateQuoteSubscriptionData<'a> { /// The special value `current_period_end` can be provided to update a subscription at the end of its current period. /// The `effective_date` is ignored if it is in the past when the quote is accepted. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreateQuoteSubscriptionDataEffectiveDate { CurrentPeriodEnd, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// A quote models prices and services for a customer. @@ -1563,9 +1564,10 @@ impl<'a> Default for UpdateQuoteSubscriptionData<'a> { /// The special value `current_period_end` can be provided to update a subscription at the end of its current period. /// The `effective_date` is ignored if it is in the past when the quote is accepted. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpdateQuoteSubscriptionDataEffectiveDate { CurrentPeriodEnd, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// A quote models prices and services for a customer. diff --git a/generated/async-stripe-billing/src/subscription/requests.rs b/generated/async-stripe-billing/src/subscription/requests.rs index 62cc293a8..4f17fdcac 100644 --- a/generated/async-stripe-billing/src/subscription/requests.rs +++ b/generated/async-stripe-billing/src/subscription/requests.rs @@ -2602,9 +2602,10 @@ impl<'de> serde::Deserialize<'de> for CreateSubscriptionProrationBehavior { /// Can be at most two years from `billing_cycle_anchor`. /// See [Using trial periods on subscriptions](https://stripe.com/docs/billing/subscriptions/trials) to learn more. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreateSubscriptionTrialEnd { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// Settings related to subscription trials. @@ -5380,9 +5381,10 @@ impl<'de> serde::Deserialize<'de> for UpdateSubscriptionProrationBehavior { /// The special value `now` can be provided to end the customer's trial immediately. /// Can be at most two years from `billing_cycle_anchor`. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpdateSubscriptionTrialEnd { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// Settings related to subscription trials. diff --git a/generated/async-stripe-billing/src/subscription_schedule/requests.rs b/generated/async-stripe-billing/src/subscription_schedule/requests.rs index 9c2bde00d..e208618a1 100644 --- a/generated/async-stripe-billing/src/subscription_schedule/requests.rs +++ b/generated/async-stripe-billing/src/subscription_schedule/requests.rs @@ -1474,10 +1474,11 @@ impl<'de> serde::Deserialize<'de> for CreateSubscriptionSchedulePhasesProrationB /// We recommend using `now` so that it starts the subscription immediately. /// You can also use a Unix timestamp to backdate the subscription so that it starts on a past date, or set a future date for the subscription to start on. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreateSubscriptionScheduleStartDate { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// Creates a new subscription schedule object. /// Each customer can have up to 500 active or scheduled subscriptions. @@ -2450,10 +2451,11 @@ impl<'de> serde::Deserialize<'de> for UpdateSubscriptionSchedulePhasesCollection /// The date at which this phase of the subscription schedule ends. /// If set, `iterations` must not be set. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpdateSubscriptionSchedulePhasesEndDate { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// All invoices will be billed using the specified settings. #[derive(Copy, Clone, Debug, serde::Serialize)] @@ -2862,18 +2864,20 @@ impl<'de> serde::Deserialize<'de> for UpdateSubscriptionSchedulePhasesProrationB /// The date at which this phase of the subscription schedule starts or `now`. /// Must be set on the first phase. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpdateSubscriptionSchedulePhasesStartDate { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// Sets the phase to trialing from the start date to this date. /// Must be before the phase end date, can not be combined with `trial`. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpdateSubscriptionSchedulePhasesTrialEnd { - Timestamp(stripe_types::Timestamp), Now, + #[serde(untagged)] + Timestamp(stripe_types::Timestamp), } /// If the update changes the current phase, indicates whether the changes should be prorated. /// The default value is `create_prorations`. diff --git a/generated/async-stripe-billing/src/usage_record/requests.rs b/generated/async-stripe-billing/src/usage_record/requests.rs index 8ed83b2c5..f06f4a2d7 100644 --- a/generated/async-stripe-billing/src/usage_record/requests.rs +++ b/generated/async-stripe-billing/src/usage_record/requests.rs @@ -81,9 +81,10 @@ impl<'de> serde::Deserialize<'de> for CreateSubscriptionItemUsageRecordAction { /// When passing `"now"`, Stripe records usage for the current time. /// Default is `"now"` if a value is not provided. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreateSubscriptionItemUsageRecordTimestamp { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// Creates a usage record for a specified subscription item and date, and fills it with a quantity. diff --git a/generated/async-stripe-connect/src/account/requests.rs b/generated/async-stripe-connect/src/account/requests.rs index 963c5e00c..de2ccac39 100644 --- a/generated/async-stripe-connect/src/account/requests.rs +++ b/generated/async-stripe-connect/src/account/requests.rs @@ -1514,9 +1514,10 @@ impl Default for CreateAccountSettingsPayoutsSchedule { /// The `delay_days` parameter remains at the last configured value if `interval` is `manual`. /// [Learn more about controlling payout delay days](https://docs.stripe.com/connect/manage-payout-schedule). #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreateAccountSettingsPayoutsScheduleDelayDays { Minimum, + #[serde(untagged)] U32(u32), } /// How frequently available funds are paid out. @@ -2629,9 +2630,10 @@ impl Default for UpdateAccountSettingsPayoutsSchedule { /// The `delay_days` parameter remains at the last configured value if `interval` is `manual`. /// [Learn more about controlling payout delay days](https://docs.stripe.com/connect/manage-payout-schedule). #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpdateAccountSettingsPayoutsScheduleDelayDays { Minimum, + #[serde(untagged)] U32(u32), } /// How frequently available funds are paid out. diff --git a/generated/async-stripe-core/src/file_link/requests.rs b/generated/async-stripe-core/src/file_link/requests.rs index 6019c3f6b..19ce83a05 100644 --- a/generated/async-stripe-core/src/file_link/requests.rs +++ b/generated/async-stripe-core/src/file_link/requests.rs @@ -257,9 +257,10 @@ impl<'a> UpdateFileLinkBuilder<'a> { } /// A future timestamp after which the link will no longer be usable, or `now` to expire the link immediately. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpdateFileLinkExpiresAt { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// Updates an existing file link object. Expired links can no longer be updated. diff --git a/generated/async-stripe-core/src/payment_intent/requests.rs b/generated/async-stripe-core/src/payment_intent/requests.rs index 8bc493b16..b496296fb 100644 --- a/generated/async-stripe-core/src/payment_intent/requests.rs +++ b/generated/async-stripe-core/src/payment_intent/requests.rs @@ -540,11 +540,12 @@ impl<'de> serde::Deserialize<'de> for CreatePaymentIntentMandateDataCustomerAcce /// Use this parameter in scenarios where you collect card details and [charge them later](https://stripe.com/docs/payments/cards/charging-saved-cards). /// This parameter can only be used with [`confirm=true`](https://stripe.com/docs/api/payment_intents/create#create_payment_intent-confirm). #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePaymentIntentOffSession { - Bool(bool), OneOff, Recurring, + #[serde(untagged)] + Bool(bool), } /// If provided, this hash will be used to create a PaymentMethod. The new PaymentMethod will appear /// in the [payment_method](https://stripe.com/docs/api/payment_intents/object#payment_intent_object-payment_method). @@ -17864,9 +17865,11 @@ impl<'a> ConfirmPaymentIntentBuilder<'a> { } } #[derive(Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum ConfirmPaymentIntentMandateData<'a> { + #[serde(untagged)] SecretKeyParam(ConfirmPaymentIntentSecretKeyParam<'a>), + #[serde(untagged)] ClientKeyParam(ConfirmPaymentIntentClientKeyParam<'a>), } #[derive(Clone, Debug, serde::Serialize)] @@ -18070,11 +18073,12 @@ impl<'de> serde::Deserialize<'de> for ConfirmPaymentIntentClientKeyParamCustomer /// Set to `true` to indicate that the customer isn't in your checkout flow during this payment attempt and can't authenticate. /// Use this parameter in scenarios where you collect card details and [charge them later](https://stripe.com/docs/payments/cards/charging-saved-cards). #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum ConfirmPaymentIntentOffSession { - Bool(bool), OneOff, Recurring, + #[serde(untagged)] + Bool(bool), } /// If provided, this hash will be used to create a PaymentMethod. The new PaymentMethod will appear /// in the [payment_method](https://stripe.com/docs/api/payment_intents/object#payment_intent_object-payment_method). diff --git a/generated/async-stripe-core/src/setup_intent/requests.rs b/generated/async-stripe-core/src/setup_intent/requests.rs index 1f537f203..1d1a9a58d 100644 --- a/generated/async-stripe-core/src/setup_intent/requests.rs +++ b/generated/async-stripe-core/src/setup_intent/requests.rs @@ -6966,9 +6966,11 @@ impl<'a> ConfirmSetupIntentBuilder<'a> { } } #[derive(Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum ConfirmSetupIntentMandateData<'a> { + #[serde(untagged)] SecretKeyParam(ConfirmSetupIntentSecretKeyParam<'a>), + #[serde(untagged)] ClientKeyParam(ConfirmSetupIntentClientKeyParam<'a>), } #[derive(Clone, Debug, serde::Serialize)] diff --git a/generated/async-stripe-core/src/token/requests.rs b/generated/async-stripe-core/src/token/requests.rs index 6c7c2f98e..1b860bc46 100644 --- a/generated/async-stripe-core/src/token/requests.rs +++ b/generated/async-stripe-core/src/token/requests.rs @@ -1018,9 +1018,11 @@ impl<'de> serde::Deserialize<'de> for CreateTokenBankAccountAccountType { /// If you also pass in a customer, the card must be the ID of a card belonging to the customer. /// Otherwise, if you do not pass in a customer, this is a dictionary containing a user's credit card details, with the options described below. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreateTokenCard<'a> { + #[serde(untagged)] CreditCardSpecs(CreateTokenCreditCardSpecs<'a>), + #[serde(untagged)] Str(&'a str), } /// The card this token will represent. diff --git a/generated/async-stripe-misc/src/tax_registration/requests.rs b/generated/async-stripe-misc/src/tax_registration/requests.rs index 1e27d0fba..0f73885a0 100644 --- a/generated/async-stripe-misc/src/tax_registration/requests.rs +++ b/generated/async-stripe-misc/src/tax_registration/requests.rs @@ -234,9 +234,10 @@ impl<'a> CreateTaxRegistrationBuilder<'a> { /// Time at which the Tax Registration becomes active. /// It can be either `now` to indicate the current time, or a future timestamp measured in seconds since the Unix epoch. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreateTaxRegistrationActiveFrom { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// Specific options for a registration in the specified `country`. @@ -5952,18 +5953,20 @@ impl<'a> UpdateTaxRegistrationBuilder<'a> { /// Time at which the registration becomes active. /// It can be either `now` to indicate the current time, or a timestamp measured in seconds since the Unix epoch. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpdateTaxRegistrationActiveFrom { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// If set, the registration stops being active at this time. /// If not set, the registration will be active indefinitely. /// It can be either `now` to indicate the current time, or a timestamp measured in seconds since the Unix epoch. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpdateTaxRegistrationExpiresAt { Now, + #[serde(untagged)] Timestamp(stripe_types::Timestamp), } /// Updates an existing Tax `Registration` object. diff --git a/generated/async-stripe-payment/src/payment_method/requests.rs b/generated/async-stripe-payment/src/payment_method/requests.rs index 45d60903f..4816054d7 100644 --- a/generated/async-stripe-payment/src/payment_method/requests.rs +++ b/generated/async-stripe-payment/src/payment_method/requests.rs @@ -623,9 +623,11 @@ impl<'a> CreatePaymentMethodBoleto<'a> { /// When providing a card number, you must meet the requirements for [PCI compliance](https://stripe.com/docs/security#validating-pci-compliance). /// We strongly recommend using Stripe.js instead of interacting with this API directly. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePaymentMethodCard<'a> { + #[serde(untagged)] CardDetailsParams(CreatePaymentMethodCardDetailsParams<'a>), + #[serde(untagged)] TokenParams(CreatePaymentMethodTokenParams<'a>), } /// If this is a `card` PaymentMethod, this hash contains the user's card details. diff --git a/generated/async-stripe-product/src/price/requests.rs b/generated/async-stripe-product/src/price/requests.rs index b7a0728f5..cf6817b97 100644 --- a/generated/async-stripe-product/src/price/requests.rs +++ b/generated/async-stripe-product/src/price/requests.rs @@ -573,9 +573,10 @@ impl CreatePriceCurrencyOptionsTiers { /// The lower bound of a tier is the upper bound of the previous tier adding one. /// Use `inf` to define a fallback tier. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePriceCurrencyOptionsTiersUpTo { Inf, + #[serde(untagged)] I64(i64), } /// These fields can be used to create a new product that this price will belong to. @@ -887,9 +888,10 @@ impl<'a> CreatePriceTiers<'a> { /// The lower bound of a tier is the upper bound of the previous tier adding one. /// Use `inf` to define a fallback tier. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreatePriceTiersUpTo { Inf, + #[serde(untagged)] I64(i64), } /// Apply a transformation to the reported usage or set quantity before computing the billed price. @@ -1226,9 +1228,10 @@ impl UpdatePriceCurrencyOptionsTiers { /// The lower bound of a tier is the upper bound of the previous tier adding one. /// Use `inf` to define a fallback tier. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum UpdatePriceCurrencyOptionsTiersUpTo { Inf, + #[serde(untagged)] I64(i64), } /// Updates the specified price by setting the values of the parameters passed. diff --git a/generated/async-stripe-product/src/product/requests.rs b/generated/async-stripe-product/src/product/requests.rs index 004dd3c57..301da3709 100644 --- a/generated/async-stripe-product/src/product/requests.rs +++ b/generated/async-stripe-product/src/product/requests.rs @@ -588,9 +588,10 @@ impl CreateProductDefaultPriceDataCurrencyOptionsTiers { /// The lower bound of a tier is the upper bound of the previous tier adding one. /// Use `inf` to define a fallback tier. #[derive(Copy, Clone, Debug, serde::Serialize)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] pub enum CreateProductDefaultPriceDataCurrencyOptionsTiersUpTo { Inf, + #[serde(untagged)] I64(i64), } /// The recurring components of a price such as `interval` and `interval_count`. diff --git a/openapi/src/templates/enums.rs b/openapi/src/templates/enums.rs index b9fe6fe02..0e976ab45 100644 --- a/openapi/src/templates/enums.rs +++ b/openapi/src/templates/enums.rs @@ -21,10 +21,13 @@ impl<'a> ObjectWriter<'a> { // Build the body of the enum definition let mut enum_body = String::with_capacity(64); + let mut variants = variants.iter().collect::>(); + variants.sort_by_key(|v| v.rust_type.is_some()); for EnumVariant { variant, rust_type } in variants { if let Some(typ) = rust_type { let printable = self.components.construct_printable_type(typ); let typ = PrintableWithLifetime::new(&printable, self.lifetime); + let _ = writeln!(enum_body, "#[serde(untagged)]"); let _ = writeln!(enum_body, "{variant}({typ}),"); } else { let _ = writeln!(enum_body, "{variant},"); @@ -36,7 +39,7 @@ impl<'a> ObjectWriter<'a> { let _ = writedoc!( out, r#" - #[serde(untagged)] + #[serde(rename_all = "snake_case")] pub enum {enum_name}{lifetime_str} {{ {enum_body} }} diff --git a/tests/tests/it/enums.rs b/tests/tests/it/enums.rs index 804230777..78624aadb 100644 --- a/tests/tests/it/enums.rs +++ b/tests/tests/it/enums.rs @@ -2,6 +2,7 @@ use std::str::FromStr; use stripe_connect::AccountType; use stripe_core::EventType; +use stripe_product::price::CreatePriceTiersUpTo; #[test] fn enums_basic() { @@ -17,6 +18,12 @@ fn enums_basic() { assert!(AccountType::from_str("unknown").is_err()); } +#[test] +fn enums_requests() { + assert_eq!(serde_json::to_string(&CreatePriceTiersUpTo::Inf).unwrap(), r#""inf""#); + assert_eq!(serde_json::to_string(&CreatePriceTiersUpTo::I64(2)).unwrap(), r#"2"#); +} + #[test] fn from_str_and_deser_behavior_match_on_unknown_variant() { let acct_authorized = "account.application.authorized"; From 090006fd605fae483c2cc7dc1215917797f80af4 Mon Sep 17 00:00:00 2001 From: Luis Alberto Santos Date: Tue, 3 Sep 2024 18:47:32 +0200 Subject: [PATCH 2/2] add test --- tests/tests/it/enums.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/tests/it/enums.rs b/tests/tests/it/enums.rs index 78624aadb..dd1a8ad0c 100644 --- a/tests/tests/it/enums.rs +++ b/tests/tests/it/enums.rs @@ -1,5 +1,6 @@ use std::str::FromStr; +use stripe_billing::plan::{CreatePlanInlineProductParams, CreatePlanProduct}; use stripe_connect::AccountType; use stripe_core::EventType; use stripe_product::price::CreatePriceTiersUpTo; @@ -22,6 +23,15 @@ fn enums_basic() { fn enums_requests() { assert_eq!(serde_json::to_string(&CreatePriceTiersUpTo::Inf).unwrap(), r#""inf""#); assert_eq!(serde_json::to_string(&CreatePriceTiersUpTo::I64(2)).unwrap(), r#"2"#); + + assert_eq!(serde_json::to_string(&CreatePlanProduct::Id("id".into())).unwrap(), r#""id""#); + assert_eq!( + serde_json::to_string(&CreatePlanProduct::InlineProductParams( + CreatePlanInlineProductParams::new("my name".into()) + )) + .unwrap(), + r#"{"name":"my name"}"# + ); } #[test]