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

Preventing openapi codegen script from emitting duplicate structs/enums #163

Closed
Closed
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
321 changes: 216 additions & 105 deletions openapi/src/main.rs

Large diffs are not rendered by default.

1,518 changes: 1,518 additions & 0 deletions output

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,10 @@ def_id!(ChargeId, "ch_" | "py_"); // TODO: Understand (and then document) why "p
def_id!(CheckoutSessionId, "cs_");
def_id!(CheckoutSessionItemId: String); // TODO: Figure out what prefix this id has
def_id!(CouponId: String); // N.B. A coupon id can be user-provided so can be any arbitrary string
def_id!(CreditNoteId, "cn_");
def_id!(CreditNoteLineItemId, "clni_");
def_id!(CustomerId, "cus_");
def_id!(CustomerBalanceTransactionId, "cbtxn_");
def_id!(DiscountId, "di_");
def_id!(DisputeId, "dp_");
def_id!(EphemeralKeyId, "ephkey_");
Expand Down
9 changes: 3 additions & 6 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ pub use {
subscription_ext::*
},
generated::billing::{
credit_note::*,
credit_note_line_item::*,
customer_balance_transaction::*,
coupon::*,
discount::*,
invoice::*,
Expand All @@ -180,13 +183,7 @@ pub use {
quote::*,
quotes_resource_total_details::*,
subscription_item::*,
subscription_item::PlanInterval as SubscriptionItemInterval,
subscription_item::SubscriptionItemPriceDataRecurring as SubscriptionItemPriceDataRecurring,
subscription_item::SubscriptionItemPriceData as SubscriptionItemPriceData,
// need to import this afterwards so that the SubscriptionItemPriceDataRecurring
// isn't silently ignored
subscription::*,
subscription::PlanInterval as SubscriptionInterval,
subscription::SubscriptionItemPriceDataRecurring as SubscriptionPriceDataRecurring,
subscription::SubscriptionItemPriceData as SubscriptionPriceData,
subscription_schedule::*,
Expand Down
3 changes: 3 additions & 0 deletions src/resources/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub mod checkout {
#[cfg(feature = "billing")]
pub mod billing {
pub mod coupon;
pub mod credit_note;
pub mod credit_note_line_item;
pub mod customer_balance_transaction;
pub mod discount;
pub mod invoice;
pub mod invoice_payment_method_options_acss_debit;
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ pub struct TransferScheduleParams {
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged, rename_all = "snake_case")]
#[serde(tag = "object", rename_all = "snake_case")]
pub enum ExternalAccount {
BankAccount(BankAccount),
Card(Card),
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/api_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct ApiErrors {
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged, rename_all = "snake_case")]
#[serde(tag = "object", rename_all = "snake_case")]
pub enum ApiErrorsSourceUnion {
BankAccount(BankAccount),
Card(Card),
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/balance_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl<'a> ListBalanceTransactions<'a> {
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged, rename_all = "snake_case")]
#[serde(tag = "object", rename_all = "snake_case")]
pub enum BalanceTransactionSourceUnion {
ApplicationFee(ApplicationFee),
Charge(Charge),
Expand Down
172 changes: 1 addition & 171 deletions src/resources/generated/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde_derive::{Deserialize, Serialize};
use crate::ids::CapabilityId;
use crate::params::{Expandable, Object, Timestamp};
use crate::resources::Account;
use crate::{AccountRequirementsAlternative, AccountRequirementsError, CapabilityStatus};

/// The resource representing a Stripe "AccountCapability".
#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -133,174 +134,3 @@ pub struct AccountCapabilityRequirements {
/// If verification fails, these fields move to `eventually_due`, `currently_due`, or `past_due`.
pub pending_verification: Vec<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AccountRequirementsAlternative {
/// Fields that can be provided to satisfy all fields in `original_fields_due`.
pub alternative_fields_due: Vec<String>,

/// Fields that are due and can be satisfied by providing all fields in `alternative_fields_due`.
pub original_fields_due: Vec<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AccountRequirementsError {
/// The code for the type of error.
pub code: AccountRequirementsErrorCode,

/// An informative message that indicates the error type and provides additional details about the error.
pub reason: String,

/// The specific user onboarding requirement field (in the requirements hash) that needs to be resolved.
pub requirement: String,
}

/// An enum representing the possible values of an `AccountRequirementsError`'s `code` field.
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum AccountRequirementsErrorCode {
InvalidAddressCityStatePostalCode,
InvalidStreetAddress,
InvalidValueOther,
VerificationDocumentAddressMismatch,
VerificationDocumentAddressMissing,
VerificationDocumentCorrupt,
VerificationDocumentCountryNotSupported,
VerificationDocumentDobMismatch,
VerificationDocumentDuplicateType,
VerificationDocumentExpired,
VerificationDocumentFailedCopy,
VerificationDocumentFailedGreyscale,
VerificationDocumentFailedOther,
VerificationDocumentFailedTestMode,
VerificationDocumentFraudulent,
VerificationDocumentIdNumberMismatch,
VerificationDocumentIdNumberMissing,
VerificationDocumentIncomplete,
VerificationDocumentInvalid,
VerificationDocumentIssueOrExpiryDateMissing,
VerificationDocumentManipulated,
VerificationDocumentMissingBack,
VerificationDocumentMissingFront,
VerificationDocumentNameMismatch,
VerificationDocumentNameMissing,
VerificationDocumentNationalityMismatch,
VerificationDocumentNotReadable,
VerificationDocumentNotSigned,
VerificationDocumentNotUploaded,
VerificationDocumentPhotoMismatch,
VerificationDocumentTooLarge,
VerificationDocumentTypeNotSupported,
VerificationFailedAddressMatch,
VerificationFailedBusinessIecNumber,
VerificationFailedDocumentMatch,
VerificationFailedIdNumberMatch,
VerificationFailedKeyedIdentity,
VerificationFailedKeyedMatch,
VerificationFailedNameMatch,
VerificationFailedOther,
VerificationFailedTaxIdMatch,
VerificationFailedTaxIdNotIssued,
VerificationMissingExecutives,
VerificationMissingOwners,
VerificationRequiresAdditionalMemorandumOfAssociations,
}

impl AccountRequirementsErrorCode {
pub fn as_str(self) -> &'static str {
match self {
AccountRequirementsErrorCode::InvalidAddressCityStatePostalCode => "invalid_address_city_state_postal_code",
AccountRequirementsErrorCode::InvalidStreetAddress => "invalid_street_address",
AccountRequirementsErrorCode::InvalidValueOther => "invalid_value_other",
AccountRequirementsErrorCode::VerificationDocumentAddressMismatch => "verification_document_address_mismatch",
AccountRequirementsErrorCode::VerificationDocumentAddressMissing => "verification_document_address_missing",
AccountRequirementsErrorCode::VerificationDocumentCorrupt => "verification_document_corrupt",
AccountRequirementsErrorCode::VerificationDocumentCountryNotSupported => "verification_document_country_not_supported",
AccountRequirementsErrorCode::VerificationDocumentDobMismatch => "verification_document_dob_mismatch",
AccountRequirementsErrorCode::VerificationDocumentDuplicateType => "verification_document_duplicate_type",
AccountRequirementsErrorCode::VerificationDocumentExpired => "verification_document_expired",
AccountRequirementsErrorCode::VerificationDocumentFailedCopy => "verification_document_failed_copy",
AccountRequirementsErrorCode::VerificationDocumentFailedGreyscale => "verification_document_failed_greyscale",
AccountRequirementsErrorCode::VerificationDocumentFailedOther => "verification_document_failed_other",
AccountRequirementsErrorCode::VerificationDocumentFailedTestMode => "verification_document_failed_test_mode",
AccountRequirementsErrorCode::VerificationDocumentFraudulent => "verification_document_fraudulent",
AccountRequirementsErrorCode::VerificationDocumentIdNumberMismatch => "verification_document_id_number_mismatch",
AccountRequirementsErrorCode::VerificationDocumentIdNumberMissing => "verification_document_id_number_missing",
AccountRequirementsErrorCode::VerificationDocumentIncomplete => "verification_document_incomplete",
AccountRequirementsErrorCode::VerificationDocumentInvalid => "verification_document_invalid",
AccountRequirementsErrorCode::VerificationDocumentIssueOrExpiryDateMissing => "verification_document_issue_or_expiry_date_missing",
AccountRequirementsErrorCode::VerificationDocumentManipulated => "verification_document_manipulated",
AccountRequirementsErrorCode::VerificationDocumentMissingBack => "verification_document_missing_back",
AccountRequirementsErrorCode::VerificationDocumentMissingFront => "verification_document_missing_front",
AccountRequirementsErrorCode::VerificationDocumentNameMismatch => "verification_document_name_mismatch",
AccountRequirementsErrorCode::VerificationDocumentNameMissing => "verification_document_name_missing",
AccountRequirementsErrorCode::VerificationDocumentNationalityMismatch => "verification_document_nationality_mismatch",
AccountRequirementsErrorCode::VerificationDocumentNotReadable => "verification_document_not_readable",
AccountRequirementsErrorCode::VerificationDocumentNotSigned => "verification_document_not_signed",
AccountRequirementsErrorCode::VerificationDocumentNotUploaded => "verification_document_not_uploaded",
AccountRequirementsErrorCode::VerificationDocumentPhotoMismatch => "verification_document_photo_mismatch",
AccountRequirementsErrorCode::VerificationDocumentTooLarge => "verification_document_too_large",
AccountRequirementsErrorCode::VerificationDocumentTypeNotSupported => "verification_document_type_not_supported",
AccountRequirementsErrorCode::VerificationFailedAddressMatch => "verification_failed_address_match",
AccountRequirementsErrorCode::VerificationFailedBusinessIecNumber => "verification_failed_business_iec_number",
AccountRequirementsErrorCode::VerificationFailedDocumentMatch => "verification_failed_document_match",
AccountRequirementsErrorCode::VerificationFailedIdNumberMatch => "verification_failed_id_number_match",
AccountRequirementsErrorCode::VerificationFailedKeyedIdentity => "verification_failed_keyed_identity",
AccountRequirementsErrorCode::VerificationFailedKeyedMatch => "verification_failed_keyed_match",
AccountRequirementsErrorCode::VerificationFailedNameMatch => "verification_failed_name_match",
AccountRequirementsErrorCode::VerificationFailedOther => "verification_failed_other",
AccountRequirementsErrorCode::VerificationFailedTaxIdMatch => "verification_failed_tax_id_match",
AccountRequirementsErrorCode::VerificationFailedTaxIdNotIssued => "verification_failed_tax_id_not_issued",
AccountRequirementsErrorCode::VerificationMissingExecutives => "verification_missing_executives",
AccountRequirementsErrorCode::VerificationMissingOwners => "verification_missing_owners",
AccountRequirementsErrorCode::VerificationRequiresAdditionalMemorandumOfAssociations => "verification_requires_additional_memorandum_of_associations",
}
}
}

impl AsRef<str> for AccountRequirementsErrorCode {
fn as_ref(&self) -> &str {
self.as_str()
}
}

impl std::fmt::Display for AccountRequirementsErrorCode {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}

/// An enum representing the possible values of an `Capability`'s `status` field.
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CapabilityStatus {
Active,
Disabled,
Inactive,
Pending,
Unrequested,
}

impl CapabilityStatus {
pub fn as_str(self) -> &'static str {
match self {
CapabilityStatus::Active => "active",
CapabilityStatus::Disabled => "disabled",
CapabilityStatus::Inactive => "inactive",
CapabilityStatus::Pending => "pending",
CapabilityStatus::Unrequested => "unrequested",
}
}
}

impl AsRef<str> for CapabilityStatus {
fn as_ref(&self) -> &str {
self.as_str()
}
}

impl std::fmt::Display for CapabilityStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
27 changes: 22 additions & 5 deletions src/resources/generated/checkout_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use crate::config::{Client, Response};
use crate::ids::{CheckoutSessionId, CustomerId, PaymentIntentId, SubscriptionId};
use crate::params::{Expand, Expandable, List, Metadata, Object, Timestamp};
use crate::resources::{
CheckoutSessionItem, Currency, Customer, Discount, PaymentIntent, PaymentLink,
PaymentMethodOptionsBoleto, PaymentMethodOptionsOxxo, SetupIntent, Shipping, ShippingRate,
Subscription, TaxRate,
CheckoutSessionItem, Currency, Customer, Discount, PaymentIntent, PaymentLink, SetupIntent,
Shipping, ShippingRate, Subscription, TaxRate,
};

/// The resource representing a Stripe "Session".
Expand Down Expand Up @@ -228,10 +227,10 @@ pub struct CheckoutSessionPaymentMethodOptions {
pub acss_debit: Option<Box<CheckoutAcssDebitPaymentMethodOptions>>,

#[serde(skip_serializing_if = "Option::is_none")]
pub boleto: Option<Box<PaymentMethodOptionsBoleto>>,
pub boleto: Option<Box<CheckoutBoletoPaymentMethodOptions>>,

#[serde(skip_serializing_if = "Option::is_none")]
pub oxxo: Option<Box<PaymentMethodOptionsOxxo>>,
pub oxxo: Option<Box<CheckoutOxxoPaymentMethodOptions>>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -277,6 +276,22 @@ pub struct CheckoutAcssDebitMandateOptions {
pub transaction_type: Option<Box<CheckoutAcssDebitMandateOptionsTransactionType>>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CheckoutBoletoPaymentMethodOptions {
/// The number of calendar days before a Boleto voucher expires.
///
/// For example, if you create a Boleto voucher on Monday and you set expires_after_days to 2, the Boleto voucher will expire on Wednesday at 23:59 America/Sao_Paulo time.
pub expires_after_days: u32,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CheckoutOxxoPaymentMethodOptions {
/// The number of calendar days before an OXXO invoice expires.
///
/// For example, if you create an OXXO invoice on Monday and you set expires_after_days to 2, the OXXO invoice will expire on Wednesday at 23:59 America/Mexico_City time.
pub expires_after_days: u32,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PaymentPagesCheckoutSessionAfterExpiration {
/// When set, configuration used to recover the Checkout Session on expiry.
Expand Down Expand Up @@ -1945,6 +1960,7 @@ pub enum CreateCheckoutSessionPaymentMethodTypes {
AcssDebit,
AfterpayClearpay,
Alipay,
AuBecsDebit,
BacsDebit,
Bancontact,
Boleto,
Expand All @@ -1968,6 +1984,7 @@ impl CreateCheckoutSessionPaymentMethodTypes {
CreateCheckoutSessionPaymentMethodTypes::AcssDebit => "acss_debit",
CreateCheckoutSessionPaymentMethodTypes::AfterpayClearpay => "afterpay_clearpay",
CreateCheckoutSessionPaymentMethodTypes::Alipay => "alipay",
CreateCheckoutSessionPaymentMethodTypes::AuBecsDebit => "au_becs_debit",
CreateCheckoutSessionPaymentMethodTypes::BacsDebit => "bacs_debit",
CreateCheckoutSessionPaymentMethodTypes::Bancontact => "bancontact",
CreateCheckoutSessionPaymentMethodTypes::Boleto => "boleto",
Expand Down
26 changes: 3 additions & 23 deletions src/resources/generated/credit_note_line_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use serde_derive::{Deserialize, Serialize};

use crate::ids::CreditNoteLineItemId;
use crate::params::{Expandable, Object};
use crate::resources::{Discount, TaxRate};
use crate::params::Object;
use crate::resources::TaxRate;
use crate::{CreditNoteTaxAmount, DiscountsResourceDiscountAmount};

/// The resource representing a Stripe "CreditNoteLineItem".
#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -69,27 +70,6 @@ impl Object for CreditNoteLineItem {
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CreditNoteTaxAmount {
/// The amount, in %s, of the tax.
pub amount: i64,

/// Whether this tax amount is inclusive or exclusive.
pub inclusive: bool,

/// The tax rate that was applied to get this tax amount.
pub tax_rate: Expandable<TaxRate>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct DiscountsResourceDiscountAmount {
/// The amount, in %s, of the discount.
pub amount: i64,

/// The discount that was applied to get this discount amount.
pub discount: Expandable<Discount>,
}

/// An enum representing the possible values of an `CreditNoteLineItem`'s `type` field.
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
Expand Down
Loading