|
|
|
|
@ -61,7 +61,7 @@ class SwiftModelGenerator: |
|
|
|
|
lines.append("") |
|
|
|
|
|
|
|
|
|
# CodingKeys |
|
|
|
|
lines.extend(self._generate_coding_keys(properties, is_observable, is_sync)) |
|
|
|
|
lines.extend(self._generate_coding_keys(model_name, properties, is_observable)) |
|
|
|
|
lines.append("") |
|
|
|
|
|
|
|
|
|
# Encryption methods |
|
|
|
|
@ -166,8 +166,13 @@ class SwiftModelGenerator: |
|
|
|
|
lines.extend([" }", ""]) # Close the method and add a blank line |
|
|
|
|
return lines |
|
|
|
|
|
|
|
|
|
def _generate_coding_keys(self, properties: List[Dict[str, Any]], is_observable: bool, is_sync: bool = False) -> List[str]: |
|
|
|
|
def _generate_coding_keys(self, model_name: str, properties: List[Dict[str, Any]], is_observable: bool) -> List[str]: |
|
|
|
|
lines = [" enum CodingKeys: String, CodingKey {"] |
|
|
|
|
|
|
|
|
|
if model_name == 'Tournament': |
|
|
|
|
lines.append(" case isCanceled = \"isCanceled\"") |
|
|
|
|
lines.append(" case payment = \"payment\"") |
|
|
|
|
|
|
|
|
|
for prop in properties: |
|
|
|
|
name = prop['name'] |
|
|
|
|
# Add underscore prefix to case name if observable |
|
|
|
|
@ -190,7 +195,10 @@ class SwiftModelGenerator: |
|
|
|
|
if enc_type == "tournament_payment": |
|
|
|
|
lines.extend([ |
|
|
|
|
f" private static func _decode{name.capitalize()}(container: KeyedDecodingContainer<CodingKeys>) throws -> TournamentPayment? {{", |
|
|
|
|
f" let data = try container.decodeIfPresent(Data.self, forKey: ._{name})", |
|
|
|
|
f" var data = try container.decodeIfPresent(Data.self, forKey: ._{name})", |
|
|
|
|
" if data == nil {", |
|
|
|
|
" data = try container.decodeIfPresent(Data.self, forKey: .payment)", |
|
|
|
|
" }", |
|
|
|
|
" ", |
|
|
|
|
" if let data {", |
|
|
|
|
" do {", |
|
|
|
|
@ -226,7 +234,10 @@ class SwiftModelGenerator: |
|
|
|
|
elif enc_type == "tournament_iscanceled": |
|
|
|
|
lines.extend([ |
|
|
|
|
f" private static func _decode{name.capitalize()}(container: KeyedDecodingContainer<CodingKeys>) throws -> Bool {{", |
|
|
|
|
f" let data = try container.decodeIfPresent(Data.self, forKey: ._{name})", |
|
|
|
|
f" var data = try container.decodeIfPresent(Data.self, forKey: ._{name})", |
|
|
|
|
" if data == nil {", |
|
|
|
|
" data = try container.decodeIfPresent(Data.self, forKey: .isCanceled)", |
|
|
|
|
" }", |
|
|
|
|
" if let data {", |
|
|
|
|
" do {", |
|
|
|
|
" let decoded: String = try data.decryptData(pass: CryptoKey.pass.rawValue)", |
|
|
|
|
|