Skip to content

Commit e9fb017

Browse files
committed
chore: use consistent check for index
1 parent 1553fd0 commit e9fb017

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

templates/cli/lib/type-generation/languages/java.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public class <%- toPascalCase(collection.name) %> {
113113
@Override
114114
public String toString() {
115115
return "<%- toPascalCase(collection.name) %>{" +
116-
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
116+
<% for (const attribute of collection.attributes) { -%>
117117
"<%= toCamelCase(attribute.key) %>=" + <%= toCamelCase(attribute.key) %> +
118118
<% } -%>
119119
'}';

templates/cli/lib/type-generation/languages/swift.js.twig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public class <%- toPascalCase(collection.name) %>: Codable {
7272
}
7373

7474
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) { %>,<% } %>
7777
<% } -%>
7878
) {
7979
<% for (const attribute of collection.attributes) { -%>
@@ -109,24 +109,24 @@ public class <%- toPascalCase(collection.name) %>: Codable {
109109
return [
110110
<% for (const attribute of collection.attributes) { -%>
111111
<% 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) { %>,<% } %>
113113
<% } 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) { %>,<% } %>
115115
<% } 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) { %>,<% } %>
117117
<% } -%>
118118
<% } -%>
119119
]
120120
}
121121

122122
public static func from(map: [String: Any]) -> <%- toPascalCase(collection.name) %> {
123123
return <%- toPascalCase(collection.name) %>(
124-
<% for (const attribute of collection.attributes) { -%>
124+
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
125125
<% if (attribute.type === 'relationship') { -%>
126126
<% 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) { %>,<% } %>
128128
<% } 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) { %>,<% } %>
130130
<% } -%>
131131
<% } else if (attribute.array) { -%>
132132
<% if (attribute.type === 'string') { -%>

0 commit comments

Comments
 (0)