Skip to content

Commit

Permalink
fix: correctly generate types for optional lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Lyon authored and arlyon committed Feb 20, 2024
1 parent e781d02 commit 63732cc
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 28 deletions.
4 changes: 0 additions & 4 deletions openapi/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,10 +1299,6 @@ pub fn gen_field_rust_type<T: Borrow<Schema>>(
// Not sure why this is here, but we want to preserve it for now
return "bool".into();
}
if ty.contains("List<") {
// N.B. return immediately; we use `Default` for list rather than `Option`
return ty;
}

// currency_options field is represented by an optional HashMap<String, T>, where the String is the currency code in ISO 4217 format.
if field_name == "currency_options" {
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ pub struct Account {
/// External accounts (bank accounts and debit cards) currently attached to this account.
///
/// External accounts are only returned for requests where `controller[is_controller]` is true.
#[serde(default)]
pub external_accounts: List<ExternalAccount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub external_accounts: Option<List<ExternalAccount>>,

#[serde(skip_serializing_if = "Option::is_none")]
pub future_requirements: Option<AccountFutureRequirements>,
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/charge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub struct Charge {
pub refunded: bool,

/// A list of refunds that have been applied to the charge.
pub refunds: List<Refund>,
pub refunds: Option<List<Refund>>,

/// ID of the review associated with this charge if one exists.
pub review: Option<Expandable<Review>>,
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/checkout_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ pub struct CheckoutSession {
pub invoice_creation: Option<PaymentPagesCheckoutSessionInvoiceCreation>,

/// The line items purchased by the customer.
#[serde(default)]
pub line_items: List<CheckoutSessionItem>,
#[serde(skip_serializing_if = "Option::is_none")]
pub line_items: Option<List<CheckoutSessionItem>>,

/// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
pub livemode: bool,
Expand Down
8 changes: 4 additions & 4 deletions src/resources/generated/customer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ pub struct Customer {
pub sources: List<PaymentSource>,

/// The customer's current subscriptions, if any.
#[serde(default)]
pub subscriptions: List<Subscription>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subscriptions: Option<List<Subscription>>,

#[serde(skip_serializing_if = "Option::is_none")]
pub tax: Option<CustomerTax>,
Expand All @@ -152,8 +152,8 @@ pub struct Customer {
pub tax_exempt: Option<CustomerTaxExempt>,

/// The customer's tax IDs.
#[serde(default)]
pub tax_ids: List<TaxId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tax_ids: Option<List<TaxId>>,

/// ID of the test clock that this customer belongs to.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub struct File {
pub filename: Option<String>,

/// A list of [file links](https://stripe.com/docs/api#file_links) that point at this file.
#[serde(default)]
pub links: List<FileLink>,
#[serde(skip_serializing_if = "Option::is_none")]
pub links: Option<List<FileLink>>,

/// The [purpose](https://stripe.com/docs/file-upload#uploading-a-file) of the uploaded file.
pub purpose: FilePurpose,
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ pub struct Invoice {
/// The individual line items that make up the invoice.
///
/// `lines` is sorted as follows: (1) pending invoice items (including prorations) in reverse chronological order, (2) subscription items in reverse chronological order, and (3) invoice items added after invoice creation in chronological order.
#[serde(default)]
pub lines: List<InvoiceLineItem>,
#[serde(skip_serializing_if = "Option::is_none")]
pub lines: Option<List<InvoiceLineItem>>,

/// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ pub struct PaymentLink {
pub invoice_creation: Option<PaymentLinksResourceInvoiceCreation>,

/// The line items representing what is being sold.
#[serde(default)]
pub line_items: List<CheckoutSessionItem>,
#[serde(skip_serializing_if = "Option::is_none")]
pub line_items: Option<List<CheckoutSessionItem>>,

/// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
pub livemode: bool,
Expand Down
8 changes: 4 additions & 4 deletions src/resources/generated/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub struct Quote {
pub invoice_settings: InvoiceSettingQuoteSetting,

/// A list of items the customer is being quoted for.
#[serde(default)]
pub line_items: List<CheckoutSessionItem>,
#[serde(skip_serializing_if = "Option::is_none")]
pub line_items: Option<List<CheckoutSessionItem>>,

/// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
pub livemode: bool,
Expand Down Expand Up @@ -302,8 +302,8 @@ pub struct QuotesResourceUpfront {
/// The line items that will appear on the next invoice after this quote is accepted.
///
/// This does not include pending invoice items that exist on the customer but may still be included in the next invoice.
#[serde(default)]
pub line_items: List<CheckoutSessionItem>,
#[serde(skip_serializing_if = "Option::is_none")]
pub line_items: Option<List<CheckoutSessionItem>>,

pub total_details: QuotesResourceTotalDetails,
}
Expand Down
4 changes: 2 additions & 2 deletions src/resources/generated/radar_value_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub struct RadarValueList {
pub item_type: Option<RadarValueListItemType>,

/// List of items contained within this value list.
#[serde(default)]
pub list_items: List<RadarValueListItem>,
#[serde(skip_serializing_if = "Option::is_none")]
pub list_items: Option<List<RadarValueListItem>>,

/// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/tax_calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct TaxCalculation {
pub expires_at: Option<Timestamp>,

/// The list of items the customer is purchasing.
pub line_items: List<TaxCalculationLineItem>,
pub line_items: Option<List<TaxCalculationLineItem>>,

/// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
pub livemode: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/tax_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct TaxTransaction {
pub customer_details: TaxProductResourceCustomerDetails,

/// The tax collected or refunded, by line item.
pub line_items: List<TaxTransactionLineItem>,
pub line_items: Option<List<TaxTransactionLineItem>>,

/// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
pub livemode: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/treasury_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct TreasuryTransaction {
/// A list of TransactionEntries that are part of this Transaction.
///
/// This cannot be expanded in any list endpoints.
pub entries: List<TreasuryTransactionEntry>,
pub entries: Option<List<TreasuryTransactionEntry>>,

/// The FinancialAccount associated with this object.
pub financial_account: String,
Expand Down

0 comments on commit 63732cc

Please sign in to comment.