From 96dd6c580674269e004a2ca840eea62873db880f Mon Sep 17 00:00:00 2001 From: 0xNF <0xNF@users.noreply.github.com> Date: Wed, 25 May 2022 12:58:45 +0900 Subject: [PATCH] [Dart] Fix incorrect generation of additionalProperties:true (#12165) (#12426) * Update samples Co-authored-by: 0xNF <0xNF> --- .../dart2/serialization/native/native_class.mustache | 7 ++++++- .../mixed_properties_and_additional_properties_class.dart | 2 +- .../petstore_client_lib_fake/lib/model/nullable_class.dart | 6 +++--- 3 files changed, 10 insertions(+), 5 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 7937e6fabe75..872dc9e8ee7c 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 @@ -171,7 +171,12 @@ class {{{classname}}} { {{/items.complexType}} {{/items.isMap}} {{^items.isMap}} - {{{name}}}: mapValueOfType<{{{datatypeWithEnum}}}>(json, r'{{{baseName}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}, + {{#items.complexType}} + {{{name}}}: {{{items.complexType}}}.mapFromJson(json[r'{{{baseName}}}'{{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}}]) ?? {{{.}}}{{/defaultValue}}{{/required}}, + {{/items.complexType}} + {{^items.complexType}} + {{{name}}}: mapCastOfType(json, r'{{{baseName}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}, + {{/items.complexType}} {{/items.isMap}} {{/items.isArray}} {{/isMap}} diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/mixed_properties_and_additional_properties_class.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/mixed_properties_and_additional_properties_class.dart index ce90481b6cd3..b281b0a0598b 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/mixed_properties_and_additional_properties_class.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/mixed_properties_and_additional_properties_class.dart @@ -85,7 +85,7 @@ class MixedPropertiesAndAdditionalPropertiesClass { return MixedPropertiesAndAdditionalPropertiesClass( uuid: mapValueOfType(json, r'uuid'), dateTime: mapDateTime(json, r'dateTime', ''), - map: mapValueOfType>(json, r'map') ?? const {}, + map: Animal.mapFromJson(json[r'map']) ?? const {}, ); } return null; diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/nullable_class.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/nullable_class.dart index 7dce3d71cf40..b8a0878b3056 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/nullable_class.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/nullable_class.dart @@ -152,9 +152,9 @@ class NullableClass { arrayNullableProp: Object.listFromJson(json[r'array_nullable_prop']) ?? const [], arrayAndItemsNullableProp: Object.listFromJson(json[r'array_and_items_nullable_prop']) ?? const [], arrayItemsNullable: Object.listFromJson(json[r'array_items_nullable']) ?? const [], - objectNullableProp: mapValueOfType>(json, r'object_nullable_prop') ?? const {}, - objectAndItemsNullableProp: mapValueOfType>(json, r'object_and_items_nullable_prop') ?? const {}, - objectItemsNullable: mapValueOfType>(json, r'object_items_nullable') ?? const {}, + objectNullableProp: mapCastOfType(json, r'object_nullable_prop') ?? const {}, + objectAndItemsNullableProp: mapCastOfType(json, r'object_and_items_nullable_prop') ?? const {}, + objectItemsNullable: mapCastOfType(json, r'object_items_nullable') ?? const {}, ); } return null;