-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[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. |
@@ -414,7 +416,7 @@ public String toDefaultValue(Schema schema) { | |||
} | |||
return schema.getDefault().toString(); | |||
} else { | |||
return "null"; | |||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
samples/client/petstore/dart/flutter_petstore/openapi/lib/model/api_response.dart
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
@wing328 can we have this merged please? |
...openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java
Show resolved
Hide resolved
samples/client/petstore/dart/flutter_petstore/openapi/lib/model/user.dart
Outdated
Show resolved
Hide resolved
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. |
modules/openapi-generator/src/main/resources/dart2/class.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/dart2/enum.mustache
Outdated
Show resolved
Hide resolved
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.sh
to 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.