[BUG] [Dart-dio-next] Enums with numbers get parsed incorrectly
When I declare enums with underscore and number their name comes out incorrectly.
ExampleEnum:
title: "exampleEnum"
description: "Example enum"
type: "string"
enum:
- "EXAMPLE_ENUM_1"
- "EXAMPLE_ENUM_2"
- "EXAMPLE_ENUM_NO_NUMBER"
Output:
/// Example enum
@BuiltValueEnumConst(wireName: EXAMPLE_ENUM_1')
static const ExampleEnum eXAMPLEENUM1 = _$eXAMPLEENUM1;
/// Example enum
@BuiltValueEnumConst(wireName: EXAMPLE_ENUM_2')
static const ExampleEnum eXAMPLEENUM1 = _$eXAMPLEENUM2;
/// Example enum
@BuiltValueEnumConst(wireName: EXAMPLE_ENUM_NO_NUMBER')
static const ExampleEnum EXAMPLE_ENUM_NO_NUMBER = _$EXAMPLE_ENUM_NO_NUMBER;
We are seeing invalid code for enum generation i.e. code is syntactically broken. Here is an example we see:
switch (data.toString()) {
case 0: ...
case 1: ...
}
No wonder, this code fails to even build due to type errors. Removing toString() from all our enums fixes this issue, but is a PITA for a generated code.
Is there a workaround that we can follow here?
For reference and posterity, here is a screenshot of invalid code being generated
For posterity
find . -name "*_enum.dart" -exec sed -i '' "s/data.toString()/data/g" {} \;
^^^ Currently following workaround is necessary to achieve a working client.
but is a PITA for a generated code.
What do you mean by this? Removing toString() seems like the only valid solution.
but is a PITA for a generated code.
What do you mean by this? Removing
toString()seems like the only valid solution.
PITA == Pain In The Ass :)
We still have this hack in our Dart generation workflow.
Yeah I know what it means lol
What I meant to say was, Removing toString from the generator seems correct. What other possible solutions could exist?
Aah, oopsies :). No worries.
You are right. I don't know why is data.toString() even generated.
I am hoping this goes away so that we can remove the hack from our client generation workflows.
Hmm... could be a dumb question... but how do you get the wireName: EXAMPLE_ENUM_1 from the enumClass... the exact case-sensitive value EXAMPLE_ENUM_1...
For posterity
find . -name "*_enum.dart" -exec sed -i '' "s/data.toString()/data/g" {} \;^^^ Currently following workaround is necessary to achieve a working client.
Where should I run this cmd line? 'Cause the generated folder doesn't have any file matching the patter _enum.dart
Hmm... could be a dumb question... but how do you get the
wireName: EXAMPLE_ENUM_1from the enumClass... the exact case-sensitive value EXAMPLE_ENUM_1...
I have no idea. No one helped or fixed this