@@ -72,8 +72,8 @@ public class <%- toPascalCase(collection.name) %>: Codable {
72
72
}
73
73
74
74
init(
75
- <% for (const attribute of collection.attributes) { -%>
76
- <% - toCamelCase(attribute.key) %> : <% - getType(attribute) %><% if (attribute != = collection.attributes[collection.attributes. length - 1 ] ) { %> ,<% } %>
75
+ <% for (const [index, attribute] of Object .entries( collection.attributes) ) { -%>
76
+ <% - toCamelCase(attribute.key) %> : <% - getType(attribute) %><% if (index < collection.attributes. length - 1 ) { %> ,<% } %>
77
77
<% } -%>
78
78
) {
79
79
<% for (const attribute of collection.attributes) { -%>
@@ -109,24 +109,24 @@ public class <%- toPascalCase(collection.name) %>: Codable {
109
109
return [
110
110
<% for (const attribute of collection.attributes) { -%>
111
111
<% if (attribute.type === ' relationship' ) { -%>
112
- "<% - attribute.key %> ": <% - toCamelCase(attribute.key) %> as Any<% if (attribute != = collection.attributes[collection.attributes. length - 1 ] ) { %> ,<% } %>
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' ) { -%>
114
- "<% - attribute.key %> ": <% - toCamelCase(attribute.key) %> ?.map { $0.toMap() } as Any<% if (attribute != = collection.attributes[collection.attributes. length - 1 ] ) { %> ,<% } %>
114
+ "<% - attribute.key %> ": <% - toCamelCase(attribute.key) %> ?.map { $0.toMap() } as Any<% if (index < collection.attributes. length - 1 ) { %> ,<% } %>
115
115
<% } else { -%>
116
- "<% - attribute.key %> ": <% - toCamelCase(attribute.key) %> as Any<% if (attribute != = collection.attributes[collection.attributes. length - 1 ] ) { %> ,<% } %>
116
+ "<% - attribute.key %> ": <% - toCamelCase(attribute.key) %> as Any<% if (index < collection.attributes. length - 1 ) { %> ,<% } %>
117
117
<% } -%>
118
118
<% } -%>
119
119
]
120
120
}
121
121
122
122
public static func from(map: [String: Any]) -> <% - toPascalCase(collection.name) %> {
123
123
return <% - toPascalCase(collection.name) %> (
124
- <% for (const attribute of collection.attributes) { -%>
124
+ <% for (const [index, attribute] of Object .entries( collection.attributes) ) { -%>
125
125
<% if (attribute.type === ' relationship' ) { -%>
126
126
<% if ((attribute.relationType === ' oneToMany' && attribute.side === ' parent' ) || (attribute.relationType === ' manyToOne' && attribute.side === ' child' ) || attribute.relationType === ' manyToMany' ) { -%>
127
- <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [<% - toPascalCase(attribute.relatedCollection) %> ]<% if (attribute != = collection.attributes[collection.attributes. length - 1 ] ) { %> ,<% } %>
127
+ <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> [<% - toPascalCase(attribute.relatedCollection) %> ]<% if (index < collection.attributes. length - 1 ) { %> ,<% } %>
128
128
<% } else { -%>
129
- <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> <% - toPascalCase(attribute.relatedCollection) %><% if (attribute != = collection.attributes[collection.attributes. length - 1 ] ) { %> ,<% } %>
129
+ <% - toCamelCase(attribute.key) %> : map["<% - attribute.key %> "] as<% if (!attribute.required) { %> ?<% } else { %> !<% } %> <% - toPascalCase(attribute.relatedCollection) %><% if (index < collection.attributes. length - 1 ) { %> ,<% } %>
130
130
<% } -%>
131
131
<% } else if (attribute.array) { -%>
132
132
<% if (attribute.type === ' string' ) { -%>
0 commit comments