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.
{
"openapi": "3.0.2",
"info": {
"title": "FastAPI",
"version": "0.1.0"
},
"paths": {
"/enum/": {
"get": {
"tags": [
"Administration"
],
"summary": "Test Enum",
"description": "Test get enum.",
"operationId": "test_enum_enum__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PercentileValue"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"PercentileUnit": {
"title": "PercentileUnit",
"enum": [
"%"
],
"type": "string",
"description": "An enumeration."
},
"PercentileValue": {
"title": "PercentileValue",
"required": [
"unit",
"value"
],
"type": "object",
"properties": {
"unit": {
"$ref": "#/components/schemas/PercentileUnit"
},
"value": {
"title": "Value",
"maximum": 97,
"minimum": 3,
"type": "number",
"description": "Value of the percentile."
}
}
}
}
}
}
The flutterconfig-dart.json file is the following:
{
"pubAuthor": "Agent Moo",
"pubDescription": "Security level BBR (Burn Before Read)",
"pubName": "PeekAMooOpenAPI",
"browserClient": false,
"useEnumExtension": true
}
The generated percentile_unit.dart model file that has an issue is the following:
part of PeekAMooOpenAPI.api;
class PercentileUnit {
/// The underlying value of this enum member.
final String value;
const PercentileUnit._internal(this.value);
/// An enumeration.
static const PercentileUnit _ = const PercentileUnit._internal("%");
static PercentileUnit fromJson(String value) {
return new PercentileUnitTypeTransformer().decode(value);
}
static List<PercentileUnit> listFromJson(List<dynamic> json) {
return json == null ? new List<PercentileUnit>() : json.map((value) => PercentileUnit.fromJson(value)).toList();
}
}
class PercentileUnitTypeTransformer {
dynamic encode(PercentileUnit data) {
return data.value;
}
PercentileUnit decode(dynamic data) {
switch (data) {
case "%": return PercentileUnit._;
default: throw('Unknown enum value to decode: $data');
}
}
}
The problem I have with the code above:
/// An enumeration.
static const PercentileUnit _ = const PercentileUnit._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
|
static const {{classname}} {{{name}}} = const {{classname}}._internal({{{value}}}); |
and in
|
case {{{value}}}: return {{classname}}.{{{name}}}; |
.
Generation Details
The Dart code is generated on Windows with the following shell command.
java -jar openapi-generator-cli-4.3.1.jar generate -i .\openapi.json -g dart -o .\peekamoo-openapi -c flutterconfig-dart.json
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
|
static const {{classname}} {{{name}}} = const {{classname}}._internal({{{value}}}); |
and in
|
case {{{value}}}: return {{classname}}.{{{name}}}; |
should not be simply
_ when the enum value is a special character.
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.{ "openapi": "3.0.2", "info": { "title": "FastAPI", "version": "0.1.0" }, "paths": { "/enum/": { "get": { "tags": [ "Administration" ], "summary": "Test Enum", "description": "Test get enum.", "operationId": "test_enum_enum__get", "responses": { "200": { "description": "Successful Response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PercentileValue" } } } } } } } }, "components": { "schemas": { "PercentileUnit": { "title": "PercentileUnit", "enum": [ "%" ], "type": "string", "description": "An enumeration." }, "PercentileValue": { "title": "PercentileValue", "required": [ "unit", "value" ], "type": "object", "properties": { "unit": { "$ref": "#/components/schemas/PercentileUnit" }, "value": { "title": "Value", "maximum": 97, "minimum": 3, "type": "number", "description": "Value of the percentile." } } } } } }The flutterconfig-dart.json file is the following:
{ "pubAuthor": "Agent Moo", "pubDescription": "Security level BBR (Burn Before Read)", "pubName": "PeekAMooOpenAPI", "browserClient": false, "useEnumExtension": true }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.