Skip to content

Commit

Permalink
fix: respect the required and optional fields for EventType and Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Sep 27, 2023
1 parent c39fd5f commit cdabd2e
Show file tree
Hide file tree
Showing 38 changed files with 110 additions and 102 deletions.
12 changes: 10 additions & 2 deletions openapi/src/codegen.rs
Expand Up @@ -1234,7 +1234,11 @@ pub fn gen_field_rust_type<T: Borrow<Schema>>(
}
if field_name == "metadata" {
state.use_params.insert("Metadata");
return "Metadata".into();
return if !required || is_nullable {
"Option<Metadata>".into()
} else {
"Metadata".into()
};
} else if (field_name == "currency" || field_name.ends_with("_currency"))
&& matches!(maybe_schema.map(|s| &s.schema_kind), Some(SchemaKind::Type(Type::String(_))))
{
Expand All @@ -1253,7 +1257,11 @@ pub fn gen_field_rust_type<T: Borrow<Schema>>(
};
} else if field_name == "type" && object == "event" {
state.use_resources.insert("EventType".into());
return "EventType".into();
return if !required || is_nullable {
"Option<EventType>".into()
} else {
"EventType".into()
};
}

let ty = gen_schema_or_ref_type(
Expand Down
8 changes: 4 additions & 4 deletions src/resources/generated/account.rs
Expand Up @@ -88,8 +88,8 @@ pub struct Account {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// Whether Stripe can send payouts to this account.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1495,8 +1495,8 @@ pub struct PersonParams {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The individual's phone number.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/bank_account.rs
Expand Up @@ -81,8 +81,8 @@ pub struct BankAccount {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// Information about the requirements for the bank account, including what information needs to be collected.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/billing_portal_configuration.rs
Expand Up @@ -47,7 +47,7 @@ pub struct BillingPortalConfiguration {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Metadata,
pub metadata: Option<Metadata>,

/// Time at which the object was last updated.
///
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/card.rs
Expand Up @@ -151,8 +151,8 @@ pub struct Card {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// Cardholder name.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
28 changes: 14 additions & 14 deletions src/resources/generated/checkout_session.rs
Expand Up @@ -126,7 +126,7 @@ pub struct CheckoutSession {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Metadata,
pub metadata: Option<Metadata>,

/// The mode of the Checkout Session.
pub mode: CheckoutSessionMode,
Expand Down Expand Up @@ -938,7 +938,7 @@ pub struct PaymentPagesCheckoutSessionInvoiceSettings {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Metadata,
pub metadata: Option<Metadata>,

/// Options for invoice PDF rendering.
pub rendering_options: Option<InvoiceSettingRenderingOptions>,
Expand Down Expand Up @@ -1563,8 +1563,8 @@ pub struct CreateCheckoutSessionPaymentIntentData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The Stripe account ID for which these funds are intended.
///
Expand Down Expand Up @@ -1761,8 +1761,8 @@ pub struct CreateCheckoutSessionSetupIntentData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The Stripe account for which the setup is intended.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1821,8 +1821,8 @@ pub struct CreateCheckoutSessionSubscriptionData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The account on behalf of which to charge, for each of the subscription's invoices.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1969,8 +1969,8 @@ pub struct CreateCheckoutSessionInvoiceCreationInvoiceData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// Default options for invoice PDF rendering for this customer.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -2529,8 +2529,8 @@ pub struct CreateCheckoutSessionShippingOptionsShippingRateData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// Specifies whether the rate is considered inclusive of taxes or exclusive of taxes.
///
Expand Down Expand Up @@ -2626,8 +2626,8 @@ pub struct CreateCheckoutSessionLineItemsPriceDataProductData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The product's name, meant to be displayable to the customer.
pub name: String,
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/coupon.rs
Expand Up @@ -69,8 +69,8 @@ pub struct Coupon {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// Name of the coupon displayed to customers on for instance invoices or receipts.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/credit_note.rs
Expand Up @@ -69,7 +69,7 @@ pub struct CreditNote {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Metadata,
pub metadata: Option<Metadata>,

/// A unique number that identifies this particular credit note and appears on the PDF of the credit note and its associated invoice.
pub number: String,
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/customer.rs
Expand Up @@ -107,8 +107,8 @@ pub struct Customer {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The customer's full name or business name.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/customer_balance_transaction.rs
Expand Up @@ -57,7 +57,7 @@ pub struct CustomerBalanceTransaction {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Metadata,
pub metadata: Option<Metadata>,

/// Transaction type: `adjustment`, `applied_to_invoice`, `credit_note`, `initial`, `invoice_overpaid`, `invoice_too_large`, `invoice_too_small`, `unspent_receiver_credit`, or `unapplied_from_invoice`.
///
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/fee_refund.rs
Expand Up @@ -38,7 +38,7 @@ pub struct ApplicationFeeRefund {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Metadata,
pub metadata: Option<Metadata>,
}

impl Object for ApplicationFeeRefund {
Expand Down
10 changes: 5 additions & 5 deletions src/resources/generated/invoice.rs
Expand Up @@ -291,8 +291,8 @@ pub struct Invoice {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The time at which payment will next be attempted.
///
Expand Down Expand Up @@ -670,7 +670,7 @@ pub struct SubscriptionDetailsData {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that will reflect the metadata of the subscription at the time of invoice creation.
///
/// *Note: This attribute is populated only for invoices created on or after June 29, 2023.*.
pub metadata: Metadata,
pub metadata: Option<Metadata>,
}

/// The parameters for `Invoice::create`.
Expand Down Expand Up @@ -1121,8 +1121,8 @@ pub struct CreateInvoiceShippingCostShippingRateData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// Specifies whether the rate is considered inclusive of taxes or exclusive of taxes.
///
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/invoiceitem.rs
Expand Up @@ -78,8 +78,8 @@ pub struct InvoiceItem {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

#[serde(skip_serializing_if = "Option::is_none")]
pub period: Option<Period>,
Expand Down
8 changes: 4 additions & 4 deletions src/resources/generated/payment_intent.rs
Expand Up @@ -2001,8 +2001,8 @@ pub struct CreatePaymentIntentPaymentMethodData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// If this is an `oxxo` PaymentMethod, this hash contains details about the OXXO payment method.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -2338,8 +2338,8 @@ pub struct UpdatePaymentIntentPaymentMethodData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// If this is an `oxxo` PaymentMethod, this hash contains details about the OXXO payment method.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
10 changes: 5 additions & 5 deletions src/resources/generated/payment_link.rs
Expand Up @@ -323,7 +323,7 @@ pub struct PaymentLinksResourceInvoiceSettings {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Metadata,
pub metadata: Option<Metadata>,

/// Options for invoice PDF rendering.
pub rendering_options: Option<InvoiceSettingRenderingOptions>,
Expand Down Expand Up @@ -1107,8 +1107,8 @@ pub struct CreatePaymentLinkInvoiceCreationInvoiceData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// Default options for invoice PDF rendering for this customer.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1235,8 +1235,8 @@ pub struct UpdatePaymentLinkInvoiceCreationInvoiceData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// Default options for invoice PDF rendering for this customer.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/payment_method.rs
Expand Up @@ -104,7 +104,7 @@ pub struct PaymentMethod {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Metadata,
pub metadata: Option<Metadata>,

#[serde(skip_serializing_if = "Option::is_none")]
pub oxxo: Option<PaymentMethodOxxo>,
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/payout.rs
Expand Up @@ -66,7 +66,7 @@ pub struct Payout {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Metadata,
pub metadata: Option<Metadata>,

/// The method used to send this payout, which can be `standard` or `instant`.
///
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/person.rs
Expand Up @@ -102,8 +102,8 @@ pub struct Person {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The country where the person is a national.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/plan.rs
Expand Up @@ -86,8 +86,8 @@ pub struct Plan {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// A brief description of the plan, hidden from customers.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
8 changes: 4 additions & 4 deletions src/resources/generated/price.rs
Expand Up @@ -71,8 +71,8 @@ pub struct Price {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// A brief description of the price, hidden from customers.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -610,8 +610,8 @@ pub struct CreatePriceProductData {
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The product's name, meant to be displayable to the customer.
pub name: String,
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/product.rs
Expand Up @@ -61,8 +61,8 @@ pub struct Product {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The product's name, meant to be displayable to the customer.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/promotion_code.rs
Expand Up @@ -51,7 +51,7 @@ pub struct PromotionCode {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Metadata,
pub metadata: Option<Metadata>,

pub restrictions: PromotionCodesResourceRestrictions,

Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/radar_value_list.rs
Expand Up @@ -50,8 +50,8 @@ pub struct RadarValueList {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,

/// The name of the value list.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down

0 comments on commit cdabd2e

Please sign in to comment.