File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
templates/swift/Sources/Models Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -81,8 +81,20 @@ open class {{ definition | modelType(spec) | raw }}: Codable {
81
81
public static func from(map: [String: Any] ) -> {{ definition .name | caseUcfirst }} {
82
82
return {{ definition .name | caseUcfirst }}(
83
83
{%~ for property in definition .properties %}
84
- {%~ set isDocument = definition .name | lower == ' document' %} {# Temporary Fix until BE is fixed to return all attributes #}
85
- {{ property.name | escapeSwiftKeyword | removeDollarSign }}: {% if property.sub_schema %}{% if property.type == 'array' %}(map["{{property.name }}"] as{% if isDocument %}?{% else %}{% if property.required %}!{% else %}?{% endif %}{% endif %} [[String: Any]]{% if isDocument %} ?? []{% elseif not property.required %} ?? []{% endif %}).map { {{property.sub_schema | caseUcfirst}}.from(map: $0) }{% else %}{% if isDocument %}map["{{property.name }}"] as? [String: Any] != nil ? {{property.sub_schema | caseUcfirst}}.from(map: map["{{property.name }}"] as! [String: Any]) : nil{% else %}{{property.sub_schema | caseUcfirst}}.from(map: map["{{property.name }}"] as! [String: Any]){% endif %}{% endif %}{% else %}{% if property | isAnyCodableArray(spec) %}(map["{{property.name }}"] as{% if isDocument %}?{% else %}{% if property.required %}!{% else %}?{% endif %}{% endif %} [Any]{% if isDocument or not property.required %} ?? []{% endif %}).map { AnyCodable($0) }{% else %}map["{{property.name }}"] as{% if isDocument %}?{% else %}{% if property.required %}!{% else %}?{% endif %}{% endif %} {{ property | propertyType(spec) | raw }}{% if isDocument and property.required %}{% if property.type == 'string' %} ?? ""{% elseif property.type == 'integer' %} ?? 0{% elseif property.type == 'number' %} ?? 0.0{% elseif property.type == 'boolean' %} ?? false{% elseif property.type == 'array' %} ?? []{% endif %}{% endif %}{% endif %}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %}
84
+ {%~ set isDocument = definition .name | lower == ' document' %}{# Temporary Fix until BE is fixed to return all attributes #}
85
+ {{ property .name | escapeSwiftKeyword | removeDollarSign }}: {% if property .sub_schema -%}
86
+ {%- if property .type == ' array' -%}
87
+ (map["{{property .name }}"] as{% if isDocument %}?{% else %}{% if property .required %}!{% else %}?{% endif %}{% endif %} [[String: Any]]{% if isDocument %} ?? []{% elseif not property .required %} ?? []{% endif %}).map { {{property .sub_schema | caseUcfirst }}.from(map: $0) }
88
+ {%- else -%}
89
+ {% if isDocument %}map["{{property .name }}"] as? [String: Any] != nil ? {{property .sub_schema | caseUcfirst }}.from(map: map["{{property .name }}"] as! [String: Any]) : nil{% else %}{{property .sub_schema | caseUcfirst }}.from(map: map["{{property .name }}"] as! [String: Any]){% endif %}
90
+ {%- endif -%}
91
+ {%- else -%}
92
+ {%- if property | isAnyCodableArray(spec ) -%}
93
+ (map["{{property .name }}"] as{% if isDocument %}?{% else %}{% if property .required %}!{% else %}?{% endif %}{% endif %} [Any]{% if isDocument or not property .required %} ?? []{% endif %}).map { AnyCodable($0) }
94
+ {%- else -%}
95
+ map["{{property .name }}"] as{% if isDocument %}?{% else %}{% if property .required %}!{% else %}?{% endif %}{% endif %} {{ property | propertyType(spec ) | raw }}{% if isDocument and property .required %}{% if property .type == ' string' %} ?? ""{% elseif property .type == ' integer' %} ?? 0{% elseif property .type == ' number' %} ?? 0.0{% elseif property .type == ' boolean' %} ?? false{% elseif property .type == ' array' %} ?? []{% endif %}{% endif %}
96
+ {%- endif -%}
97
+ {%- endif %}{% if not loop .last or (loop .last and definition .additionalProperties ) %},{% endif %}
86
98
87
99
{%~ endfor %}
88
100
{%~ if definition .additionalProperties %}
You can’t perform that action at this time.
0 commit comments