Skip to content

Commit 9f38234

Browse files
committed
fix: indentation in swift to use 4 spaces instead of 2
1 parent 25dd730 commit 9f38234

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

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

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,109 +55,109 @@ class Swift extends LanguageMeta {
5555
<% if (attribute.format === 'enum') { -%>
5656
public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
5757
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
58-
case <%- strict ? toCamelCase(element) : element %> = "<%- element %>"
58+
case <%- strict ? toCamelCase(element) : element %> = "<%- element %>"
5959
<% } -%>
6060
}
6161

6262
<% } -%>
6363
<% } -%>
6464
public class <%- toPascalCase(collection.name) %>: Codable {
6565
<% for (const attribute of collection.attributes) { -%>
66-
public let <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %>
66+
public let <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %>
6767
<% } %>
68-
enum CodingKeys: String, CodingKey {
68+
enum CodingKeys: String, CodingKey {
6969
<% for (const attribute of collection.attributes) { -%>
70-
case <%- strict ? toCamelCase(attribute.key) : attribute.key %> = "<%- attribute.key %>"
70+
case <%- strict ? toCamelCase(attribute.key) : attribute.key %> = "<%- attribute.key %>"
7171
<% } -%>
72-
}
72+
}
7373

74-
init(
74+
init(
7575
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
7676
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
7777
<% } -%>
78-
) {
78+
) {
7979
<% for (const attribute of collection.attributes) { -%>
8080
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = <%- strict ? toCamelCase(attribute.key) : attribute.key %>
8181
<% } -%>
82-
}
82+
}
8383

84-
public required init(from decoder: Decoder) throws {
85-
let container = try decoder.container(keyedBy: CodingKeys.self)
84+
public required init(from decoder: Decoder) throws {
85+
let container = try decoder.container(keyedBy: CodingKeys.self)
8686

8787
<% for (const attribute of collection.attributes) { -%>
8888
<% if (attribute.required) { -%>
89-
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
89+
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
9090
<% } else { -%>
91-
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
91+
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
9292
<% } -%>
9393
<% } -%>
94-
}
94+
}
9595

96-
public func encode(to encoder: Encoder) throws {
97-
var container = encoder.container(keyedBy: CodingKeys.self)
96+
public func encode(to encoder: Encoder) throws {
97+
var container = encoder.container(keyedBy: CodingKeys.self)
9898

9999
<% for (const attribute of collection.attributes) { -%>
100100
<% if (attribute.required) { -%>
101-
try container.encode(<%- strict ? toCamelCase(attribute.key) : attribute.key %>, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
101+
try container.encode(<%- strict ? toCamelCase(attribute.key) : attribute.key %>, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
102102
<% } else { -%>
103-
try container.encodeIfPresent(<%- strict ? toCamelCase(attribute.key) : attribute.key %>, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
103+
try container.encodeIfPresent(<%- strict ? toCamelCase(attribute.key) : attribute.key %>, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
104104
<% } -%>
105105
<% } -%>
106-
}
106+
}
107107

108-
public func toMap() -> [String: Any] {
109-
return [
108+
public func toMap() -> [String: Any] {
109+
return [
110110
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
111111
<% if (attribute.type === 'relationship') { -%>
112-
"<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %> as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
112+
"<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : 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 %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %>?.map { $0.toMap() } as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
114+
"<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %>?.map { $0.toMap() } as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
115115
<% } else { -%>
116-
"<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %> as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
116+
"<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %> as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
117117
<% } -%>
118118
<% } -%>
119-
]
120-
}
119+
]
120+
}
121121

122-
public static func from(map: [String: Any]) -> <%- toPascalCase(collection.name) %> {
123-
return <%- toPascalCase(collection.name) %>(
122+
public static func from(map: [String: Any]) -> <%- toPascalCase(collection.name) %> {
123+
return <%- toPascalCase(collection.name) %>(
124124
<% 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-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [<%- toPascalCase(attribute.relatedCollection) %>]<% if (index < collection.attributes.length - 1) { %>,<% } %>
127+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [<%- toPascalCase(attribute.relatedCollection) %>]<% if (index < collection.attributes.length - 1) { %>,<% } %>
128128
<% } else { -%>
129-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> <%- toPascalCase(attribute.relatedCollection) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
129+
<%- strict ? toCamelCase(attribute.key) : 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') { -%>
133-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (index < collection.attributes.length - 1) { %>,<% } %>
133+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (index < collection.attributes.length - 1) { %>,<% } %>
134134
<% } else if (attribute.type === 'integer') { -%>
135-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Int]<% if (index < collection.attributes.length - 1) { %>,<% } %>
135+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Int]<% if (index < collection.attributes.length - 1) { %>,<% } %>
136136
<% } else if (attribute.type === 'float') { -%>
137-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Double]<% if (index < collection.attributes.length - 1) { %>,<% } %>
137+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Double]<% if (index < collection.attributes.length - 1) { %>,<% } %>
138138
<% } else if (attribute.type === 'boolean') { -%>
139-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Bool]<% if (index < collection.attributes.length - 1) { %>,<% } %>
139+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Bool]<% if (index < collection.attributes.length - 1) { %>,<% } %>
140140
<% } else { -%>
141-
<%- strict ? toCamelCase(attribute.key) : 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) { %>,<% } %>
141+
<%- strict ? toCamelCase(attribute.key) : 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) { %>,<% } %>
142142
<% } -%>
143143
<% } else { -%>
144144
<% if ((attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') && attribute.format !== 'enum') { -%>
145-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (index < collection.attributes.length - 1) { %>,<% } %>
145+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (index < collection.attributes.length - 1) { %>,<% } %>
146146
<% } else if (attribute.type === 'string' && attribute.format === 'enum') { -%>
147-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- toPascalCase(attribute.key) %>(rawValue: map["<%- attribute.key %>"] as! String)!<% if (index < collection.attributes.length - 1) { %>,<% } %>
147+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- toPascalCase(attribute.key) %>(rawValue: map["<%- attribute.key %>"] as! String)!<% if (index < collection.attributes.length - 1) { %>,<% } %>
148148
<% } else if (attribute.type === 'integer') { -%>
149-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (index < collection.attributes.length - 1) { %>,<% } %>
149+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (index < collection.attributes.length - 1) { %>,<% } %>
150150
<% } else if (attribute.type === 'float') { -%>
151-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Double<% if (index < collection.attributes.length - 1) { %>,<% } %>
151+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Double<% if (index < collection.attributes.length - 1) { %>,<% } %>
152152
<% } else if (attribute.type === 'boolean') { -%>
153-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Bool<% if (index < collection.attributes.length - 1) { %>,<% } %>
153+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Bool<% if (index < collection.attributes.length - 1) { %>,<% } %>
154154
<% } else { -%>
155-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- toPascalCase(attribute.type) %>.from(map: map["<%- attribute.key %>"] as! [String: Any])<% if (index < collection.attributes.length - 1) { %>,<% } %>
155+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- toPascalCase(attribute.type) %>.from(map: map["<%- attribute.key %>"] as! [String: Any])<% if (index < collection.attributes.length - 1) { %>,<% } %>
156156
<% } -%>
157157
<% } -%>
158158
<% } -%>
159-
)
160-
}
159+
)
160+
}
161161
}`;
162162
}
163163

0 commit comments

Comments
 (0)