Skip to content

Commit a91ac97

Browse files
authored
Merge pull request #490 from jwiesler/fix-self-rename
Fix issue with missing rename of Self_
2 parents 5a43415 + 9c58038 commit a91ac97

9 files changed

+38
-6
lines changed

openapi/src/codegen.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ pub fn gen_unions(out: &mut String, unions: &BTreeMap<String, InferredUnion>, me
657657
.unwrap_or_else(|| schema.schema_data.title.clone().unwrap());
658658
let variant_name = meta.schema_to_rust_type(&object_name);
659659
let type_name = meta.schema_to_rust_type(variant_schema);
660-
if variant_name.to_snake_case() != object_name {
660+
if variant_to_serde_snake_case(&variant_name) != object_name {
661661
write_serde_rename(out, &object_name);
662662
}
663663
out.push_str(" ");
@@ -694,6 +694,22 @@ pub fn gen_unions(out: &mut String, unions: &BTreeMap<String, InferredUnion>, me
694694
}
695695
}
696696

697+
/// This code is taken from serde RenameRule::apply_to_variant
698+
/// It differs in some cases from heck, so we need to make sure we
699+
/// do exactly the same when figuring out whether we need a serde(rename)
700+
/// e.g. heck_snake(Self_) = self
701+
/// serde_snake(Self_) = self_
702+
pub fn variant_to_serde_snake_case(variant: &str) -> String {
703+
let mut snake = String::new();
704+
for (i, ch) in variant.char_indices() {
705+
if i > 0 && ch.is_uppercase() {
706+
snake.push('_');
707+
}
708+
snake.push(ch.to_ascii_lowercase());
709+
}
710+
snake
711+
}
712+
697713
#[tracing::instrument(skip_all)]
698714
pub fn gen_variant_name(wire_name: &str, meta: &Metadata) -> String {
699715
match wire_name {
@@ -732,7 +748,7 @@ pub fn gen_enums(out: &mut String, enums: &BTreeMap<String, InferredEnum>, meta:
732748
if variant_name.trim().is_empty() {
733749
panic!("unhandled enum variant: {:?}", wire_name)
734750
}
735-
if &variant_name.to_snake_case() != wire_name {
751+
if &variant_to_serde_snake_case(&variant_name) != wire_name {
736752
write_serde_rename(out, wire_name);
737753
}
738754
out.push_str(" ");

src/resources/generated/checkout_session.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4721,6 +4721,7 @@ impl std::default::Default for CheckoutUsBankAccountPaymentMethodOptionsVerifica
47214721
#[serde(rename_all = "snake_case")]
47224722
pub enum CreateCheckoutSessionAutomaticTaxLiabilityType {
47234723
Account,
4724+
#[serde(rename = "self")]
47244725
Self_,
47254726
}
47264727

@@ -5035,6 +5036,7 @@ impl std::default::Default for CreateCheckoutSessionCustomerUpdateShipping {
50355036
#[serde(rename_all = "snake_case")]
50365037
pub enum CreateCheckoutSessionInvoiceCreationInvoiceDataIssuerType {
50375038
Account,
5039+
#[serde(rename = "self")]
50385040
Self_,
50395041
}
50405042

@@ -7857,6 +7859,7 @@ impl std::default::Default for CreateCheckoutSessionShippingOptionsShippingRateD
78577859
#[serde(rename_all = "snake_case")]
78587860
pub enum CreateCheckoutSessionSubscriptionDataInvoiceSettingsIssuerType {
78597861
Account,
7862+
#[serde(rename = "self")]
78607863
Self_,
78617864
}
78627865

src/resources/generated/connect_account_reference.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct ConnectAccountReference {
2424
#[serde(rename_all = "snake_case")]
2525
pub enum ConnectAccountReferenceType {
2626
Account,
27+
#[serde(rename = "self")]
2728
Self_,
2829
}
2930

src/resources/generated/invoice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,7 @@ impl std::default::Default for CollectionMethod {
15551555
#[serde(rename_all = "snake_case")]
15561556
pub enum CreateInvoiceAutomaticTaxLiabilityType {
15571557
Account,
1558+
#[serde(rename = "self")]
15581559
Self_,
15591560
}
15601561

@@ -1621,6 +1622,7 @@ impl std::default::Default for CreateInvoiceFromInvoiceAction {
16211622
#[serde(rename_all = "snake_case")]
16221623
pub enum CreateInvoiceIssuerType {
16231624
Account,
1625+
#[serde(rename = "self")]
16241626
Self_,
16251627
}
16261628

src/resources/generated/issuing_card.rs

-2
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,6 @@ pub enum IssuingCardSpendingLimitCategories {
608608
HardwareStores,
609609
HealthAndBeautySpas,
610610
HearingAidsSalesAndSupplies,
611-
#[serde(rename = "heating_plumbing_a_c")]
612611
HeatingPlumbingAC,
613612
HobbyToyAndGameShops,
614613
HomeSupplyWarehouseStores,
@@ -737,7 +736,6 @@ pub enum IssuingCardSpendingLimitCategories {
737736
TruckUtilityTrailerRentals,
738737
TypesettingPlateMakingAndRelatedServices,
739738
TypewriterStores,
740-
#[serde(rename = "u_s_federal_government_agencies_or_departments")]
741739
USFederalGovernmentAgenciesOrDepartments,
742740
UniformsCommercialClothing,
743741
UsedMerchandiseAndSecondhandStores,

src/resources/generated/issuing_cardholder.rs

-2
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ pub enum IssuingCardholderSpendingLimitCategories {
510510
HardwareStores,
511511
HealthAndBeautySpas,
512512
HearingAidsSalesAndSupplies,
513-
#[serde(rename = "heating_plumbing_a_c")]
514513
HeatingPlumbingAC,
515514
HobbyToyAndGameShops,
516515
HomeSupplyWarehouseStores,
@@ -639,7 +638,6 @@ pub enum IssuingCardholderSpendingLimitCategories {
639638
TruckUtilityTrailerRentals,
640639
TypesettingPlateMakingAndRelatedServices,
641640
TypewriterStores,
642-
#[serde(rename = "u_s_federal_government_agencies_or_departments")]
643641
USFederalGovernmentAgenciesOrDepartments,
644642
UniformsCommercialClothing,
645643
UsedMerchandiseAndSecondhandStores,

src/resources/generated/payment_link.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,7 @@ impl std::default::Default for CreatePaymentLinkAfterCompletionType {
17881788
#[serde(rename_all = "snake_case")]
17891789
pub enum CreatePaymentLinkAutomaticTaxLiabilityType {
17901790
Account,
1791+
#[serde(rename = "self")]
17911792
Self_,
17921793
}
17931794

@@ -1996,6 +1997,7 @@ impl std::default::Default for CreatePaymentLinkCustomFieldsType {
19961997
#[serde(rename_all = "snake_case")]
19971998
pub enum CreatePaymentLinkInvoiceCreationInvoiceDataIssuerType {
19981999
Account,
2000+
#[serde(rename = "self")]
19992001
Self_,
20002002
}
20012003

@@ -2967,6 +2969,7 @@ impl std::default::Default for CreatePaymentLinkShippingAddressCollectionAllowed
29672969
#[serde(rename_all = "snake_case")]
29682970
pub enum CreatePaymentLinkSubscriptionDataInvoiceSettingsIssuerType {
29692971
Account,
2972+
#[serde(rename = "self")]
29702973
Self_,
29712974
}
29722975

@@ -4318,6 +4321,7 @@ impl std::default::Default for UpdatePaymentLinkAfterCompletionType {
43184321
#[serde(rename_all = "snake_case")]
43194322
pub enum UpdatePaymentLinkAutomaticTaxLiabilityType {
43204323
Account,
4324+
#[serde(rename = "self")]
43214325
Self_,
43224326
}
43234327

@@ -4420,6 +4424,7 @@ impl std::default::Default for UpdatePaymentLinkCustomFieldsType {
44204424
#[serde(rename_all = "snake_case")]
44214425
pub enum UpdatePaymentLinkInvoiceCreationInvoiceDataIssuerType {
44224426
Account,
4427+
#[serde(rename = "self")]
44234428
Self_,
44244429
}
44254430

@@ -5321,6 +5326,7 @@ impl std::default::Default for UpdatePaymentLinkShippingAddressCollectionAllowed
53215326
#[serde(rename_all = "snake_case")]
53225327
pub enum UpdatePaymentLinkSubscriptionDataInvoiceSettingsIssuerType {
53235328
Account,
5329+
#[serde(rename = "self")]
53245330
Self_,
53255331
}
53265332

src/resources/generated/subscription.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,7 @@ impl std::default::Default for CancellationDetailsReason {
19581958
#[serde(rename_all = "snake_case")]
19591959
pub enum CreateSubscriptionAutomaticTaxLiabilityType {
19601960
Account,
1961+
#[serde(rename = "self")]
19611962
Self_,
19621963
}
19631964

@@ -1992,6 +1993,7 @@ impl std::default::Default for CreateSubscriptionAutomaticTaxLiabilityType {
19921993
#[serde(rename_all = "snake_case")]
19931994
pub enum CreateSubscriptionInvoiceSettingsIssuerType {
19941995
Account,
1996+
#[serde(rename = "self")]
19951997
Self_,
19961998
}
19971999

@@ -3173,6 +3175,7 @@ impl std::default::Default for SubscriptionsResourcePaymentSettingsSaveDefaultPa
31733175
#[serde(rename_all = "snake_case")]
31743176
pub enum UpdateSubscriptionAutomaticTaxLiabilityType {
31753177
Account,
3178+
#[serde(rename = "self")]
31763179
Self_,
31773180
}
31783181

@@ -3253,6 +3256,7 @@ impl std::default::Default for UpdateSubscriptionCancellationDetailsFeedback {
32533256
#[serde(rename_all = "snake_case")]
32543257
pub enum UpdateSubscriptionInvoiceSettingsIssuerType {
32553258
Account,
3259+
#[serde(rename = "self")]
32563260
Self_,
32573261
}
32583262

src/resources/generated/subscription_schedule.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@ pub struct UpdateSubscriptionSchedulePhasesItemsPriceDataRecurring {
12871287
#[serde(rename_all = "snake_case")]
12881288
pub enum CreateSubscriptionSchedulePhasesAutomaticTaxLiabilityType {
12891289
Account,
1290+
#[serde(rename = "self")]
12901291
Self_,
12911292
}
12921293

@@ -1571,6 +1572,7 @@ impl std::default::Default for SubscriptionScheduleDefaultSettingsCollectionMeth
15711572
#[serde(rename_all = "snake_case")]
15721573
pub enum SubscriptionScheduleDefaultSettingsParamsAutomaticTaxLiabilityType {
15731574
Account,
1575+
#[serde(rename = "self")]
15741576
Self_,
15751577
}
15761578

@@ -1681,6 +1683,7 @@ impl std::default::Default for SubscriptionScheduleEndBehavior {
16811683
#[serde(rename_all = "snake_case")]
16821684
pub enum SubscriptionScheduleInvoiceSettingsIssuerType {
16831685
Account,
1686+
#[serde(rename = "self")]
16841687
Self_,
16851688
}
16861689

@@ -1789,6 +1792,7 @@ impl std::default::Default for SubscriptionScheduleStatus {
17891792
#[serde(rename_all = "snake_case")]
17901793
pub enum UpdateSubscriptionSchedulePhasesAutomaticTaxLiabilityType {
17911794
Account,
1795+
#[serde(rename = "self")]
17921796
Self_,
17931797
}
17941798

0 commit comments

Comments
 (0)