diff --git a/README.md b/README.md index e48a396..3038566 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,22 @@ ![Logo](https://raw.githubusercontent.com/insanoid/SwiftyJSONAccelerator/master/SwiftyJSONAccelerator/Support/Assets.xcassets/AppIcon.appiconset/Icon_32x32%402x.png) -# SwiftyJSONAccelerator +# SwiftyJSONAccelerator (Model file Generator For Swift 3) [![Build Status](https://travis-ci.org/insanoid/SwiftyJSONAccelerator.svg?branch=master)](https://travis-ci.org/insanoid/SwiftyJSONAccelerator) [![codecov](https://codecov.io/gh/insanoid/SwiftyJSONAccelerator/branch/master/graph/badge.svg)](https://codecov.io/gh/insanoid/SwiftyJSONAccelerator) -**Version v1.2.0 Released!** - -- Now supports [Marshal](https://github.com/utahiosmac/Marshal)! One of the fastest JSONSerialisation class out there! [(Read more)](https://github.com/bwhiteley/JSONShootout) -- Set `class` as `final`. -- `init` marked as `required` by default for `class`. - -**Version v1.1.0 Released!** - -- Now generates the correct option `struct` and `class` based on what was selected. +**Version v1.3.0 Released!** -**Version v1.0.0 Released!** +- Serialisation keys moved into a struct for clarity. +- Minor fixes for Marshal and ObjectMapper. +- Generated comments now updated to the new Swift 3 Markup. -- Now generates **Swift 3** and the software itself is upgraded to Swift 3. -- Unit tests and complete code coverage for file generation module. -- Modular code to make adding support for other JSON mapping libraries simple. -- Project upgraded with SwiftLint, Travis, CocoaPods etc. +[Previous Release Notes](#previous-releases) ## Download/Installing - **Option 1:** Download the repo, install pods and run the project! -- **Option 2:** [Download the .app(v1.2.0)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v1.2.0/SwiftyJSONAccelerator.zip) +- **Option 2:** [Download the .app(v1.3.0)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v1.3.0/SwiftyJSONAccelerator.zip) A swift model generator like the Objective-C [JSONAccelerator](http://nerdery.com/json-accelerator). Formats and generates models for the given JSON and also breaks them into files making it easy to manage and share between several models. @@ -53,6 +44,25 @@ Currently, the pattern is very similar to its Objective-C counterpart. It genera - Do the necessary UI changes for the dropdown. - Add tests for your library. +## Previous Releases + +**Version v1.2.0 Released!** + +- Now supports [Marshal](https://github.com/utahiosmac/Marshal)! One of the fastest JSONSerialisation class out there! [(Read more)](https://github.com/bwhiteley/JSONShootout) +- Set `class` as `final`. +- `init` marked as `required` by default for `class`. + +**Version v1.1.0 Released!** + +- Now generates the correct option `struct` and `class` based on what was selected. + +**Version v1.0.0 Released!** + +- Now generates **Swift 3** and the software itself is upgraded to Swift 3. +- Unit tests and complete code coverage for file generation module. +- Modular code to make adding support for other JSON mapping libraries simple. +- Project upgraded with SwiftLint, Travis, CocoaPods etc. + ## Swift 2? [Download (v0.0.6)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v0.0.6/SwiftyJSONAccelerator.zip), the older version of the project, please keep in mind it is **no longer supported**. diff --git a/SwiftyJSONAccelerator/Generators/FileGenerator.swift b/SwiftyJSONAccelerator/Generators/FileGenerator.swift index aa934ff..9ef04f7 100644 --- a/SwiftyJSONAccelerator/Generators/FileGenerator.swift +++ b/SwiftyJSONAccelerator/Generators/FileGenerator.swift @@ -33,6 +33,7 @@ struct FileGenerator { static func generateFileContentWith(_ modelFile: ModelFile, configuration: ModelGenerationConfiguration) -> String { var content = loadFileWith("BaseTemplate") + let singleTab = " ", doubleTab = " " content = content.replacingOccurrences(of: "{OBJECT_NAME}", with: modelFile.fileName) content = content.replacingOccurrences(of: "{DATE}", with: todayDateString()) content = content.replacingOccurrences(of: "{OBJECT_KIND}", with: modelFile.type.rawValue) @@ -73,10 +74,11 @@ struct FileGenerator { content = content.replacingOccurrences(of: "{EXTENDED_OBJECT_COLON}", with: "") } - let stringConstants = modelFile.component.stringConstants.map({ " " + $0 }).joined(separator: "\n") - let declarations = modelFile.component.declarations.map({ " " + $0 }).joined(separator: "\n") - let initialisers = modelFile.component.initialisers.map({ " " + $0 }).joined(separator: "\n") - let description = modelFile.component.description.map({ " " + $0 }).joined(separator: "\n") + + let stringConstants = modelFile.component.stringConstants.map({doubleTab + $0 }).joined(separator: "\n") + let declarations = modelFile.component.declarations.map({ singleTab + $0 }).joined(separator: "\n") + let initialisers = modelFile.component.initialisers.map({doubleTab + $0 }).joined(separator: "\n") + let description = modelFile.component.description.map({ doubleTab + $0 }).joined(separator: "\n") content = content.replacingOccurrences(of: "{STRING_CONSTANT}", with: stringConstants) content = content.replacingOccurrences(of: "{DECLARATION}", with: declarations) @@ -89,8 +91,8 @@ struct FileGenerator { if configuration.supportNSCoding && configuration.constructType == .ClassType { content = content.replacingOccurrences(of: "{NSCODING_SUPPORT}", with: loadFileWith("NSCodingTemplate")) - let encoders = modelFile.component.encoders.map({ " " + $0 }).joined(separator: "\n") - let decoders = modelFile.component.decoders.map({ " " + $0 }).joined(separator: "\n") + let encoders = modelFile.component.encoders.map({ doubleTab + $0 }).joined(separator: "\n") + let decoders = modelFile.component.decoders.map({ doubleTab + $0 }).joined(separator: "\n") content = content.replacingOccurrences(of: "{DECODERS}", with: decoders) content = content.replacingOccurrences(of: "{ENCODERS}", with: encoders) } else { diff --git a/SwiftyJSONAccelerator/Generators/ModelGenerator.swift b/SwiftyJSONAccelerator/Generators/ModelGenerator.swift index 7adc830..337ab4f 100644 --- a/SwiftyJSONAccelerator/Generators/ModelGenerator.swift +++ b/SwiftyJSONAccelerator/Generators/ModelGenerator.swift @@ -66,7 +66,7 @@ public struct ModelGenerator { if let rootObject = object.dictionary { // A model file to store the current model. - var currentModel = self.initaliseModelFileFor(configuration.modelMappingLibrary) + var currentModel = self.initialiseModelFileFor(configuration.modelMappingLibrary) currentModel.setInfo(className, configuration) for (key, value) in rootObject { @@ -139,7 +139,7 @@ public struct ModelGenerator { - returns: A new model file of the required type. */ - func initaliseModelFileFor(_ modelMappingLibrary: JSONMappingLibrary) -> ModelFile { + func initialiseModelFileFor(_ modelMappingLibrary: JSONMappingLibrary) -> ModelFile { switch modelMappingLibrary { case .ObjectMapper: return ObjectMapperModelFile() diff --git a/SwiftyJSONAccelerator/Generators/NameGenerator.swift b/SwiftyJSONAccelerator/Generators/NameGenerator.swift index ab32fdd..16e4b0b 100644 --- a/SwiftyJSONAccelerator/Generators/NameGenerator.swift +++ b/SwiftyJSONAccelerator/Generators/NameGenerator.swift @@ -68,9 +68,8 @@ struct NameGenerator { */ static func replaceKeywords(_ currentName: String) -> String { - let keywordsWithReplacements = ["id": "internalIdentifier", + let keywordsWithReplacements = [ "description": "descriptionValue", - "_id": "internalIdentifier", "class": "classProperty", "struct": "structProperty", "enum": "enumProperty", @@ -91,8 +90,6 @@ struct NameGenerator { - returns: The name for the key for the variable in the given class. */ static func variableKey(_ className: String, _ variableName: String) -> String { - var _variableName = variableName - _variableName.uppercaseFirst() - return "k\(className)\(_variableName)Key" + return "SerializationKeys.\(variableName)" } } diff --git a/SwiftyJSONAccelerator/Models-Components/DefaultModelFileComponent.swift b/SwiftyJSONAccelerator/Models-Components/DefaultModelFileComponent.swift index 8c40a4b..7f48681 100644 --- a/SwiftyJSONAccelerator/Models-Components/DefaultModelFileComponent.swift +++ b/SwiftyJSONAccelerator/Models-Components/DefaultModelFileComponent.swift @@ -116,7 +116,9 @@ protocol DefaultModelFileComponent { extension DefaultModelFileComponent { func genStringConstant(_ constantName: String, _ value: String) -> String { - return "private let \(constantName): String = \"\(value)\"" + //The incoming string is in the format "SeralizationKey.ConstantName" we only need the second part. + let component = constantName.components(separatedBy: ".") + return "static let \(component.last!) = \"\(value)\"" } func genVariableDeclaration(_ name: String, _ type: String, _ isArray: Bool) -> String { @@ -129,7 +131,7 @@ extension DefaultModelFileComponent { func genPrimitiveVariableDeclaration(_ name: String, _ type: String) -> String { if type == VariableType.Bool.rawValue { - return "public var \(name): \(type) = false" + return "public var \(name): \(type)? = false" } return "public var \(name): \(type)?" } diff --git a/SwiftyJSONAccelerator/Models-Components/ModelComponent.swift b/SwiftyJSONAccelerator/Models-Components/ModelComponent.swift index 47b3fbf..6a4e21c 100644 --- a/SwiftyJSONAccelerator/Models-Components/ModelComponent.swift +++ b/SwiftyJSONAccelerator/Models-Components/ModelComponent.swift @@ -27,7 +27,7 @@ internal struct ModelComponent { var description: [String] /** - Initalise a blank model component structure. + Initialise a blank model component structure. */ init() { declarations = [] diff --git a/SwiftyJSONAccelerator/Support/Info.plist b/SwiftyJSONAccelerator/Support/Info.plist index af4017c..9b1bd12 100644 --- a/SwiftyJSONAccelerator/Support/Info.plist +++ b/SwiftyJSONAccelerator/Support/Info.plist @@ -17,11 +17,13 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.2.0 + 1.3.0 CFBundleSignature ???? CFBundleVersion - 8 + 9 + LSApplicationCategoryType + public.app-category.developer-tools LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/SwiftyJSONAccelerator/Templates/BaseTemplate.txt b/SwiftyJSONAccelerator/Templates/BaseTemplate.txt index 2ea2620..99e5416 100644 --- a/SwiftyJSONAccelerator/Templates/BaseTemplate.txt +++ b/SwiftyJSONAccelerator/Templates/BaseTemplate.txt @@ -10,16 +10,17 @@ import Foundation{INCLUDE_HEADER} public{IS_FINAL}{OBJECT_KIND} {OBJECT_NAME}{EXTENDED_OBJECT_COLON}{EXTEND_FROM} { // MARK: Declaration for string constants to be used to decode and also serialize. + private struct SerializationKeys { {STRING_CONSTANT} + } // MARK: Properties {DECLARATION} {JSON_PARSER_LIBRARY_BODY} - /** - Generates description of the object in the form of a NSDictionary. - - returns: A Key value pair containing all valid values in the object. - */ + /// Generates description of the object in the form of a NSDictionary. + /// + /// - returns: A Key value pair containing all valid values in the object. public func dictionaryRepresentation() -> [String: Any] { var dictionary: [String: Any] = [:] {DESCRIPTION} diff --git a/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/MarshalTemplate.txt b/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/MarshalTemplate.txt index de8ad68..6756b40 100644 --- a/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/MarshalTemplate.txt +++ b/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/MarshalTemplate.txt @@ -1,9 +1,8 @@ // MARK: Marshal Initializers - /** - Map a JSON object to this class using ObjectMapper - - parameter map: A mapping from ObjectMapper - */ + /// Map a JSON object to this class using Marshal. + /// + /// - parameter object: A mapping from ObjectMapper public{REQUIRED}init(object: MarshaledObject) { {INITIALIZER} } diff --git a/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/ObjectMapperTemplate.txt b/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/ObjectMapperTemplate.txt index d6c6341..bc59f47 100644 --- a/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/ObjectMapperTemplate.txt +++ b/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/ObjectMapperTemplate.txt @@ -1,16 +1,14 @@ // MARK: ObjectMapper Initializers - /** - Map a JSON object to this class using ObjectMapper - - parameter map: A mapping from ObjectMapper - */ - public{REQUIRED}init?(_ map: Map){ + /// Map a JSON object to this class using ObjectMapper. + /// + /// - parameter map: A mapping from ObjectMapper. + public{REQUIRED}init?(map: Map){ } - /** - Map a JSON object to this class using ObjectMapper - - parameter map: A mapping from ObjectMapper - */ + /// Map a JSON object to this class using ObjectMapper. + /// + /// - parameter map: A mapping from ObjectMapper. public func mapping(map: Map) { {INITIALIZER} } diff --git a/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/SwiftyJSONTemplate.txt b/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/SwiftyJSONTemplate.txt index 054d7fa..62a23c6 100644 --- a/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/SwiftyJSONTemplate.txt +++ b/SwiftyJSONAccelerator/Templates/Library-Extension-Templates/SwiftyJSONTemplate.txt @@ -1,18 +1,15 @@ // MARK: SwiftyJSON Initializers - /** - Initiates the instance based on the object - - parameter object: The object of either Dictionary or Array kind that was passed. - - returns: An initialized instance of the class. - */ + /// Initiates the instance based on the object. + /// + /// - parameter object: The object of either Dictionary or Array kind that was passed. + /// - returns: An initialized instance of the class. public convenience init(object: Any) { self.init(json: JSON(object)) } - /** - Initiates the instance based on the JSON that was passed. - - parameter json: JSON object from SwiftyJSON. - - returns: An initialized instance of the class. - */ + /// Initiates the instance based on the JSON that was passed. + /// + /// - parameter json: JSON object from SwiftyJSON. public{REQUIRED}init(json: JSON) { {INITIALIZER} } diff --git a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift index bb3285b..3b63db5 100644 --- a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift +++ b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift @@ -74,13 +74,13 @@ class ModelGeneratorTests: XCTestCase { /** Test model file initialisation test. */ - func testinitaliseModelFileFor() { + func testinitialiseModelFileFor() { let config = defaultConfiguration(.SwiftyJSON) let m = ModelGenerator.init(JSON.init([testJSON()]), config) - expect(m.initaliseModelFileFor(.SwiftyJSON) is SwiftyJSONModelFile).to(equal(true)) - expect(m.initaliseModelFileFor(.SwiftyJSON) is ObjectMapperModelFile).to(equal(false)) - expect(m.initaliseModelFileFor(.ObjectMapper) is SwiftyJSONModelFile).to(equal(false)) - expect(m.initaliseModelFileFor(.ObjectMapper) is ObjectMapperModelFile).to(equal(true)) + expect(m.initialiseModelFileFor(.SwiftyJSON) is SwiftyJSONModelFile).to(equal(true)) + expect(m.initialiseModelFileFor(.SwiftyJSON) is ObjectMapperModelFile).to(equal(false)) + expect(m.initialiseModelFileFor(.ObjectMapper) is SwiftyJSONModelFile).to(equal(false)) + expect(m.initialiseModelFileFor(.ObjectMapper) is ObjectMapperModelFile).to(equal(true)) } /** @@ -241,14 +241,14 @@ class ModelGeneratorTests: XCTestCase { expect(baseModelFile!.component.stringConstants.count).to(equal(8)) let stringConstants = [ - "private let kACBaseClassValueSevenKey: String = \"value_seven\"", - "private let kACBaseClassValueTwoKey: String = \"value_two\"", - "private let kACBaseClassValueFourKey: String = \"value_four\"", - "private let kACBaseClassValueFiveKey: String = \"value_five\"", - "private let kACBaseClassValueSixKey: String = \"value_six\"", - "private let kACBaseClassValueOneKey: String = \"value_one\"", - "private let kACBaseClassValueThreeKey: String = \"value_three\"", - "private let kACBaseClassValueEightKey: String = \"value_eight\"" + "static let valueSeven = \"value_seven\"", + "static let valueTwo = \"value_two\"", + "static let valueFour = \"value_four\"", + "static let valueFive = \"value_five\"", + "static let valueSix = \"value_six\"", + "static let valueOne = \"value_one\"", + "static let valueThree = \"value_three\"", + "static let valueEight = \"value_eight\"" ] for stringConstant in stringConstants { expect(baseModelFile!.component.stringConstants.contains(stringConstant)).to(equal(true)) @@ -262,7 +262,7 @@ class ModelGeneratorTests: XCTestCase { "public var valueFive: [String]?", "public var valueSix: ACValueSix?", "public var valueOne: String?", - "public var valueThree: Bool = false", + "public var valueThree: Bool? = false", "public var valueEight: [Any]?" ] for declaration in declarations { @@ -271,14 +271,14 @@ class ModelGeneratorTests: XCTestCase { expect(baseModelFile!.component.description.count).to(equal(8)) let descriptions = [ - "if let value = valueSix { dictionary[kACBaseClassValueSixKey] = value.dictionaryRepresentation() }", - "if let value = valueFive { dictionary[kACBaseClassValueFiveKey] = value }", - "if let value = valueTwo { dictionary[kACBaseClassValueTwoKey] = value }", - "dictionary[kACBaseClassValueThreeKey] = valueThree", - "if let value = valueSeven { dictionary[kACBaseClassValueSevenKey] = value.map { $0.dictionaryRepresentation() } }", - "if let value = valueOne { dictionary[kACBaseClassValueOneKey] = value }", - "if let value = valueFour { dictionary[kACBaseClassValueFourKey] = value }", - "if let value = valueEight { dictionary[kACBaseClassValueEightKey] = value }" + "if let value = valueSix { dictionary[SerializationKeys.valueSix] = value.dictionaryRepresentation() }", + "if let value = valueFive { dictionary[SerializationKeys.valueFive] = value }", + "if let value = valueTwo { dictionary[SerializationKeys.valueTwo] = value }", + "dictionary[SerializationKeys.valueThree] = valueThree", + "if let value = valueSeven { dictionary[SerializationKeys.valueSeven] = value.map { $0.dictionaryRepresentation() } }", + "if let value = valueOne { dictionary[SerializationKeys.valueOne] = value }", + "if let value = valueFour { dictionary[SerializationKeys.valueFour] = value }", + "if let value = valueEight { dictionary[SerializationKeys.valueEight] = value }" ] for description in descriptions { expect(baseModelFile!.component.description.contains(description)).to(equal(true)) @@ -286,28 +286,28 @@ class ModelGeneratorTests: XCTestCase { expect(baseModelFile!.component.encoders.count).to(equal(8)) let encoders = [ - "aCoder.encode(valueSeven, forKey: kACBaseClassValueSevenKey)", - "aCoder.encode(valueTwo, forKey: kACBaseClassValueTwoKey)", - "aCoder.encode(valueFour, forKey: kACBaseClassValueFourKey)", - "aCoder.encode(valueFive, forKey: kACBaseClassValueFiveKey)", - "aCoder.encode(valueSix, forKey: kACBaseClassValueSixKey)", - "aCoder.encode(valueOne, forKey: kACBaseClassValueOneKey)", - "aCoder.encode(valueThree, forKey: kACBaseClassValueThreeKey)", - "aCoder.encode(valueEight, forKey: kACBaseClassValueEightKey)"] + "aCoder.encode(valueSeven, forKey: SerializationKeys.valueSeven)", + "aCoder.encode(valueTwo, forKey: SerializationKeys.valueTwo)", + "aCoder.encode(valueFour, forKey: SerializationKeys.valueFour)", + "aCoder.encode(valueFive, forKey: SerializationKeys.valueFive)", + "aCoder.encode(valueSix, forKey: SerializationKeys.valueSix)", + "aCoder.encode(valueOne, forKey: SerializationKeys.valueOne)", + "aCoder.encode(valueThree, forKey: SerializationKeys.valueThree)", + "aCoder.encode(valueEight, forKey: SerializationKeys.valueEight)"] for encoder in encoders { expect(baseModelFile!.component.encoders.contains(encoder)).to(equal(true)) } expect(baseModelFile!.component.decoders.count).to(equal(8)) let decoders = [ - "self.valueSeven = aDecoder.decodeObject(forKey: kACBaseClassValueSevenKey) as? [ACValueSeven]", - "self.valueTwo = aDecoder.decodeObject(forKey: kACBaseClassValueTwoKey) as? Int", - "self.valueFour = aDecoder.decodeObject(forKey: kACBaseClassValueFourKey) as? Float", - "self.valueFive = aDecoder.decodeObject(forKey: kACBaseClassValueFiveKey) as? [String]", - "self.valueSix = aDecoder.decodeObject(forKey: kACBaseClassValueSixKey) as? ACValueSix", - "self.valueOne = aDecoder.decodeObject(forKey: kACBaseClassValueOneKey) as? String", - "self.valueThree = aDecoder.decodeBool(forKey: kACBaseClassValueThreeKey)", - "self.valueEight = aDecoder.decodeObject(forKey: kACBaseClassValueEightKey) as? [Any]" + "self.valueSeven = aDecoder.decodeObject(forKey: SerializationKeys.valueSeven) as? [ACValueSeven]", + "self.valueTwo = aDecoder.decodeObject(forKey: SerializationKeys.valueTwo) as? Int", + "self.valueFour = aDecoder.decodeObject(forKey: SerializationKeys.valueFour) as? Float", + "self.valueFive = aDecoder.decodeObject(forKey: SerializationKeys.valueFive) as? [String]", + "self.valueSix = aDecoder.decodeObject(forKey: SerializationKeys.valueSix) as? ACValueSix", + "self.valueOne = aDecoder.decodeObject(forKey: SerializationKeys.valueOne) as? String", + "self.valueThree = aDecoder.decodeBool(forKey: SerializationKeys.valueThree)", + "self.valueEight = aDecoder.decodeObject(forKey: SerializationKeys.valueEight) as? [Any]" ] for decoder in decoders { expect(baseModelFile!.component.decoders.contains(decoder)).to(equal(true)) @@ -317,14 +317,14 @@ class ModelGeneratorTests: XCTestCase { func runSwiftyJSONInitialiserCheckForBaseModel(_ baseModelFile: ModelFile) { expect(baseModelFile.component.initialisers.count).to(equal(8)) let initialisers = [ - "if let items = json[kACBaseClassValueSevenKey].array { valueSeven = items.map { ACValueSeven(json: $0) } }", - "valueTwo = json[kACBaseClassValueTwoKey].int", - "valueFour = json[kACBaseClassValueFourKey].float", - "if let items = json[kACBaseClassValueFiveKey].array { valueFive = items.map { $0.stringValue } }", - "valueSix = ACValueSix(json: json[kACBaseClassValueSixKey])", - "valueOne = json[kACBaseClassValueOneKey].string", - "valueThree = json[kACBaseClassValueThreeKey].boolValue", - "if let items = json[kACBaseClassValueEightKey].array { valueEight = items.map { $0.object} }" + "if let items = json[SerializationKeys.valueSeven].array { valueSeven = items.map { ACValueSeven(json: $0) } }", + "valueTwo = json[SerializationKeys.valueTwo].int", + "valueFour = json[SerializationKeys.valueFour].float", + "if let items = json[SerializationKeys.valueFive].array { valueFive = items.map { $0.stringValue } }", + "valueSix = ACValueSix(json: json[SerializationKeys.valueSix])", + "valueOne = json[SerializationKeys.valueOne].string", + "valueThree = json[SerializationKeys.valueThree].boolValue", + "if let items = json[SerializationKeys.valueEight].array { valueEight = items.map { $0.object} }" ] for initialiser in initialisers { expect(baseModelFile.component.initialisers.contains(initialiser)).to(equal(true)) @@ -334,14 +334,14 @@ class ModelGeneratorTests: XCTestCase { func runObjectMapperInitialiserCheckForBaseModel(_ baseModelFile: ModelFile) { expect(baseModelFile.component.initialisers.count).to(equal(8)) let initialisers = [ - "valueSeven <- map[kACBaseClassValueSevenKey]", - "valueTwo <- map[kACBaseClassValueTwoKey]", - "valueFour <- map[kACBaseClassValueFourKey]", - "valueFive <- map[kACBaseClassValueFiveKey]", - "valueSix <- map[kACBaseClassValueSixKey]", - "valueEight <- map[kACBaseClassValueEightKey]", - "valueOne <- map[kACBaseClassValueOneKey]", - "valueThree <- map[kACBaseClassValueThreeKey]" + "valueSeven <- map[SerializationKeys.valueSeven]", + "valueTwo <- map[SerializationKeys.valueTwo]", + "valueFour <- map[SerializationKeys.valueFour]", + "valueFive <- map[SerializationKeys.valueFive]", + "valueSix <- map[SerializationKeys.valueSix]", + "valueEight <- map[SerializationKeys.valueEight]", + "valueOne <- map[SerializationKeys.valueOne]", + "valueThree <- map[SerializationKeys.valueThree]" ] for initialiser in initialisers { expect(baseModelFile.component.initialisers.contains(initialiser)).to(equal(true)) @@ -351,14 +351,14 @@ class ModelGeneratorTests: XCTestCase { func runMarshalInitialiserCheckForBaseModel(_ baseModelFile: ModelFile) { expect(baseModelFile.component.initialisers.count).to(equal(8)) let initialisers = [ - "valueSeven = try? object.value(for: kACBaseClassValueSevenKey)", - "valueTwo = try? object.value(for: kACBaseClassValueTwoKey)", - "valueFour = try? object.value(for: kACBaseClassValueFourKey)", - "valueFive = try? object.value(for: kACBaseClassValueFiveKey)", - "valueSix = try? object.value(for: kACBaseClassValueSixKey)", - "valueOne = try? object.value(for: kACBaseClassValueOneKey)", - "valueThree = try? object.value(for: kACBaseClassValueThreeKey)", - "valueEight = try? object.value(for: kACBaseClassValueEightKey)" + "valueSeven = try? object.value(for: SerializationKeys.valueSeven)", + "valueTwo = try? object.value(for: SerializationKeys.valueTwo)", + "valueFour = try? object.value(for: SerializationKeys.valueFour)", + "valueFive = try? object.value(for: SerializationKeys.valueFive)", + "valueSix = try? object.value(for: SerializationKeys.valueSix)", + "valueOne = try? object.value(for: SerializationKeys.valueOne)", + "valueThree = try? object.value(for: SerializationKeys.valueThree)", + "valueEight = try? object.value(for: SerializationKeys.valueEight)" ] for initialiser in initialisers { expect(baseModelFile.component.initialisers.contains(initialiser)).to(equal(true)) diff --git a/SwiftyJSONAcceleratorTests/Support Files/TestJSONFile.json b/SwiftyJSONAcceleratorTests/Support Files/TestJSONFile.json index c8f1d8c..660bbf3 100644 --- a/SwiftyJSONAcceleratorTests/Support Files/TestJSONFile.json +++ b/SwiftyJSONAcceleratorTests/Support Files/TestJSONFile.json @@ -1,22 +1,28 @@ { - "glossary": { - "title": "example glossary", - "GlossDiv": { - "title": "S", - "GlossList": { - "GlossEntry": { - "ID": "SGML", - "SortAs": "SGML", - "GlossTerm": "Standard Generalized Markup Language", - "Acronym": "SGML", - "Abbrev": "ISO 8879:1986", - "GlossDef": { - "para": "A meta-markup language, used to create markup languages such as DocBook.", - "GlossSeeAlso": ["GML", "XML"] - }, - "GlossSee": "markup" - } - } + "glossary": { + "title": "example glossary", + "GlossDiv": { + "isHighlighted": true, + "currentScore": 20, + "title": "S", + "GlossList": { + "GlossEntry": { + "SortAs": "SGML", + "Abbrev": "ISO 8879:1986", + "GlossTerm": "Standard Generalized Markup Language", + "GlossDef": { + "GlossSeeAlso": [ + "GML", + "XML" + ], + "para": "A meta-markup language, used to create markup languages such as DocBook." + }, + "GlossSee": "markup", + "ID": "SGML", + "Acronym": "SGML" } + }, + "starCount": 5 } + } }