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
Meaning that : none of my fields are required, and non of the fields in the JSON of the request can be null.
In other words, only fields that are set will be in the json, the unset fields will not be in the JSON object.
But using this yaml file, with Generator.dart, i'm given :
Map<String, dynamic> toJson() {
final json =<String, dynamic>{};
if (this.name !=null) {
json[r'name'] =this.name;
} else {
json[r'name'] =null;
}
I'm suposed to not have the else section, if the field this.nameis null, because it's not nullable (in JSON side) and not required.
Steps to reproduce
Use an openAPI yaml file with the above case, example :
Generate the API code with this yaml file withthe command flutter pub run build_runner build --delete-conflicting-outputs,
for example having somewhere :
If 'name' is null in my dart side, it should mean it is not set.
And as this fields is not required and not nullable, the JSON result should not get "else ..=null", but just :
Map<String, dynamic> toJson() {
final json =<String, dynamic>{};
if (this.name !=null) {
json[r'name'] =this.name;
}
Logs
No response
Screenshots
No response
Platform
Windows
Library version
5.0.2
Flutter version
3.16.9
Flutter channel
stable
Additional context
Maybe my understanding of OpenAPI is not good and the yaml file it wrong itself to describe the case of "only the fields set should be set in the resulting JSON", in this case, any help would be welcome :)
The text was updated successfully, but these errors were encountered:
Description of the bug
In my OpenAPI yaml file i've been given, a schema describes :
Meaning that : none of my fields are required, and non of the fields in the JSON of the request can be null.
In other words, only fields that are set will be in the json, the unset fields will not be in the JSON object.
But using this
yaml
file, withGenerator.dart
, i'm given :I'm suposed to not have the
else
section, if the field this.nameis null, because it's not nullable (in JSON side) and not required.Steps to reproduce
Use an openAPI yaml file with the above case, example :
Generate the API code with this yaml file withthe command
flutter pub run build_runner build --delete-conflicting-outputs
,for example having somewhere :
Expected behavior
If 'name' is null in my dart side, it should mean it is not set.
And as this fields is not required and not nullable, the JSON result should not get "else ..=null", but just :
Logs
No response
Screenshots
No response
Platform
Windows
Library version
5.0.2
Flutter version
3.16.9
Flutter channel
stable
Additional context
The text was updated successfully, but these errors were encountered: