-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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][dart-dio] Nullable support/improvements #8727
[dart][dart-dio] Nullable support/improvements #8727
Conversation
This is not in line with the OAS and will prevent future Dart nullabilty features (NNBD) from being useful as all types would be optional. Users can still opt-in for this.
* properties in built_value need to be nullable when they are nullable in OAS or when they are not required in OAS * built_value does not support serializing `null` values by default as it is based on a serialization format based on iterables/lists and not maps * dart-dio uses the built_value json plugin to convert the built_value format to regular json * by generating a custom serializer for each class we can add support for serializing `null` values if the property is required AND nullable in OAS * this is a breaking change as not all properties in the models are nullable by default anymore
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
@@ -40,7 +40,7 @@ | |||
|
|||
private static final String CLIENT_NAME = "clientName"; | |||
|
|||
private boolean nullableFields = true; |
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.
What do you think to move this to dart generator?
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.
I would rather deprecate this and get rid of it in 6.0 - we should not promote this going forward in with Dart/NNBD. I think this was more of a workaround for built_value. Maybe @josh-burton can say more to the original motivation.
@wing328 is there any other generator that supports not-null-by-default? @kuhnroyal Most languages are null-by-default, can this change potentially make dart-dio incompatible wither other generators without changes to spec file? I thought adding NNBD would be a bit simpler to start with, by just changing |
@agilob Kotlin is NNBD and basically the same as Dart in this regard. I have looked at the templates there and basically mirrored this with some adaptions for built_value. Basically everything that is nullable in OAS needs to be an optional type in Dart. Everything else should be non-null. Doing this with the current mutable models in the dart2 generator isn't great but possible, it should be straight forward for dart-dio. |
I would add a generator NNBD switch that defaults to true for 5.1.0 and allow users to set this to false. |
|
Follow-up for #8235 and a requirement for any move towards Dart NNBD in #8278
Fixes #5411
dart-dio/built_value
Disable all fields nullable by default:
This is not in line with OAS and will prevent future Dart nullabilty features (NNBD) from being useful as all types would be optional. This is a breaking change with fallback (set
nullableFields=true
).Properties are
@nullable
when nullable OR ( not required AND no defaultValue )Support nullable/required fields in JSON
@nullable
when they are nullable in OAS or when they are not required in OASnull
values by default as it is based on a serialization format based on iterables/lists and not mapsnull
values if the property is required AND nullable in OASDart
null
when the field is required and nullablePR checklist
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/configs/java*
.For Windows users, please run the script in Git BASH.
master
,5.1.x
,6.0.x
CC @swipesight (2018/09) @jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12)