diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index e40ebac3940..c6289c2b766 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -176,7 +176,7 @@ class {{{classname}}} { final responseBody = await _decodeBodyBytes(response); return (await apiClient.deserializeAsync(responseBody, '{{{returnType}}}') as List) .cast<{{{returnBaseType}}}>() - .{{#uniqueItems}}toSet(){{/uniqueItems}}{{^uniqueItems}}toList(){{/uniqueItems}}; + .{{#uniqueItems}}toSet(){{/uniqueItems}}{{^uniqueItems}}toList(growable: false){{/uniqueItems}}; {{/isArray}} {{^isArray}} {{#isMap}} 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 a8dc4df18f7..a8a6273cf28 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 @@ -86,7 +86,7 @@ class {{{classname}}} { {{/isDate}} {{^isDateTime}} {{^isDate}} - json[r'{{{baseName}}}'] = this.{{{name}}}; + json[r'{{{baseName}}}'] = this.{{{name}}}{{#isArray}}{{#uniqueItems}}{{#isNullable}}!{{/isNullable}}.toList(growable: false){{/uniqueItems}}{{/isArray}}; {{/isDate}} {{/isDateTime}} {{#isNullable}} @@ -200,8 +200,8 @@ class {{{classname}}} { {{{name}}}: {{{items.datatypeWithEnum}}}.listFromJson(json[r'{{{baseName}}}']){{#uniqueItems}}.toSet(){{/uniqueItems}}, {{/isEnum}} {{^isEnum}} - {{{name}}}: json[r'{{{baseName}}}'] is {{#uniqueItems}}Set{{/uniqueItems}}{{^uniqueItems}}List{{/uniqueItems}} - ? (json[r'{{{baseName}}}'] as {{#uniqueItems}}Set{{/uniqueItems}}{{^uniqueItems}}List{{/uniqueItems}}).cast<{{{items.datatype}}}>() + {{{name}}}: json[r'{{{baseName}}}'] is Iterable + ? (json[r'{{{baseName}}}'] as Iterable).cast<{{{items.datatype}}}>().{{#uniqueItems}}toSet(){{/uniqueItems}}{{^uniqueItems}}toList(growable: false){{/uniqueItems}} : {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}, {{/isEnum}} {{/isArray}} diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index d0354de38db..68cb08b13e9 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -190,7 +190,7 @@ class PetApi { final responseBody = await _decodeBodyBytes(response); return (await apiClient.deserializeAsync(responseBody, 'List') as List) .cast() - .toList(); + .toList(growable: false); } return null; @@ -253,7 +253,7 @@ class PetApi { final responseBody = await _decodeBodyBytes(response); return (await apiClient.deserializeAsync(responseBody, 'List') as List) .cast() - .toList(); + .toList(growable: false); } return null; diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart index 53a2d20dcec..a8e54d9920f 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart @@ -113,8 +113,8 @@ class Pet { id: mapValueOfType(json, r'id'), category: Category.fromJson(json[r'category']), name: mapValueOfType(json, r'name')!, - photoUrls: json[r'photoUrls'] is List - ? (json[r'photoUrls'] as List).cast() + photoUrls: json[r'photoUrls'] is Iterable + ? (json[r'photoUrls'] as Iterable).cast().toList(growable: false) : const [], tags: Tag.listFromJson(json[r'tags']), status: PetStatusEnum.fromJson(json[r'status']), diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart index 371afa625cf..2f49efb4c3f 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart @@ -182,7 +182,7 @@ class PetApi { final responseBody = await _decodeBodyBytes(response); return (await apiClient.deserializeAsync(responseBody, 'List') as List) .cast() - .toList(); + .toList(growable: false); } return null; diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_of_number_only.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_of_number_only.dart index 65a8d4b14d1..9275a619a5a 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_of_number_only.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/array_of_number_only.dart @@ -55,8 +55,8 @@ class ArrayOfNumberOnly { }()); return ArrayOfNumberOnly( - arrayNumber: json[r'ArrayNumber'] is List - ? (json[r'ArrayNumber'] as List).cast() + arrayNumber: json[r'ArrayNumber'] is Iterable + ? (json[r'ArrayNumber'] as Iterable).cast().toList(growable: false) : const [], ); } 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 1d4114defe6..282d225cfa6 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 @@ -67,8 +67,8 @@ class ArrayTest { }()); return ArrayTest( - arrayOfString: json[r'array_of_string'] is List - ? (json[r'array_of_string'] as List).cast() + arrayOfString: json[r'array_of_string'] is Iterable + ? (json[r'array_of_string'] as Iterable).cast().toList(growable: false) : const [], arrayArrayOfInteger: json[r'array_array_of_integer'] is List ? (json[r'array_array_of_integer'] as List).map((e) => diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_deprecated_fields.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_deprecated_fields.dart index 2e2e2b7c687..91932b3bc41 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_deprecated_fields.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_deprecated_fields.dart @@ -108,8 +108,8 @@ class ObjectWithDeprecatedFields { ? null : num.parse(json[r'id'].toString()), deprecatedRef: DeprecatedObject.fromJson(json[r'deprecatedRef']), - bars: json[r'bars'] is List - ? (json[r'bars'] as List).cast() + bars: json[r'bars'] is Iterable + ? (json[r'bars'] as Iterable).cast().toList(growable: false) : const [], ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart index 669bf85edd5..9e0c77e120b 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart @@ -81,7 +81,7 @@ class Pet { json[r'category'] = null; } json[r'name'] = this.name; - json[r'photoUrls'] = this.photoUrls; + json[r'photoUrls'] = this.photoUrls.toList(growable: false); json[r'tags'] = this.tags; if (this.status != null) { json[r'status'] = this.status; @@ -113,8 +113,8 @@ class Pet { id: mapValueOfType(json, r'id'), category: Category.fromJson(json[r'category']), name: mapValueOfType(json, r'name')!, - photoUrls: json[r'photoUrls'] is Set - ? (json[r'photoUrls'] as Set).cast() + photoUrls: json[r'photoUrls'] is Iterable + ? (json[r'photoUrls'] as Iterable).cast().toSet() : const {}, tags: Tag.listFromJson(json[r'tags']), status: PetStatusEnum.fromJson(json[r'status']),