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

Demonstrate backward-compatible deprecation of enums #92

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joshuaflanagan
Copy link
Contributor

I would like to get rid of using C# enums in the SDK. They unnecessarily constrain the
values that a user can send to the ShipEngine API. The API expects a string, the SDK
should allow the user to specify a string. An enum requires converting values to an integer,
which has no value for our purposes. It also leads to awkwardness when the default is 0,
which will correspond to an enum value we don't necessarily want. It requires the user
to update their SDK any time there is a new possible value accepted by the API.
We can still provide guidance for valid values via classes that expose static strings.

However, there is likely code in the wild where users are setting properties to an enum value.
This is an experiment to demonstrate using implicit conversion operators, and a custom JsonConverter,
to allow a user to set a "string enum" value using a string or an enum.

I would like to get rid of using C# enums in the SDK. They unnecessarily constrain the
values that a user can send to the ShipEngine API. The API expects a string, the SDK
should allow the user to specify a string. An enum requires converting values to an integer,
which has no value for our purposes. It also leads to awkwardness when the default is `0`,
which will correspond to an enum value we don't necessarily want. It requires the user
to update their SDK any time there is a new possible value accepted by the API.
We can still provide guidance for valid values via classes that expose static strings.

However, there is likely code in the wild where users are setting properties to an enum value.
This is an experiment to demonstrate using implicit conversion operators, and a custom JsonConverter,
to allow a user to set a "string enum" value using a string or an enum.
@coveralls
Copy link

coveralls commented Jun 25, 2024

Pull Request Test Coverage Report for Build 9670357484

Details

  • 46 of 58 (79.31%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.1%) to 84.271%

Changes Missing Coverage Covered Lines Changed/Added Lines %
ShipEngine/Models/Dto/CreateLabelFromShipmentDetails/StringEnum.cs 41 53 77.36%
Totals Coverage Status
Change from base Build 9486504073: -1.1%
Covered Lines: 690
Relevant Lines: 793

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants