File tree Expand file tree Collapse file tree 1 file changed +4
-0
lines changed
templates/swift/Sources/Models Expand file tree Collapse file tree 1 file changed +4
-0
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,11 @@ 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
+ {%~ if definition .name | lower == ' document' %}
85
+ {{ property.name | escapeSwiftKeyword | removeDollarSign }}: {% if property.sub_schema %}{% if property.type == 'array' %}(map["{{property.name }}"] as? [[String: Any]] ?? []).map { {{property.sub_schema | caseUcfirst}}.from(map: $0) }{% else %}map["{{property.name }}"] as? [String: Any] != nil ? {{property.sub_schema | caseUcfirst}}.from(map: map["{{property.name }}"] as! [String: Any]) : nil{% endif %}{% else %}{% if property | isAnyCodableArray(spec) %}(map["{{property.name }}"] as? [Any] ?? []).map { AnyCodable($0) }{% else %}map["{{property.name }}"] as? {{ property | propertyType(spec) | raw }}{% if property.required and property.type == 'string' %} ?? ""{% elseif property.required and property.type == 'integer' %} ?? 0{% elseif property.required and property.type == 'number' %} ?? 0.0{% elseif property.required and property.type == 'boolean' %} ?? false{% elseif property.required and property.type == 'array' %} ?? []{% endif %}{% endif %}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %}
86
+ {%~ else %}
84
87
{{ property .name | escapeSwiftKeyword | removeDollarSign }}: {% if property .sub_schema %}{% if property .type == ' array' %}(map["{{property .name }}"] as! [[String: Any]]).map { {{property .sub_schema | caseUcfirst }}.from(map: $0) }{% else %}{{property .sub_schema | caseUcfirst }}.from(map: map["{{property .name }}"] as! [String: Any]){% endif %}{% else %}{% if property | isAnyCodableArray(spec ) %}(map["{{property .name }}"] as{% if property .required %}!{% else %}?{% endif %} [Any]{% if not property .required %} ?? []{% endif %}).map { AnyCodable($0) }{% else %}map["{{property .name }}"] as{% if property .required %}!{% else %}?{% endif %} {{ property | propertyType(spec ) | raw }}{% endif %}{% endif %}{% if not loop .last or (loop .last and definition .additionalProperties ) %},{% endif %}
88
+ {%~ endif %}
85
89
86
90
{%~ endfor %}
87
91
{%~ if definition .additionalProperties %}
You can’t perform that action at this time.
0 commit comments