Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly generate types for optional lists #503

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ serde_qs = "0.10.1"
serde_path_to_error = "0.1.8"
smol_str = "0.1"
surf = { version = "2.1", optional = true }
tokio = { version = "1.2", optional = true }
tokio = { version = "1", optional = true }
smart-default = "0.6.0"
uuid = { version = "0.8", optional=true, features=["v4"] }

Expand All @@ -156,6 +156,12 @@ axum = { version = "0.6.18", features = ["macros"] }
async-trait = "0.1"
actix-web = "4.2.1"

# MSRV PINS
#
# We have a few deps that have MSRVs that are higher than our own.
# We pin them here to ensure that we can run tests on the MSRV
bumpalo = ">=3.0.0, <= 3.15.0"

[[example]]
name = "checkout"
required-features = ["async"]
Expand Down
9 changes: 5 additions & 4 deletions examples/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,18 @@ async fn main() {
CheckoutSession::create(&client, params).await.unwrap()
};

let line_items = checkout_session.line_items.unwrap();

println!(
"created a {} checkout session for {} {:?} for {} {} at {}",
checkout_session.payment_status,
checkout_session.line_items.data[0].quantity.unwrap(),
match checkout_session.line_items.data[0].price.as_ref().unwrap().product.as_ref().unwrap()
{
line_items.data[0].quantity.unwrap(),
match line_items.data[0].price.as_ref().unwrap().product.as_ref().unwrap() {
Expandable::Object(p) => p.name.as_ref().unwrap(),
_ => panic!("product not found"),
},
checkout_session.amount_subtotal.unwrap() / 100,
checkout_session.line_items.data[0].price.as_ref().unwrap().currency.unwrap(),
line_items.data[0].price.as_ref().unwrap().currency.unwrap(),
checkout_session.url.unwrap()
);
}
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
3 changes: 3 additions & 0 deletions src/resources/generated/tax_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ pub enum CreateTaxIdOwnerType {
Account,
Application,
Customer,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -283,6 +284,7 @@ pub enum ListTaxIdsOwnerType {
Account,
Application,
Customer,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -321,6 +323,7 @@ pub enum TaxIDsOwnerType {
Account,
Application,
Customer,
#[serde(rename = "self")]
Self_,
}

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
Loading