Open matanlurey opened 5 years ago
Thanks. That makes sense. Will try to take a look at some point.
The use of a factory
constructor will currently cause the build_runner to throw an error, because only one constructor is expected.
However, this is just fine:
static Drink from(String name) {
final identity = _$DrinkSerializer._fromWire[name];
return valueOf(identity);
}
I'm not familiar enough with Dart at the moment to know if the factory
constructor has any inherent benefits over a static
method.
Any updates on this... i just want to get the exact enum-constant value without having to edit any generated EnumClass code (generated by openapi-generator)...
For example, here is the current behavior:
It would be nice, as an option, to use
wireName: ...
as the identity value:My rationale for this is for the web (and mobile, with deep linking), using hyphenated values is much more common (and easier to read and write). For example, If I wanted to see a recipe, I might visit
localhost/drinks/old-fashioned
, and it would be nice to doDrinks.valueOf('old-fashioned')
.I have found a (hacky) workaround, which is:
It works for my needs, but it's not perfect. Another option is allowing users to custom implement
valueOf
(i.e. I could moveDrink.from
toDrink.valueOf
).