@@ -107,7 +107,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
107
107
108
108
public func toMap() -> [String: Any] {
109
109
return [
110
- <% for (const attribute of collection.attributes) { -%>
110
+ <% for (const [index, attribute] of Object .entries( collection.attributes) ) { -%>
111
111
<% if (attribute.type === ' relationship' ) { -%>
112
112
"<% - attribute.key %> ": <% - toCamelCase(attribute.key) %> as Any<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
113
113
<% } else if (attribute.array && attribute.type != = ' string' && attribute.type != = ' integer' && attribute.type != = ' float' && attribute.type != = ' boolean' ) { -%>
@@ -130,29 +130,29 @@ public class <%- toPascalCase(collection.name) %>: Codable {
130
130
<% } -%>
131
131
<% } else if (attribute.array) { -%>
132
132
<% if (attribute.type === ' string' ) { -%>
133
- <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [String]<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
133
+ <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [String]<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
134
134
<% } else if (attribute.type === ' integer' ) { -%>
135
- <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [Int]<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
135
+ <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [Int]<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
136
136
<% } else if (attribute.type === ' float' ) { -%>
137
- <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [Double]<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
137
+ <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [Double]<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
138
138
<% } else if (attribute.type === ' boolean' ) { -%>
139
- <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [Bool]<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
139
+ <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [Bool]<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
140
140
<% } else { -%>
141
- <% - toCamelCase(attribute.key) %> : (map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [[String: Any]])<% if (!attribute.required) { %> ?<% } %> .map { <% - toPascalCase(attribute.type) %> .from(map: $0) }<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
141
+ <% - toCamelCase(attribute.key) %> : (map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [[String: Any]])<% if (!attribute.required) { %> ?<% } %> .map { <% - toPascalCase(attribute.type) %> .from(map: $0) }<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
142
142
<% } -%>
143
143
<% } else { -%>
144
144
<% if ((attribute.type === ' string' || attribute.type === ' email' || attribute.type === ' datetime' ) && attribute.format != = ' enum' ) { -%>
145
- <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> String<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
145
+ <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> String<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
146
146
<% } else if (attribute.type === ' string' && attribute.format === ' enum' ) { -%>
147
- <% - toCamelCase(attribute.key) %> : <% - toPascalCase(attribute.key) %> (rawValue: map["<% - attribute.key %> "] as! String)!<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
147
+ <% - toCamelCase(attribute.key) %> : <% - toPascalCase(attribute.key) %> (rawValue: map["<% - attribute.key %> "] as! String)!<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
148
148
<% } else if (attribute.type === ' integer' ) { -%>
149
- <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> Int<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
149
+ <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> Int<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
150
150
<% } else if (attribute.type === ' float' ) { -%>
151
- <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> Double<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
151
+ <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> Double<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
152
152
<% } else if (attribute.type === ' boolean' ) { -%>
153
- <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> Bool<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
153
+ <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> Bool<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
154
154
<% } else { -%>
155
- <% - toCamelCase(attribute.key) %> : <% - toPascalCase(attribute.type) %> .from(map: map["<% - attribute.key %> "] as! [String: Any])<% if (attribute != = collection.attributes.length - 1 ) { %> ,<% } %>
155
+ <% - toCamelCase(attribute.key) %> : <% - toPascalCase(attribute.type) %> .from(map: map["<% - attribute.key %> "] as! [String: Any])<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
156
156
<% } -%>
157
157
<% } -%>
158
158
<% } -%>
0 commit comments