@@ -12,6 +12,7 @@ abstract class SwiftTarget < Target
12
12
when AST ::BoolPrimitiveType ; " Bool"
13
13
when AST ::BytesPrimitiveType ; " Data"
14
14
when AST ::VoidPrimitiveType ; " NoReply"
15
+ when AST ::MoneyPrimitiveType ; " Int64"
15
16
else
16
17
raise " BUG! Should handle primitive #{ t.class } "
17
18
end
@@ -38,6 +39,7 @@ abstract class SwiftTarget < Target
38
39
when AST ::StringPrimitiveType ; path
39
40
when AST ::IntPrimitiveType ; path
40
41
when AST ::UIntPrimitiveType ; path
42
+ when AST ::MoneyPrimitiveType ; path
41
43
when AST ::FloatPrimitiveType ; path
42
44
when AST ::DatePrimitiveType ; path
43
45
when AST ::DateTimePrimitiveType ; path
@@ -55,11 +57,11 @@ abstract class SwiftTarget < Target
55
57
56
58
def generate_struct_type (t )
57
59
String .build do |io |
58
- io << " class #{ t.name } : Codable {\n "
60
+ io << " public class #{ t.name } : Codable {\n "
59
61
t.fields.each do |field |
60
- io << ident " var #{ field.name } : #{ native_type field.type } \n "
62
+ io << ident " public var #{ field.name } : #{ native_type field.type } \n "
61
63
end
62
- io << ident " \n var copy: #{ t.name } {\n "
64
+ io << ident " \n public var copy: #{ t.name } {\n "
63
65
io << ident ident " return #{ t.name } (\n "
64
66
io << ident ident ident t.fields.map { |field | " #{ field.name } : #{ generate_property_copy(field.type, field.name) } " }.join(" ,\n " )
65
67
io << ident ident " \n )\n "
@@ -74,7 +76,7 @@ abstract class SwiftTarget < Target
74
76
io << ident <<-END
75
77
76
78
77
- init() {
79
+ public init() {
78
80
79
81
END
80
82
t.fields.each do |field |
83
85
io << ident <<-END
84
86
}
85
87
86
- init(#{ t.fields.map { |f | " #{ f.name } : #{ native_type f.type } " }.join(" , " ) } ) {
88
+ public init(#{ t.fields.map { |f | " #{ f.name } : #{ native_type f.type } " }.join(" , " ) } ) {
87
89
88
90
END
89
91
t.fields.each do |field |
92
94
io << ident <<-END
93
95
}
94
96
95
- init(json: [String: Any]) throws {
97
+ public init(json: [String: Any]) throws {
96
98
let jsonData = try JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)
97
99
let decodedSelf = try decoder.decode(#{ t.name } .self, from: jsonData)\n
98
100
103
105
io << ident <<-END
104
106
}
105
107
106
- func toJSON() -> [String: Any] {
108
+ public func toJSON() -> [String: Any] {
107
109
var json = [String: Any]()
108
110
109
111
END
122
124
def generate_enum_type (t )
123
125
String .build do |io |
124
126
if t.name == " ErrorType"
125
- io << " enum #{ t.name } : String, Error, Codable {\n "
127
+ io << " public enum #{ t.name } : String, Error, Codable {\n "
126
128
else
127
- io << " enum #{ t.name } : String, CaseIterable, DisplayableValue, Codable {\n "
129
+ io << " public enum #{ t.name } : String, CaseIterable, DisplayableValue, Codable {\n "
128
130
end
129
131
130
132
t.values.each do |value |
142
144
io << ident ident " return dictionary\n "
143
145
io << ident " }\n "
144
146
145
- io << ident " \n static func allDisplayableValues() -> [String] {\n "
147
+ io << ident " \n public static func allDisplayableValues() -> [String] {\n "
146
148
io << ident ident " var displayableValues: [String] = []\n "
147
149
io << ident ident " for enumCase in self.allCases {\n "
148
150
io << ident ident ident " displayableValues.append(enumCase.displayableValue)\n "
158
160
case t
159
161
when AST ::StringPrimitiveType
160
162
" \"\" "
161
- when AST ::IntPrimitiveType , AST ::UIntPrimitiveType , AST ::FloatPrimitiveType
163
+ when AST ::IntPrimitiveType , AST ::UIntPrimitiveType , AST ::FloatPrimitiveType , AST :: MoneyPrimitiveType
162
164
" 0"
163
165
when AST ::BoolPrimitiveType
164
166
" false"
185
187
186
188
def type_to_json (t : AST ::Type , src : String )
187
189
case t
188
- when AST ::StringPrimitiveType , AST ::IntPrimitiveType , AST ::UIntPrimitiveType , AST ::FloatPrimitiveType , AST ::BoolPrimitiveType
190
+ when AST ::StringPrimitiveType , AST ::IntPrimitiveType , AST ::UIntPrimitiveType , AST ::FloatPrimitiveType , AST ::BoolPrimitiveType , AST :: MoneyPrimitiveType
189
191
" #{ src } "
190
192
when AST ::DatePrimitiveType
191
193
" apiInternal.encodeDate(date: #{ src } )"
0 commit comments