@@ -3,15 +3,15 @@ const { AttributeType } = require('../attribute');
33const { LanguageMeta } = require("./language");
44
55class Swift extends LanguageMeta {
6- getType(attribute, collections) {
6+ getType(attribute, collections, collectionName ) {
77 let type = "";
88 switch (attribute.type) {
99 case AttributeType.STRING:
1010 case AttributeType.EMAIL:
1111 case AttributeType.DATETIME:
1212 type = "String";
1313 if (attribute.format === AttributeType.ENUM) {
14- type = LanguageMeta.toPascalCase(attribute.key);
14+ type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase( attribute.key);
1515 }
1616 break;
1717 case AttributeType.INTEGER:
@@ -53,7 +53,7 @@ class Swift extends LanguageMeta {
5353
5454<% for (const attribute of collection.attributes) { -%>
5555<% if (attribute.format === ' enum' ) { -%>
56- public enum <% - toPascalCase(attribute.key) %> : String, Codable, CaseIterable {
56+ public enum <% - toPascalCase(collection.name) %><% - toPascalCase( attribute.key) %> : String, Codable, CaseIterable {
5757<% for (const [index, element] of Object .entries(attribute.elements)) { -%>
5858 case <% - strict ? toCamelCase(element) : element %> = "<% - element %> "
5959<% } -%>
@@ -63,7 +63,7 @@ public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
6363<% } -%>
6464public class <% - toPascalCase(collection.name) %> : Codable {
6565<% for (const attribute of collection.attributes) { -%>
66- public let <% - strict ? toCamelCase(attribute.key) : attribute.key %> : <% - getType(attribute, collections) %>
66+ public let <% - strict ? toCamelCase(attribute.key) : attribute.key %> : <% - getType(attribute, collections, collection.name ) %>
6767<% } %>
6868 enum CodingKeys: String, CodingKey {
6969<% for (const attribute of collection.attributes) { -%>
@@ -73,7 +73,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
7373
7474 public init(
7575<% for (const [index, attribute] of Object .entries(collection.attributes)) { -%>
76- <% - strict ? toCamelCase(attribute.key) : attribute.key %> : <% - getType(attribute, collections) %><% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
76+ <% - strict ? toCamelCase(attribute.key) : attribute.key %> : <% - getType(attribute, collections, collection.name ) %><% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
7777<% } -%>
7878 ) {
7979<% for (const attribute of collection.attributes) { -%>
@@ -86,9 +86,9 @@ public class <%- toPascalCase(collection.name) %>: Codable {
8686
8787<% for (const attribute of collection.attributes) { -%>
8888<% if (!(!attribute.required && attribute.default === null)) { -%>
89- self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<% - getType(attribute, collections).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
89+ self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<% - getType(attribute, collections, collection.name ).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
9090<% } else { -%>
91- self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<% - getType(attribute, collections).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
91+ self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<% - getType(attribute, collections, collection.name ).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
9292<% } -%>
9393<% } -%>
9494 }
@@ -144,7 +144,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
144144<% if ((attribute.type === ' string' || attribute.type === ' email' || attribute.type === ' datetime' ) && attribute.format != = ' enum' ) { -%>
145145 <% - 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(collection.name) %><% - toPascalCase( attribute.key) %> (rawValue: map["<% - attribute.key %> "] as! String)!<% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
148148<% } else if (attribute.type === ' integer' ) { -%>
149149 <% - 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' ) { -%>
0 commit comments