From 341a8535c75cbf2a42f3e9bd781dbdf1c327b629 Mon Sep 17 00:00:00 2001 From: 0xNF <0xNF@users.noreply.github.com> Date: Wed, 28 Dec 2022 01:01:08 +0900 Subject: [PATCH] [Dart] Fix array of array nullable and non-nullable value generation (#13461) * [Dart] Added non-invalid defaults for non nullable array of arrays (#13460) * [Dart] Update samples --- .../dart2/serialization/native/native_class.mustache | 8 ++++---- .../lib/model/array_of_array_of_number_only.dart | 6 +++--- .../lib/model/array_test.dart | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache b/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache index dd656c53e709..cde87e7d9831 100644 --- a/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache @@ -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}}, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_of_array_of_number_only.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_of_array_of_number_only.dart index 99f89a1ee20d..5127b4ec1b95 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_of_array_of_number_only.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_of_array_of_number_only.dart @@ -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() + ? (json[r'ArrayArrayNumber'] as List).map((e) => + e == null ? const [] : (e as List).cast() ).toList() - : null, + : const [], ); } return null; diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_test.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_test.dart index c0b262e7d2d0..fea02b3ae8a4 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_test.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_test.dart @@ -71,15 +71,15 @@ class ArrayTest { ? (json[r'array_of_string'] as List).cast() : 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() + ? (json[r'array_array_of_integer'] as List).map((e) => + e == null ? const [] : (e as List).cast() ).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;