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

Better string enums #1675

Merged
merged 1 commit into from
Jul 5, 2019
Merged

Better string enums #1675

merged 1 commit into from
Jul 5, 2019

Conversation

ob-stripe
Copy link
Contributor

@ob-stripe ob-stripe commented Jun 21, 2019

r? @brandur-stripe
cc @stripe/api-libraries

Right now we're using regular enums for a few special values, like PlanTierUpTo.Inf.

The issue with this approach is that enum are really integers, but in our case it's not desirable to have a conversion between enum and int. This is especially true for PlanTierUpTo, because PlanTierOptions.UpTo is defined as AnyOf<long?, PlanTierUpTo?>. If for some reason the PlanTierUpTo is implicitly or explicitly converted to long, 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 enums 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 use PlanTierUpTo.Inf just like before.

@ob-stripe ob-stripe changed the title [wip] Better string enums Better string enums Jul 5, 2019
Copy link
Contributor

@brandur-stripe brandur-stripe left a 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

src/Stripe.net/Services/_base/StringEnum.cs Show resolved Hide resolved
@stripe-ci stripe-ci assigned ob-stripe and unassigned brandur-stripe Jul 5, 2019
@ob-stripe ob-stripe changed the base branch from master to integration-v28 July 5, 2019 18:19
@ob-stripe
Copy link
Contributor Author

Added comments, ptal @brandur-stripe

@ob-stripe ob-stripe assigned brandur-stripe and unassigned ob-stripe Jul 5, 2019
Copy link
Contributor

@brandur-stripe brandur-stripe left a 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!

@stripe-ci stripe-ci assigned ob-stripe and unassigned brandur-stripe Jul 5, 2019
@ob-stripe ob-stripe merged commit 07e57d5 into integration-v28 Jul 5, 2019
@ob-stripe ob-stripe deleted the ob-string-enums branch July 5, 2019 21:55
@ob-stripe ob-stripe mentioned this pull request Jul 5, 2019
19 tasks
@ghost ghost mentioned this pull request Jul 11, 2019
ob-stripe added a commit that referenced this pull request Jul 18, 2019
remi-stripe pushed a commit that referenced this pull request Jul 19, 2019
remi-stripe pushed a commit that referenced this pull request Aug 12, 2019
ob-stripe added a commit that referenced this pull request Aug 16, 2019
ob-stripe added a commit that referenced this pull request Sep 30, 2019
ob-stripe added a commit that referenced this pull request Oct 7, 2019
ob-stripe added a commit that referenced this pull request Oct 8, 2019
ob-stripe added a commit that referenced this pull request Oct 9, 2019
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants