Skip to content

Commit 6ab3025

Browse files
authored
Merge pull request #339 from appwrite/fix-kotlin-android-number-properties
Replace Kotlin + Android number casting with conversion
2 parents dd7a773 + 8e11912 commit 6ab3025

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ data class {{ definition.name | caseUcfirst }}(
2121
@Suppress("UNCHECKED_CAST")
2222
fun from(map: Map<String, Any>) = {{ definition.name | caseUcfirst }}(
2323
{% for property in definition.properties %}
24-
{{ 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) }{% else %}{{property.sub_schema | caseUcfirst}}.from(map = map["{{property.name | escapeDollarSign }}"] as Map<String, Any>){% endif %}{% else %}map["{{ property.name | escapeDollarSign }}"] as{% if not property.required %}?{% endif %} {{ _self.sub_schema(property) }}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %}
24+
{{ 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) }{% else %}{{property.sub_schema | caseUcfirst}}.from(map = map["{{property.name | escapeDollarSign }}"] as Map<String, Any>){% endif %}{% else %}{% if property.type == "integer" or property.type == "number" %}({% endif %}map["{{ property.name | escapeDollarSign }}"]{% if property.type == "integer" or property.type == "number" %} as Number){% endif %}{% if property.type == "integer" %}.toLong(){% elseif property.type == "number" %}.toDouble(){% else %} as{% if not property.required %}?{% endif %} {{ _self.sub_schema(property) }}{% endif %}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %}
2525

2626
{% endfor %}
2727
{% if definition.additionalProperties %}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
{% macro sub_schema(property) %}{% if property.sub_schema %}{% if property.type == 'array' %}List<{{property.sub_schema | caseUcfirst}}>{% else %}{{property.sub_schema | caseUcfirst}}{% endif %}{% else %}{{property.type | typeName}}{% endif %}{% endmacro %}
22
package {{ sdk.namespace | caseDot }}.models
33

4-
/// {{ definition.description }}
4+
/**
5+
* {{ definition.description }}
6+
*/
57
data class {{ definition.name | caseUcfirst }}(
68
{% for property in definition.properties %}
7-
{% if property.required %}val{% else%}var{% endif %} {{ property.name | escapeKeyword | removeDollarSign }}: {{_self.sub_schema(property)}}{% if not property.required %}?{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %}
9+
/**
10+
* {{ property.description }}
11+
*
12+
*/
13+
{% if property.required %}val{% else%}var{% endif %} {{ property.name | escapeKeyword | removeDollarSign }}: {{_self.sub_schema(property)}}{% if not property.required %}?{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{{ "\n" }}{% endif %}
814

915
{% endfor %}
1016
{% if definition.additionalProperties %}
1117
val data: Map<String, Any>
1218
{% endif %}
1319
) {
1420
companion object {
21+
@Suppress("UNCHECKED_CAST")
1522
fun from(map: Map<String, Any>) = {{ definition.name | caseUcfirst }}(
1623
{% for property in definition.properties %}
17-
{{ 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) }{% else %}{{property.sub_schema | caseUcfirst}}.from(map = map["{{property.name | escapeDollarSign }}"] as Map<String, Any>){% endif %}{% else %}map["{{ property.name | escapeDollarSign }}"] as{% if not property.required %}?{% endif %} {{ _self.sub_schema(property) }}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %}
24+
{{ 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) }{% else %}{{property.sub_schema | caseUcfirst}}.from(map = map["{{property.name | escapeDollarSign }}"] as Map<String, Any>){% endif %}{% else %}{% if property.type == "integer" or property.type == "number" %}({% endif %}map["{{ property.name | escapeDollarSign }}"]{% if property.type == "integer" or property.type == "number" %} as Number){% endif %}{% if property.type == "integer" %}.toLong(){% elseif property.type == "number" %}.toDouble(){% else %} as{% if not property.required %}?{% endif %} {{ _self.sub_schema(property) }}{% endif %}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %}
1825

1926
{% endfor %}
2027
{% if definition.additionalProperties %}

0 commit comments

Comments
 (0)