[Dart] Fix enum generation#6729
Conversation
|
Dart doesnt support inner classes and test is failing because enum Easy solution to this would be to generate enum name as |
|
Imo this is ready now, @ircecho (2017/07) @swipesight (2018/09) @jaumard (2018/09) @nickmeinhold (2019/09) @athornz (2019/12) @amondnet (2019/12) @wing328 would it be possible to get this in the next release 5? Is there any specific roadmap? |
Yes, I think so. We'll release 5.0.0-beta to start with (hopefully this week). For the roadmap, please refer to https://github.com/OpenAPITools/openapi-generator/blob/master/docs/roadmap.md |
|
@wing328 Fixed conflicts |
|
Found a regression when non-required fields with default value aren't correctly generated. |
| return schema.getDefault().toString(); | ||
| } else { | ||
| return "null"; | ||
| return null; |
There was a problem hiding this comment.
This fixes not setting null value on properties that don't have default value. Dart is evolving to non-null by default language, so this will be important in the next releases of the language.
|
@wing328 opening back for review after correctly setting default value and removing null from default values. https://dart.dev/null-safety |
This comment has been minimized.
This comment has been minimized.
|
@wing328 can we have this merged please? |
|
Hi, I tested this PR with this https://github.com/geoDavey/osrm-openapi/blob/master/osrm-openapi.yaml OpenAPI specification. class IntersectionList<EntryEnum> {
/// The underlying value of this enum member.
final List<String> value;
const IntersectionList<EntryEnum>._internal(this.value);
static const IntersectionList<EntryEnum> true_ = IntersectionList<EntryEnum>._internal("true");
static const IntersectionList<EntryEnum> false_ = IntersectionList<EntryEnum>._internal("false");
List<String> toJson () {
return value;
}
@override
String toString () {
return value;
}
static IntersectionList<EntryEnum> fromJson(List<String> value) {
return IntersectionList<EntryEnum>TypeTransformer().decode(value);
}
static List<IntersectionList<EntryEnum>> listFromJson(List<dynamic> json) {
return json == null
? List<IntersectionList<EntryEnum>>()
: json.map((value) => IntersectionList<EntryEnum>.fromJson(value)).toList();
}
}
class IntersectionList<EntryEnum>TypeTransformer {
dynamic encode(IntersectionList<EntryEnum> data) {
return data.value;
}
IntersectionList<EntryEnum> decode(dynamic data) {
switch (data) {
case "true": return IntersectionList<EntryEnum>.true_;
case "false": return IntersectionList<EntryEnum>.false_;
default: return null;
}
}
}Could you have a look over it why it happens? Because some enum classes generation works. |
That's because allOf and anyOf aren't supported, and it worked (by letting code compiled by defaulting to null) by accident. reverted the breaking change. |
|
Tested again and the result looks good. |
PR checklist
./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/config/java*. For Windows users, please run the script in Git BASH.master@ircecho @swipesight @jaumard @athornz @amondnet
fixes #6727 #4974
Also fixes #3633 by removing default initialization to null.