From 434c31addecf3dfcb0668acf0f3fd1b5b551bb61 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:29:08 +0000 Subject: [PATCH 1/2] fix: cast string arrays --- templates/dart/lib/src/models/model.dart.twig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/templates/dart/lib/src/models/model.dart.twig b/templates/dart/lib/src/models/model.dart.twig index 3ce581e20..775d18910 100644 --- a/templates/dart/lib/src/models/model.dart.twig +++ b/templates/dart/lib/src/models/model.dart.twig @@ -39,8 +39,12 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model {%- if property.type == "string" -%} {%- if not property.required %}?{% endif %}.toString() {%- endif -%} - {%- if property.type == "array" -%} - {% if property.required %} ?? []{% endif %} + {%- if property.type == 'array' -%} + {%- if property.sub_schema -%} + List<{{property.sub_schema | caseUcfirst | overrideIdentifier}}>.from(map['{{property.name | escapeDollarSign }}'].map((p) => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(p))) + {%- else -%} + List<{{ property | typeNameInner }}>.from(map['{{property.name | escapeDollarSign }}']?.map((x) => x{% if property.items.type == "string" %}.toString(){% endif %}) ?? []) + {%- endif -%} {%- endif -%} {%- endif -%}, {% endfor %} From 5d4e932cce9656e8ff7b776683e72a1d79d9c681 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:51:44 +0000 Subject: [PATCH 2/2] fix: template --- templates/dart/lib/src/models/model.dart.twig | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/templates/dart/lib/src/models/model.dart.twig b/templates/dart/lib/src/models/model.dart.twig index 775d18910..33c81d923 100644 --- a/templates/dart/lib/src/models/model.dart.twig +++ b/templates/dart/lib/src/models/model.dart.twig @@ -32,18 +32,15 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model {{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(map['{{property.name | escapeDollarSign }}']) {%- endif -%} {%- else -%} - map['{{property.name | escapeDollarSign }}'] - {%- if property.type == "number" -%} - {%- if not property.required %}?{% endif %}.toDouble() - {%- endif -%} - {%- if property.type == "string" -%} - {%- if not property.required %}?{% endif %}.toString() - {%- endif -%} {%- if property.type == 'array' -%} - {%- if property.sub_schema -%} - List<{{property.sub_schema | caseUcfirst | overrideIdentifier}}>.from(map['{{property.name | escapeDollarSign }}'].map((p) => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(p))) - {%- else -%} - List<{{ property | typeNameInner }}>.from(map['{{property.name | escapeDollarSign }}']?.map((x) => x{% if property.items.type == "string" %}.toString(){% endif %}) ?? []) + List<{{ property.items.type | caseUcfirst }}>.from(map['{{property.name | escapeDollarSign }}']?.map((x) => x{% if property.items.type == "string" %}.toString(){% endif %}) ?? []) + {%- else -%} + map['{{property.name | escapeDollarSign }}'] + {%- if property.type == "number" -%} + {%- if not property.required %}?{% endif %}.toDouble() + {%- endif -%} + {%- if property.type == "string" -%} + {%- if not property.required %}?{% endif %}.toString() {%- endif -%} {%- endif -%} {%- endif -%}, @@ -79,4 +76,4 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model {% endfor %} {% endif %} {% endfor %} -} +} \ No newline at end of file