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 issue with missing rename of Self_ #490

Merged
merged 1 commit into from
Feb 15, 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
20 changes: 18 additions & 2 deletions openapi/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ pub fn gen_unions(out: &mut String, unions: &BTreeMap<String, InferredUnion>, me
.unwrap_or_else(|| schema.schema_data.title.clone().unwrap());
let variant_name = meta.schema_to_rust_type(&object_name);
let type_name = meta.schema_to_rust_type(variant_schema);
if variant_name.to_snake_case() != object_name {
if variant_to_serde_snake_case(&variant_name) != object_name {
write_serde_rename(out, &object_name);
}
out.push_str(" ");
Expand Down Expand Up @@ -694,6 +694,22 @@ pub fn gen_unions(out: &mut String, unions: &BTreeMap<String, InferredUnion>, me
}
}

/// This code is taken from serde RenameRule::apply_to_variant
/// It differs in some cases from heck, so we need to make sure we
/// do exactly the same when figuring out whether we need a serde(rename)
/// e.g. heck_snake(Self_) = self
/// serde_snake(Self_) = self_
pub fn variant_to_serde_snake_case(variant: &str) -> String {
let mut snake = String::new();
for (i, ch) in variant.char_indices() {
if i > 0 && ch.is_uppercase() {
snake.push('_');
}
snake.push(ch.to_ascii_lowercase());
}
snake
}

#[tracing::instrument(skip_all)]
pub fn gen_variant_name(wire_name: &str, meta: &Metadata) -> String {
match wire_name {
Expand Down Expand Up @@ -732,7 +748,7 @@ pub fn gen_enums(out: &mut String, enums: &BTreeMap<String, InferredEnum>, meta:
if variant_name.trim().is_empty() {
panic!("unhandled enum variant: {:?}", wire_name)
}
if &variant_name.to_snake_case() != wire_name {
if &variant_to_serde_snake_case(&variant_name) != wire_name {
write_serde_rename(out, wire_name);
}
out.push_str(" ");
Expand Down
3 changes: 3 additions & 0 deletions src/resources/generated/checkout_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4699,6 +4699,7 @@ impl std::default::Default for CheckoutUsBankAccountPaymentMethodOptionsVerifica
#[serde(rename_all = "snake_case")]
pub enum CreateCheckoutSessionAutomaticTaxLiabilityType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -5013,6 +5014,7 @@ impl std::default::Default for CreateCheckoutSessionCustomerUpdateShipping {
#[serde(rename_all = "snake_case")]
pub enum CreateCheckoutSessionInvoiceCreationInvoiceDataIssuerType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -7833,6 +7835,7 @@ impl std::default::Default for CreateCheckoutSessionShippingOptionsShippingRateD
#[serde(rename_all = "snake_case")]
pub enum CreateCheckoutSessionSubscriptionDataInvoiceSettingsIssuerType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down
1 change: 1 addition & 0 deletions src/resources/generated/connect_account_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct ConnectAccountReference {
#[serde(rename_all = "snake_case")]
pub enum ConnectAccountReferenceType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,7 @@ impl std::default::Default for CollectionMethod {
#[serde(rename_all = "snake_case")]
pub enum CreateInvoiceAutomaticTaxLiabilityType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -1621,6 +1622,7 @@ impl std::default::Default for CreateInvoiceFromInvoiceAction {
#[serde(rename_all = "snake_case")]
pub enum CreateInvoiceIssuerType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down
2 changes: 0 additions & 2 deletions src/resources/generated/issuing_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ pub enum IssuingCardSpendingLimitCategories {
HardwareStores,
HealthAndBeautySpas,
HearingAidsSalesAndSupplies,
#[serde(rename = "heating_plumbing_a_c")]
HeatingPlumbingAC,
arlyon marked this conversation as resolved.
Show resolved Hide resolved
HobbyToyAndGameShops,
HomeSupplyWarehouseStores,
Expand Down Expand Up @@ -737,7 +736,6 @@ pub enum IssuingCardSpendingLimitCategories {
TruckUtilityTrailerRentals,
TypesettingPlateMakingAndRelatedServices,
TypewriterStores,
#[serde(rename = "u_s_federal_government_agencies_or_departments")]
USFederalGovernmentAgenciesOrDepartments,
arlyon marked this conversation as resolved.
Show resolved Hide resolved
UniformsCommercialClothing,
UsedMerchandiseAndSecondhandStores,
Expand Down
2 changes: 0 additions & 2 deletions src/resources/generated/issuing_cardholder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ pub enum IssuingCardholderSpendingLimitCategories {
HardwareStores,
HealthAndBeautySpas,
HearingAidsSalesAndSupplies,
#[serde(rename = "heating_plumbing_a_c")]
HeatingPlumbingAC,
HobbyToyAndGameShops,
HomeSupplyWarehouseStores,
Expand Down Expand Up @@ -639,7 +638,6 @@ pub enum IssuingCardholderSpendingLimitCategories {
TruckUtilityTrailerRentals,
TypesettingPlateMakingAndRelatedServices,
TypewriterStores,
#[serde(rename = "u_s_federal_government_agencies_or_departments")]
USFederalGovernmentAgenciesOrDepartments,
UniformsCommercialClothing,
UsedMerchandiseAndSecondhandStores,
Expand Down
6 changes: 6 additions & 0 deletions src/resources/generated/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,7 @@ impl std::default::Default for CreatePaymentLinkAfterCompletionType {
#[serde(rename_all = "snake_case")]
pub enum CreatePaymentLinkAutomaticTaxLiabilityType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -1996,6 +1997,7 @@ impl std::default::Default for CreatePaymentLinkCustomFieldsType {
#[serde(rename_all = "snake_case")]
pub enum CreatePaymentLinkInvoiceCreationInvoiceDataIssuerType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -2965,6 +2967,7 @@ impl std::default::Default for CreatePaymentLinkShippingAddressCollectionAllowed
#[serde(rename_all = "snake_case")]
pub enum CreatePaymentLinkSubscriptionDataInvoiceSettingsIssuerType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -4314,6 +4317,7 @@ impl std::default::Default for UpdatePaymentLinkAfterCompletionType {
#[serde(rename_all = "snake_case")]
pub enum UpdatePaymentLinkAutomaticTaxLiabilityType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -4416,6 +4420,7 @@ impl std::default::Default for UpdatePaymentLinkCustomFieldsType {
#[serde(rename_all = "snake_case")]
pub enum UpdatePaymentLinkInvoiceCreationInvoiceDataIssuerType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -5315,6 +5320,7 @@ impl std::default::Default for UpdatePaymentLinkShippingAddressCollectionAllowed
#[serde(rename_all = "snake_case")]
pub enum UpdatePaymentLinkSubscriptionDataInvoiceSettingsIssuerType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down
4 changes: 4 additions & 0 deletions src/resources/generated/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,7 @@ impl std::default::Default for CancellationDetailsReason {
#[serde(rename_all = "snake_case")]
pub enum CreateSubscriptionAutomaticTaxLiabilityType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -1980,6 +1981,7 @@ impl std::default::Default for CreateSubscriptionAutomaticTaxLiabilityType {
#[serde(rename_all = "snake_case")]
pub enum CreateSubscriptionInvoiceSettingsIssuerType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -3161,6 +3163,7 @@ impl std::default::Default for SubscriptionsResourcePaymentSettingsSaveDefaultPa
#[serde(rename_all = "snake_case")]
pub enum UpdateSubscriptionAutomaticTaxLiabilityType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -3241,6 +3244,7 @@ impl std::default::Default for UpdateSubscriptionCancellationDetailsFeedback {
#[serde(rename_all = "snake_case")]
pub enum UpdateSubscriptionInvoiceSettingsIssuerType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down
4 changes: 4 additions & 0 deletions src/resources/generated/subscription_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,7 @@ pub struct UpdateSubscriptionSchedulePhasesItemsPriceDataRecurring {
#[serde(rename_all = "snake_case")]
pub enum CreateSubscriptionSchedulePhasesAutomaticTaxLiabilityType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -1558,6 +1559,7 @@ impl std::default::Default for SubscriptionScheduleDefaultSettingsCollectionMeth
#[serde(rename_all = "snake_case")]
pub enum SubscriptionScheduleDefaultSettingsParamsAutomaticTaxLiabilityType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -1668,6 +1670,7 @@ impl std::default::Default for SubscriptionScheduleEndBehavior {
#[serde(rename_all = "snake_case")]
pub enum SubscriptionScheduleInvoiceSettingsIssuerType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down Expand Up @@ -1776,6 +1779,7 @@ impl std::default::Default for SubscriptionScheduleStatus {
#[serde(rename_all = "snake_case")]
pub enum UpdateSubscriptionSchedulePhasesAutomaticTaxLiabilityType {
Account,
#[serde(rename = "self")]
Self_,
}

Expand Down
Loading