@@ -71,21 +71,21 @@ public class <%- toPascalCase(collection.name) %>: Codable {
7171<% } -%>
7272 }
7373
74- init(
74+ public init(
7575<% for (const [index, attribute] of Object .entries(collection.attributes)) { -%>
76- <% - strict ? toCamelCase(attribute.key) : attribute.key %> : <% - getType(attribute) %><% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
76+ <% - strict ? toCamelCase(attribute.key) : attribute.key %> : <% - getType(attribute) %><% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
7777<% } -%>
7878 ) {
7979<% for (const attribute of collection.attributes) { -%>
80- self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = <% - strict ? toCamelCase(attribute.key) : attribute.key %>
80+ self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = <% - strict ? toCamelCase(attribute.key) : attribute.key %>
8181<% } -%>
8282 }
8383
8484 public required init(from decoder: Decoder) throws {
8585 let container = try decoder.container(keyedBy: CodingKeys.self)
8686
8787<% for (const attribute of collection.attributes) { -%>
88- <% if (attribute.required) { -%>
88+ <% if (!(! attribute.required && attribute.default === null) ) { -%>
8989 self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<% - getType(attribute).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
9090<% } else { -%>
9191 self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<% - getType(attribute).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
@@ -97,7 +97,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
9797 var container = encoder.container(keyedBy: CodingKeys.self)
9898
9999<% for (const attribute of collection.attributes) { -%>
100- <% if (attribute.required) { -%>
100+ <% if (!(! attribute.required && attribute.default === null) ) { -%>
101101 try container.encode(<% - strict ? toCamelCase(attribute.key) : attribute.key %> , forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
102102<% } else { -%>
103103 try container.encodeIfPresent(<% - strict ? toCamelCase(attribute.key) : attribute.key %> , forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
0 commit comments