Skip to content

Commit fc6d378

Browse files
authored
Merge pull request #1202 from appwrite/fix-dart-any-model
2 parents a304270 + d71fdd3 commit fc6d378

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

templates/android/library/src/main/java/io/package/models/Model.kt.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import io.appwrite.extensions.jsonCast
6464
{{ property.name | escapeKeyword | removeDollarSign }} = {% if property.sub_schema %}{% if property.type == 'array' %}(map["{{ property.name | escapeDollarSign }}"] as List<Map<String, Any>>).map { {{ property.sub_schema | caseUcfirst }}.from(map = it{% if property.sub_schema | hasGenericType(spec) %}, nestedType{% endif %}) }{% else %}{{ property.sub_schema | caseUcfirst }}.from(map = map["{{property.name | escapeDollarSign }}"] as Map<String, Any>{% if property.sub_schema | hasGenericType(spec) %}, nestedType{% endif %}){% endif %}{% else %}{% if property.type == "integer" or property.type == "number" %}({% endif %}map["{{ property.name | escapeDollarSign }}"]{% if property.type == "integer" or property.type == "number" %} as{% if not property.required %}?{% endif %} Number){% endif %}{% if property.type == "integer" %}{% if not property.required %}?{% endif %}.toLong(){% elseif property.type == "number" %}{% if not property.required %}?{% endif %}.toDouble(){% else %} as{% if not property.required %}?{% endif %} {{ property | propertyType(spec) | raw }}{% endif %}{% endif %},
6565
{%~ endfor %}
6666
{%~ if definition.additionalProperties %}
67-
data = map.jsonCast(to = nestedType)
67+
data = map["data"]?.jsonCast(to = nestedType) ?: map.jsonCast(to = nestedType)
6868
{%~ endif %}
6969
)
7070
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model
4747
{%- endif -%},
4848
{% endfor %}
4949
{% if definition.additionalProperties %}
50-
data: map,
50+
data: map["data"] ?? map,
5151
{% endif %}
5252
);
5353
}

templates/dotnet/Package/Models/Model.cs.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace {{ spec.title | caseUcfirst }}.Models
6969
{%~ endif %}
7070
{%~ endfor %}
7171
{%- if definition.additionalProperties %}
72-
data: map
72+
data: map.TryGetValue("data", out var dataValue) ? (Dictionary<string, object>)dataValue : map
7373
{%- endif ~%}
7474
);
7575

templates/kotlin/src/main/kotlin/io/appwrite/models/Model.kt.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import io.appwrite.extensions.jsonCast
6464
{{ property.name | escapeKeyword | removeDollarSign }} = {% if property.sub_schema %}{% if property.type == 'array' %}(map["{{ property.name | escapeDollarSign }}"] as List<Map<String, Any>>).map { {{ property.sub_schema | caseUcfirst }}.from(map = it{% if property.sub_schema | hasGenericType(spec) %}, nestedType{% endif %}) }{% else %}{{ property.sub_schema | caseUcfirst }}.from(map = map["{{property.name | escapeDollarSign }}"] as Map<String, Any>{% if property.sub_schema | hasGenericType(spec) %}, nestedType{% endif %}){% endif %}{% else %}{% if property.type == "integer" or property.type == "number" %}({% endif %}map["{{ property.name | escapeDollarSign }}"]{% if property.type == "integer" or property.type == "number" %} as{% if not property.required %}?{% endif %} Number){% endif %}{% if property.type == "integer" %}{% if not property.required %}?{% endif %}.toLong(){% elseif property.type == "number" %}{% if not property.required %}?{% endif %}.toDouble(){% else %} as{% if not property.required %}?{% endif %} {{ property | propertyType(spec) | raw }}{% endif %}{% endif %},
6565
{%~ endfor %}
6666
{%~ if definition.additionalProperties %}
67-
data = map.jsonCast(to = nestedType)
67+
data = map["data"]?.jsonCast(to = nestedType) ?: map.jsonCast(to = nestedType)
6868
{%~ endif %}
6969
)
7070
}

templates/ruby/lib/container/models/model.rb.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module {{ spec.title | caseUcfirst }}
3535

3636
{% endfor %}
3737
{% if definition.additionalProperties %}
38-
data: map
38+
data: map["data"] || map
3939
{% endif %}
4040
)
4141
end

templates/swift/Sources/Models/Model.swift.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ open class {{ definition | modelType(spec) | raw }}: Codable {
9898

9999
{%~ endfor %}
100100
{%~ if definition.additionalProperties %}
101-
data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: []))
101+
data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map["data"] as? [String: Any] ?? map, options: []))
102102
{%~ endif %}
103103
)
104104
}

0 commit comments

Comments
 (0)