@@ -71,21 +71,21 @@ public class <%- toPascalCase(collection.name) %>: Codable {
71
71
<% } -%>
72
72
}
73
73
74
- init(
74
+ public init(
75
75
<% 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 ) { %> ,<% } %>
77
77
<% } -%>
78
78
) {
79
79
<% 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 %>
81
81
<% } -%>
82
82
}
83
83
84
84
public required init(from decoder: Decoder) throws {
85
85
let container = try decoder.container(keyedBy: CodingKeys.self)
86
86
87
87
<% for (const attribute of collection.attributes) { -%>
88
- <% if (attribute.required) { -%>
88
+ <% if (!(! attribute.required && attribute.default === null) ) { -%>
89
89
self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<% - getType(attribute).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
90
90
<% } else { -%>
91
91
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 {
97
97
var container = encoder.container(keyedBy: CodingKeys.self)
98
98
99
99
<% for (const attribute of collection.attributes) { -%>
100
- <% if (attribute.required) { -%>
100
+ <% if (!(! attribute.required && attribute.default === null) ) { -%>
101
101
try container.encode(<% - strict ? toCamelCase(attribute.key) : attribute.key %> , forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
102
102
<% } else { -%>
103
103
try container.encodeIfPresent(<% - strict ? toCamelCase(attribute.key) : attribute.key %> , forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
0 commit comments