Skip to content

Commit 3463325

Browse files
committed
fix(dart): models empty sub_schema array scenario
1 parent 271e8d1 commit 3463325

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

templates/dart/lib/src/models/model.dart.twig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model
66
{% for property in definition.properties %}
77
/// {{ property.description }}
88
final {% if not property.required %}{{_self.sub_schema(property)}}? {{ property.name | escapeKeyword }}{% else %}{{_self.sub_schema(property)}} {{ property.name | escapeKeyword }}{% endif %};
9+
910
{% endfor %}
10-
{% if definition.additionalProperties %}
11+
{%~ if definition.additionalProperties %}
1112
final Map<String, dynamic> data;
12-
{% endif %}
1313

14+
{% endif %}
1415
{{ definition.name | caseUcfirst | overrideIdentifier}}({% if definition.properties | length or definition.additionalProperties %}{{ '{' }}{% endif %}
1516

1617
{% for property in definition.properties %}
@@ -33,7 +34,7 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model
3334
{%- endif -%}
3435
{%- else -%}
3536
{%- if property.type == 'array' -%}
36-
List<{{ property.items.type | caseUcfirst }}>.from(map['{{property.name | escapeDollarSign }}']?.map((x) => x{% if property.items.type == "string" %}.toString(){% endif %}) ?? [])
37+
List.from(map['{{property.name | escapeDollarSign }}'] ?? [])
3738
{%- else -%}
3839
map['{{property.name | escapeDollarSign }}']
3940
{%- if property.type == "number" -%}
@@ -76,4 +77,4 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model
7677
{% endfor %}
7778
{% endif %}
7879
{% endfor %}
79-
}
80+
}

0 commit comments

Comments
 (0)