-
Notifications
You must be signed in to change notification settings - Fork 572
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
Better string enums #1675
Better string enums #1675
Conversation
4136fb6
to
1f3f135
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This looks super clean to me — and thanks for the detailed PR description explaining why.
Left one minor comment, but looks good to me otherwise.
ptal @ob-stripe
1f3f135
to
63c4a28
Compare
63c4a28
to
499601c
Compare
499601c
to
4eb15b9
Compare
Added comments, ptal @brandur-stripe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments looks great. Thanks!
* Better string enums (#1675) * Init options with default parameter values (#1699) * Remove multiple deprecated features (#1713) Many features were marked as obsolete and are now being removed: * AccountBalance on Customer, use Balance instead * Billing on Subscription/Invoice/SubscriptionSchedule, use CollectionMethod instead * TaxInfo and TaxInfoVerification on Customer, use TaxId instead * AllowedSourceTypes on PaymentIntent, use PaymentMethodTypes instead * Start on Subscription, use StartDate instead * ApplicationFee on Charge, use ApplicationFeeAmount instead * Date when listing Invoices, use Created instead * OperatorAccount on all Terminal APIs * Remove all Expand* fields (#1715) * Use properl SetupIntent class * Removed Id and FileId suffixes to stay as close to the API as possible. (#1738) * Add a test to ensure that JSON names match property names (#1744) * A few more renames (#1739) * Remove dead code for service expansions (#1751) * Bump Stylecop.Analyzers to latest version (#1752) * Bump SourceLink and create symbol package (#1755) * Fix all classes not inheriting from the generic version of StripeEntity * Add a wholesome test to ensure proper JSON converters are applied (#1761) * Remove more deprecated stuff (#1802) * Remove more Id/FileId suffixes (#1803) * One more rename (#1805) * Fix ExternalAccountUpdateOptions (#1806) * Rename AccountOpener to Representative and move to latest API version * Enable test for JSON<->property name consistency (#1804)
r? @brandur-stripe
cc @stripe/api-libraries
Right now we're using regular
enum
s for a few special values, likePlanTierUpTo.Inf
.The issue with this approach is that
enum
are really integers, but in our case it's not desirable to have a conversion betweenenum
andint
. This is especially true forPlanTierUpTo
, becausePlanTierOptions.UpTo
is defined asAnyOf<long?, PlanTierUpTo?>
. If for some reason thePlanTierUpTo
is implicitly or explicitly converted tolong
, then the value will be accepted and sent as an int instead of a string in the request, leading to unexpected results (cf. #1674).This PR shows a possible solution: stop using
enum
s and instead use regular classes with a private constructor and the possible values as static properties. This is technically a breaking change because of the type change, but the impact on users should be very minimal because the syntax doesn't change: you can still usePlanTierUpTo.Inf
just like before.