You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a problem with the generated dart code for enums, as those enums in the openapi.json file, where the enum value is a special character, like %, will end up in the generated dart code with the name _.
openapi-generator version
4.3.1
Support file contents
The openapi.json file content is shown below. The part of the specification that results in the problematic dart code is components/schemas/PercentileUnit/enum.
The generated percentile_unit.dart model file that has an issue is the following:
part of PeekAMooOpenAPI.api;
classPercentileUnit {
/// The underlying value of this enum member.finalString value;
constPercentileUnit._internal(this.value);
/// An enumeration.staticconstPercentileUnit _ =constPercentileUnit._internal("%");
staticPercentileUnitfromJson(String value) {
returnnewPercentileUnitTypeTransformer().decode(value);
}
staticList<PercentileUnit> listFromJson(List<dynamic> json) {
return json ==null?newList<PercentileUnit>() : json.map((value) =>PercentileUnit.fromJson(value)).toList();
}
}
classPercentileUnitTypeTransformer {
dynamicencode(PercentileUnit data) {
return data.value;
}
PercentileUnitdecode(dynamic data) {
switch (data) {
case"%":returnPercentileUnit._;
default:throw('Unknown enum value to decode: $data');
}
}
}
The problem I have with the code above:
/// An enumeration.staticconstPercentileUnit _ =constPercentileUnit._internal("%");
Dart code outside the generated dart package cannot reference enume value with PercentileUnit._. Somehow special characters, like % should be translated to a string, that can be used as valid parameter name in Dart, because currently the special characters are translated to an empty string. Most likely the problem is with the content of {{{name}}} in
Execute shell command written above, using the support files included above, then check the generated dart code in .\peekamoo-openapi\lib\model\percentile_unit.dart.
Bug Report Checklist
Description
There is a problem with the generated dart code for enums, as those enums in the openapi.json file, where the enum value is a special character, like %, will end up in the generated dart code with the name
_
.openapi-generator version
4.3.1
Support file contents
The openapi.json file content is shown below. The part of the specification that results in the problematic dart code is
components/schemas/PercentileUnit/enum
.The flutterconfig-dart.json file is the following:
The generated percentile_unit.dart model file that has an issue is the following:
The problem I have with the code above:
Dart code outside the generated dart package cannot reference enume value with
PercentileUnit._
. Somehow special characters, like%
should be translated to a string, that can be used as valid parameter name in Dart, because currently the special characters are translated to an empty string. Most likely the problem is with the content of {{{name}}} inopenapi-generator/modules/openapi-generator/src/main/resources/dart/enum.mustache
Line 13 in b609157
openapi-generator/modules/openapi-generator/src/main/resources/dart/enum.mustache
Line 30 in b609157
Generation Details
The Dart code is generated on Windows with the following shell command.
Steps to reproduce
Execute shell command written above, using the support files included above, then check the generated dart code in
.\peekamoo-openapi\lib\model\percentile_unit.dart
.Related issues/PRs
none
Suggest a fix
The content of {{{name}}} in
openapi-generator/modules/openapi-generator/src/main/resources/dart/enum.mustache
Line 13 in b609157
openapi-generator/modules/openapi-generator/src/main/resources/dart/enum.mustache
Line 30 in b609157
_
when the enum value is a special character.The text was updated successfully, but these errors were encountered: