@@ -7,6 +7,15 @@ public class {{ definition | modelType(spec) | raw }} {}
7
7
{% else %}
8
8
public class {{ definition | modelType(spec ) | raw }} {
9
9
10
+ enum CodingKeys: String, CodingKey {
11
+ {%~ for property in definition .properties %}
12
+ case {{ property .name | escapeSwiftKeyword | removeDollarSign }} = "{{ property .name }}"
13
+ {%~ endfor %}
14
+ {%~ if definition .additionalProperties %}
15
+ case data
16
+ {%~ endif %}
17
+ }
18
+
10
19
{%~ for property in definition .properties %}
11
20
/// {{ property .description }}
12
21
public let {{ property .name | escapeSwiftKeyword | removeDollarSign }}: {{ property | propertyType(spec ) | raw }}{% if not property .required %}?{% endif %}
@@ -35,6 +44,28 @@ public class {{ definition | modelType(spec) | raw }} {
35
44
{%~ endif %}
36
45
}
37
46
47
+ public required init(from decoder: Decoder) throws {
48
+ let container = try decoder.container(keyedBy: CodingKeys.self)
49
+
50
+ {%~ for property in definition .properties %}
51
+ self.{{ property .name | escapeSwiftKeyword | removeDollarSign }} = try container.decode{% if not property .required %}IfPresent{% endif %}({{ property | propertyType(spec ) | raw }}.self, forKey: .{{ property .name | escapeSwiftKeyword | removeDollarSign }})
52
+ {%~ endfor %}
53
+ {%~ if definition .additionalProperties %}
54
+ self.data = try container.decode(T.self, forKey: .data)
55
+ {%~ endif %}
56
+ }
57
+
58
+ public func encode(to encoder: Encoder) throws {
59
+ var container = encoder.container(keyedBy: CodingKeys.self)
60
+
61
+ {%~ for property in definition .properties %}
62
+ try container.encode{% if not property .required %}IfPresent{% endif %}({{ property .name | escapeSwiftKeyword | removeDollarSign }}, forKey: .{{ property .name | escapeSwiftKeyword | removeDollarSign }})
63
+ {%~ endfor %}
64
+ {%~ if definition .additionalProperties %}
65
+ try container.encode(data, forKey: .data)
66
+ {%~ endif %}
67
+ }
68
+
38
69
public func toMap() -> [String: Any] {
39
70
return [
40
71
{%~ for property in definition .properties %}
0 commit comments