Skip to content

Commit

Permalink
[Dart] Fix array of array nullable and non-nullable value generation (#…
Browse files Browse the repository at this point in the history
…13461)

* [Dart] Added non-invalid defaults for non nullable array of arrays (#13460)

* [Dart] Update samples
  • Loading branch information
0xNF authored Dec 27, 2022
1 parent efdc94b commit 341a853
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ class {{{classname}}} {
{{#isArray}}
{{#items.isArray}}
{{{name}}}: json[r'{{{baseName}}}'] is List
? (json[r'{{{baseName}}}'] as List).map(
? (json[r'{{{baseName}}}'] as List).map((e) =>
{{#items.complexType}}
{{items.complexType}}.listFromJson(json[r'{{{baseName}}}'])
{{items.complexType}}.listFromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}
{{/items.complexType}}
{{^items.complexType}}
(e) => e == null ? null : (e as List).cast<{{items.items.dataType}}>()
e == null ? {{#items.isNullable}}null{{/items.isNullable}}{{^items.isNullable}}const <{{items.items.dataType}}>[]{{/items.isNullable}} : (e as List).cast<{{items.items.dataType}}>()
{{/items.complexType}}
).toList()
: null,
: {{#isNullable}}null{{/isNullable}}{{^isNullable}}const []{{/isNullable}},
{{/items.isArray}}
{{^items.isArray}}
{{{name}}}: {{{complexType}}}.listFromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class ArrayOfArrayOfNumberOnly {

return ArrayOfArrayOfNumberOnly(
arrayArrayNumber: json[r'ArrayArrayNumber'] is List
? (json[r'ArrayArrayNumber'] as List).map(
(e) => e == null ? null : (e as List).cast<num>()
? (json[r'ArrayArrayNumber'] as List).map((e) =>
e == null ? const <num>[] : (e as List).cast<num>()
).toList()
: null,
: const [],
);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ class ArrayTest {
? (json[r'array_of_string'] as List).cast<String>()
: const [],
arrayArrayOfInteger: json[r'array_array_of_integer'] is List
? (json[r'array_array_of_integer'] as List).map(
(e) => e == null ? null : (e as List).cast<int>()
? (json[r'array_array_of_integer'] as List).map((e) =>
e == null ? const <int>[] : (e as List).cast<int>()
).toList()
: null,
: const [],
arrayArrayOfModel: json[r'array_array_of_model'] is List
? (json[r'array_array_of_model'] as List).map(
ReadOnlyFirst.listFromJson(json[r'array_array_of_model'])
? (json[r'array_array_of_model'] as List).map((e) =>
ReadOnlyFirst.listFromJson(json[r'array_array_of_model']) ?? const []
).toList()
: null,
: const [],
);
}
return null;
Expand Down

0 comments on commit 341a853

Please sign in to comment.