ShipEngine / shipengine-dotnet

The official ShipEngine SDK for C# and the .NET Framework
https://www.shipengine.com/docs/
Apache License 2.0
11 stars 11 forks source link

Demonstrate backward-compatible deprecation of enums #92

Open joshuaflanagan opened 4 months ago

joshuaflanagan commented 4 months ago

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 commented 4 months ago

Pull Request Test Coverage Report for Build 9670357484

Details


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

💛 - Coveralls