Merge pull request #28 from TouchInstinct/fix/update_swift_templates
swift templates fixes
This commit is contained in:
commit
5ce079ef00
|
|
@ -29,7 +29,8 @@ import LeadKit
|
|||
required init(map: Map) throws {
|
||||
{%- include 'blocks/class/fields-mapping-from-map.twig' with {
|
||||
fields: fields,
|
||||
classType: classType
|
||||
classType: classType,
|
||||
typeParameters: type.typeParameters
|
||||
} -%}
|
||||
{% if hasParent %}
|
||||
try super.init(map: map)
|
||||
|
|
@ -39,7 +40,8 @@ import LeadKit
|
|||
{% if hasParent %} override {% endif %}func mapping(map: Map) {
|
||||
{%- include 'blocks/class/fields-mapping-to-map.twig' with {
|
||||
fields: fields,
|
||||
classType: classType
|
||||
classType: classType,
|
||||
typeParameters: type.typeParameters
|
||||
} -%}
|
||||
{% if hasParent %}
|
||||
super.mapping(map: map)
|
||||
|
|
@ -53,12 +55,22 @@ import LeadKit
|
|||
}
|
||||
|
||||
return{%- if hasParent %} super.isEqual(to: other){%- endif %}{%- if (fields is not empty) and hasParent %} &&{% endif %} {% include 'blocks/class/fields-equal.twig' with { fields: fields } %}
|
||||
}
|
||||
}{{ "\n" }}
|
||||
{%- endif %}
|
||||
}
|
||||
{{ "\n" }}
|
||||
{%- if not hasChilds -%}
|
||||
extension {{ type.baseTypeName }}: UniversalMappable {
|
||||
|
||||
static func decode(from map: Map, key: String) throws -> {{ type.baseTypeName }} {
|
||||
return try map.value(key)
|
||||
}
|
||||
|
||||
}
|
||||
{{ "\n" }}
|
||||
{%- endif -%}
|
||||
|
||||
{% if (not hasChilds) and (not hasGenerics) and (not fieldsHasGenericsOrNonEqutableCollections) -%}
|
||||
{%- if (not hasChilds) and (not hasGenerics) and (not fieldsHasGenericsOrNonEqutableCollections) -%}
|
||||
extension {{ type.baseTypeName }}: Equatable {
|
||||
|
||||
static func ==(lhs: {{ classType }}, rhs: {{ classType }}) -> Bool {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{%- import '../../macroses/common.utils.twig' as utils -%}
|
||||
{%- for field in fields %}
|
||||
{{ field.name }} = {{ utils.formatNullableOrOptional('try', field.nullable, field.optional) }} {{ utils.mappingFromMapForField(field, classType) }}
|
||||
{{ field.name }} = {{ utils.formatNullableOrOptional('try', field.nullable, field.optional) }} {{ utils.mappingFromMapForField(field, classType, typeParameters) }}
|
||||
{%- endfor -%}
|
||||
|
|
@ -2,9 +2,9 @@
|
|||
{%- for field in fields %}
|
||||
{%- if field.optional %}
|
||||
if {{ field.name }} != nil {
|
||||
{{ field.name }} >>> {{ utils.mappingToMapForField(field, classType) }}
|
||||
{{ utils.mappingToMapForField(field, classType, typeParameters) }}
|
||||
}
|
||||
{%- else %}
|
||||
{{ field.name }} >>> {{ utils.mappingToMapForField(field, classType) }}
|
||||
{{ utils.mappingToMapForField(field, classType, typeParameters) }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
{%- if parameters is not empty -%}
|
||||
<
|
||||
{%- for typeParameter in parameters %}
|
||||
{{- utils.formatValueType(typeParameter) -}}{{- withConstraint ? ": ImmutableMappable" : ""-}}{%- if not (loop.last) %}, {% endif %}
|
||||
{{- utils.formatValueType(typeParameter) -}}{{- withConstraint ? ": UniversalMappable" : ""-}}{%- if not (loop.last) %}, {% endif %}
|
||||
{%- endfor -%}
|
||||
>
|
||||
{%- endif -%}
|
||||
|
|
|
|||
|
|
@ -36,25 +36,29 @@
|
|||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro mappingFromMapForField(field, className) %}
|
||||
{% macro mappingFromMapForField(field, className, typeParameters) %}
|
||||
{%- import _self as self -%}
|
||||
|
||||
{%- if field.type.type.baseTypeName == "DateTime" -%}
|
||||
map.value("{{ field.jsonName }}", using: {{ self.mappingTransformForField(field) -}})
|
||||
{%- elseif field.type.type.baseTypeName == "Decimal" -%}
|
||||
map.value("{{ field.jsonName }}", using: NSDecimalNumberTransform())
|
||||
{%- elseif (self.fieldIsGeneric(field, typeParameters) != null) -%}
|
||||
{{ field.type.type.baseTypeName }}.decode(from: map, key: "{{ field.jsonName }}")
|
||||
{%- else -%}
|
||||
map.value("{{ field.jsonName }}")
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro mappingToMapForField(field, className) %}
|
||||
{% macro mappingToMapForField(field, className, typeParameters) %}
|
||||
{%- import _self as self -%}
|
||||
|
||||
{%- if field.type.type.baseTypeName == "DateTime" -%}
|
||||
(map["{{ field.jsonName }}"], {{ self.mappingTransformForField(field) -}})
|
||||
{{ field.name }} >>> (map["{{ field.jsonName }}"], {{ self.mappingTransformForField(field) -}})
|
||||
{%- elseif (self.fieldIsGeneric(field, typeParameters) != null) -%}
|
||||
{{ self.formatNullableOrOptional(field.name, field.nullable, field.optional) }}.encode(to: map, key: "{{ field.jsonName }}")
|
||||
{%- else -%}
|
||||
map["{{ field.jsonName }}"]
|
||||
{{ field.name }} >>> map["{{ field.jsonName }}"]
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
|
|
@ -106,7 +110,7 @@
|
|||
{%- elseif (valueType.parent is not null) -%}
|
||||
{%- import _self as self -%}
|
||||
|
||||
{{ self.valueTypeHasGenerics(valueType.parent) }}
|
||||
{{- self.valueTypeHasGenerics(valueType.parent) -}}
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
|
|
@ -121,13 +125,21 @@
|
|||
{%- if (valueType.itemsType.typeParameters is not null) -%}
|
||||
{{ true }}
|
||||
{%- else -%}
|
||||
{{ self.hasGenericsOrNonEqutableCollections(valueType.itemsType) }}
|
||||
{{- self.hasGenericsOrNonEqutableCollections(valueType.itemsType) -}}
|
||||
{%- endif -%}
|
||||
{%- elseif valueType.baseTypeName == "Map" -%}
|
||||
{{ true }}
|
||||
{%- elseif type.allFieldsOrdered is not null -%}
|
||||
{%- for field in type.allFieldsOrdered -%}
|
||||
{{ self.hasGenericsOrNonEqutableCollections(field.type) }}
|
||||
{{- self.hasGenericsOrNonEqutableCollections(field.type) -}}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro fieldIsGeneric(field, typeParameters) %}
|
||||
{%- for typeParameter in typeParameters -%}
|
||||
{%- if typeParameter.baseTypeName == field.type.type.baseTypeName -%}
|
||||
{{ true }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{% endmacro %}
|
||||
|
|
|
|||
Loading…
Reference in New Issue