Skip to content

Commit 3d1bc6b

Browse files
committed
fix issues with generated files
1 parent e1c5578 commit 3d1bc6b

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

Core/Generator/FileGeneratorExtension.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ extension FileGenerator {
3131
content = content.replacingOccurrences(of: "{DECLARATION}", with: declarations)
3232
content = content.replacingOccurrences(of: "{INITIALIZER}", with: initialisers)
3333

34+
if modelFile.type == .classType {
35+
content = content.replacingOccurrences(of: "{REQUIRED}", with: "required ")
36+
} else {
37+
content = content.replacingOccurrences(of: "{REQUIRED}", with: "")
38+
}
3439
return content
3540
}
3641

Core/Generator/Model-File-Components/SwiftJSONModelFile.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ struct SwiftJSONModelFile: ModelFile {
100100
if isArray {
101101
variableType = "[\(type)]"
102102
}
103+
let component = constantName.components(separatedBy: ".")
103104
let decodeMethod = isOptional ? "decodeIfPresent" : "decode"
104-
return "\(name) = try container.\(decodeMethod)(\(variableType).self, forKey: .\(constantName))"
105+
return "\(name) = try container.\(decodeMethod)(\(variableType).self, forKey: .\(component.last!))"
105106
}
106107
}

Core/Template/BaseTemplate.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import Foundation
99

1010
{OBJECT_KIND} {OBJECT_NAME}: Codable {
1111

12-
enum CodingKeys: CodingKey {
12+
enum CodingKeys: String, CodingKey {
1313
{STRING_CONSTANT}
1414
}
1515

1616
{DECLARATION}
1717

18-
init(from decoder: Decoder) throws {
18+
{REQUIRED}init(from decoder: Decoder) throws {
1919
let container = try decoder.container(keyedBy: CodingKeys.self)
2020
{INITIALIZER}
2121
}

SwiftyJSONAccelerator/Support/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>2.0</string>
2121
<key>CFBundleVersion</key>
22-
<string>12</string>
22+
<string>13</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.developer-tools</string>
2525
<key>LSMinimumSystemVersion</key>

0 commit comments

Comments
 (0)