Update samples using latest codegen and templates (#7071)

This commit is contained in:
ehyche
2017-11-29 01:49:45 -05:00
committed by William Cheng
parent 80cc90c7c1
commit d2a2292d20
82 changed files with 4869 additions and 54 deletions

View File

@@ -11,14 +11,23 @@ public typealias EncodeResult = (data: Data?, error: Error?)
open class CodableHelper {
open static var dateformatter: DateFormatter?
open class func decode<T>(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable {
var returnedDecodable: T? = nil
var returnedError: Error? = nil
let decoder = JSONDecoder()
decoder.dataDecodingStrategy = .base64
if #available(iOS 10.0, *) {
decoder.dateDecodingStrategy = .iso8601
if let df = self.dateformatter {
decoder.dateDecodingStrategy = .formatted(df)
} else {
decoder.dataDecodingStrategy = .base64
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .iso8601)
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
decoder.dateDecodingStrategy = .formatted(formatter)
}
do {
@@ -39,9 +48,12 @@ open class CodableHelper {
encoder.outputFormatting = .prettyPrinted
}
encoder.dataEncodingStrategy = .base64
if #available(iOS 10.0, *) {
encoder.dateEncodingStrategy = .iso8601
}
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .iso8601)
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
encoder.dateEncodingStrategy = .formatted(formatter)
do {
returnedData = try encoder.encode(value)

View File

@@ -44,7 +44,8 @@ open class AllPrimitives: Codable {
public var myInlineStringEnum: MyInlineStringEnum?
public init(myInteger: Int?, myIntegerArray: [Int]?, myLong: Int64?, myLongArray: [Int64]?, myFloat: Float?, myFloatArray: [Float]?, myDouble: Double?, myDoubleArray: [Double]?, myString: String?, myStringArray: [String]?, myBytes: Data?, myBytesArray: [Data]?, myBoolean: Bool?, myBooleanArray: [Bool]?, myDate: Date?, myDateArray: [Date]?, myDateTime: Date?, myDateTimeArray: [Date]?, myFile: URL?, myFileArray: [URL]?, myUUID: UUID?, myUUIDArray: [UUID]?, myStringEnum: StringEnum?, myStringEnumArray: [StringEnum]?) {
public init(myInteger: Int?, myIntegerArray: [Int]?, myLong: Int64?, myLongArray: [Int64]?, myFloat: Float?, myFloatArray: [Float]?, myDouble: Double?, myDoubleArray: [Double]?, myString: String?, myStringArray: [String]?, myBytes: Data?, myBytesArray: [Data]?, myBoolean: Bool?, myBooleanArray: [Bool]?, myDate: Date?, myDateArray: [Date]?, myDateTime: Date?, myDateTimeArray: [Date]?, myFile: URL?, myFileArray: [URL]?, myUUID: UUID?, myUUIDArray: [UUID]?, myStringEnum: StringEnum?, myStringEnumArray: [StringEnum]?, myInlineStringEnum: MyInlineStringEnum?) {
self.myInteger = myInteger
self.myIntegerArray = myIntegerArray
self.myLong = myLong
@@ -69,7 +70,9 @@ open class AllPrimitives: Codable {
self.myUUIDArray = myUUIDArray
self.myStringEnum = myStringEnum
self.myStringEnumArray = myStringEnumArray
self.myInlineStringEnum = myInlineStringEnum
}
// Encodable protocol methods
@@ -78,29 +81,29 @@ open class AllPrimitives: Codable {
var container = encoder.container(keyedBy: String.self)
try container.encodeIfPresent(myInteger, forKey: "myInteger")
try container.encodeArrayIfPresent(myIntegerArray, forKey: "myIntegerArray")
try container.encodeIfPresent(myIntegerArray, forKey: "myIntegerArray")
try container.encodeIfPresent(myLong, forKey: "myLong")
try container.encodeArrayIfPresent(myLongArray, forKey: "myLongArray")
try container.encodeIfPresent(myLongArray, forKey: "myLongArray")
try container.encodeIfPresent(myFloat, forKey: "myFloat")
try container.encodeArrayIfPresent(myFloatArray, forKey: "myFloatArray")
try container.encodeIfPresent(myFloatArray, forKey: "myFloatArray")
try container.encodeIfPresent(myDouble, forKey: "myDouble")
try container.encodeArrayIfPresent(myDoubleArray, forKey: "myDoubleArray")
try container.encodeIfPresent(myDoubleArray, forKey: "myDoubleArray")
try container.encodeIfPresent(myString, forKey: "myString")
try container.encodeArrayIfPresent(myStringArray, forKey: "myStringArray")
try container.encodeIfPresent(myStringArray, forKey: "myStringArray")
try container.encodeIfPresent(myBytes, forKey: "myBytes")
try container.encodeArrayIfPresent(myBytesArray, forKey: "myBytesArray")
try container.encodeIfPresent(myBytesArray, forKey: "myBytesArray")
try container.encodeIfPresent(myBoolean, forKey: "myBoolean")
try container.encodeArrayIfPresent(myBooleanArray, forKey: "myBooleanArray")
try container.encodeIfPresent(myBooleanArray, forKey: "myBooleanArray")
try container.encodeIfPresent(myDate, forKey: "myDate")
try container.encodeArrayIfPresent(myDateArray, forKey: "myDateArray")
try container.encodeIfPresent(myDateArray, forKey: "myDateArray")
try container.encodeIfPresent(myDateTime, forKey: "myDateTime")
try container.encodeArrayIfPresent(myDateTimeArray, forKey: "myDateTimeArray")
try container.encodeIfPresent(myDateTimeArray, forKey: "myDateTimeArray")
try container.encodeIfPresent(myFile, forKey: "myFile")
try container.encodeArrayIfPresent(myFileArray, forKey: "myFileArray")
try container.encodeIfPresent(myFileArray, forKey: "myFileArray")
try container.encodeIfPresent(myUUID, forKey: "myUUID")
try container.encodeArrayIfPresent(myUUIDArray, forKey: "myUUIDArray")
try container.encodeIfPresent(myUUIDArray, forKey: "myUUIDArray")
try container.encodeIfPresent(myStringEnum, forKey: "myStringEnum")
try container.encodeArrayIfPresent(myStringEnumArray, forKey: "myStringEnumArray")
try container.encodeIfPresent(myStringEnumArray, forKey: "myStringEnumArray")
try container.encodeIfPresent(myInlineStringEnum, forKey: "myInlineStringEnum")
}
@@ -110,29 +113,29 @@ open class AllPrimitives: Codable {
let container = try decoder.container(keyedBy: String.self)
myInteger = try container.decodeIfPresent(Int.self, forKey: "myInteger")
myIntegerArray = try container.decodeArrayIfPresent(Int.self, forKey: "myIntegerArray")
myIntegerArray = try container.decodeIfPresent([Int].self, forKey: "myIntegerArray")
myLong = try container.decodeIfPresent(Int64.self, forKey: "myLong")
myLongArray = try container.decodeArrayIfPresent(Int64.self, forKey: "myLongArray")
myLongArray = try container.decodeIfPresent([Int64].self, forKey: "myLongArray")
myFloat = try container.decodeIfPresent(Float.self, forKey: "myFloat")
myFloatArray = try container.decodeArrayIfPresent(Float.self, forKey: "myFloatArray")
myFloatArray = try container.decodeIfPresent([Float].self, forKey: "myFloatArray")
myDouble = try container.decodeIfPresent(Double.self, forKey: "myDouble")
myDoubleArray = try container.decodeArrayIfPresent(Double.self, forKey: "myDoubleArray")
myDoubleArray = try container.decodeIfPresent([Double].self, forKey: "myDoubleArray")
myString = try container.decodeIfPresent(String.self, forKey: "myString")
myStringArray = try container.decodeArrayIfPresent(String.self, forKey: "myStringArray")
myStringArray = try container.decodeIfPresent([String].self, forKey: "myStringArray")
myBytes = try container.decodeIfPresent(Data.self, forKey: "myBytes")
myBytesArray = try container.decodeArrayIfPresent(Data.self, forKey: "myBytesArray")
myBytesArray = try container.decodeIfPresent([Data].self, forKey: "myBytesArray")
myBoolean = try container.decodeIfPresent(Bool.self, forKey: "myBoolean")
myBooleanArray = try container.decodeArrayIfPresent(Bool.self, forKey: "myBooleanArray")
myBooleanArray = try container.decodeIfPresent([Bool].self, forKey: "myBooleanArray")
myDate = try container.decodeIfPresent(Date.self, forKey: "myDate")
myDateArray = try container.decodeArrayIfPresent(Date.self, forKey: "myDateArray")
myDateArray = try container.decodeIfPresent([Date].self, forKey: "myDateArray")
myDateTime = try container.decodeIfPresent(Date.self, forKey: "myDateTime")
myDateTimeArray = try container.decodeArrayIfPresent(Date.self, forKey: "myDateTimeArray")
myDateTimeArray = try container.decodeIfPresent([Date].self, forKey: "myDateTimeArray")
myFile = try container.decodeIfPresent(URL.self, forKey: "myFile")
myFileArray = try container.decodeArrayIfPresent(URL.self, forKey: "myFileArray")
myFileArray = try container.decodeIfPresent([URL].self, forKey: "myFileArray")
myUUID = try container.decodeIfPresent(UUID.self, forKey: "myUUID")
myUUIDArray = try container.decodeArrayIfPresent(UUID.self, forKey: "myUUIDArray")
myUUIDArray = try container.decodeIfPresent([UUID].self, forKey: "myUUIDArray")
myStringEnum = try container.decodeIfPresent(StringEnum.self, forKey: "myStringEnum")
myStringEnumArray = try container.decodeArrayIfPresent(StringEnum.self, forKey: "myStringEnumArray")
myStringEnumArray = try container.decodeIfPresent([StringEnum].self, forKey: "myStringEnumArray")
myInlineStringEnum = try container.decodeIfPresent(MyInlineStringEnum.self, forKey: "myInlineStringEnum")
}
}

View File

@@ -17,11 +17,13 @@ open class ErrorInfo: Codable {
public var details: [String]?
public init(code: Int?, message: String?, details: [String]?) {
self.code = code
self.message = message
self.details = details
}
// Encodable protocol methods
@@ -31,7 +33,7 @@ open class ErrorInfo: Codable {
try container.encodeIfPresent(code, forKey: "code")
try container.encodeIfPresent(message, forKey: "message")
try container.encodeArrayIfPresent(details, forKey: "details")
try container.encodeIfPresent(details, forKey: "details")
}
// Decodable protocol methods
@@ -41,7 +43,7 @@ open class ErrorInfo: Codable {
code = try container.decodeIfPresent(Int.self, forKey: "code")
message = try container.decodeIfPresent(String.self, forKey: "message")
details = try container.decodeArrayIfPresent(String.self, forKey: "details")
details = try container.decodeIfPresent([String].self, forKey: "details")
}
}

View File

@@ -17,11 +17,13 @@ open class GetAllModelsResult: Codable {
public var myVariableNameTest: VariableNameTest?
public init(myPrimitiveArray: [AllPrimitives]?, myPrimitive: AllPrimitives?, myVariableNameTest: VariableNameTest?) {
self.myPrimitiveArray = myPrimitiveArray
self.myPrimitive = myPrimitive
self.myVariableNameTest = myVariableNameTest
}
// Encodable protocol methods
@@ -29,7 +31,7 @@ open class GetAllModelsResult: Codable {
var container = encoder.container(keyedBy: String.self)
try container.encodeArrayIfPresent(myPrimitiveArray, forKey: "myPrimitiveArray")
try container.encodeIfPresent(myPrimitiveArray, forKey: "myPrimitiveArray")
try container.encodeIfPresent(myPrimitive, forKey: "myPrimitive")
try container.encodeIfPresent(myVariableNameTest, forKey: "myVariableNameTest")
}
@@ -39,7 +41,7 @@ open class GetAllModelsResult: Codable {
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)
myPrimitiveArray = try container.decodeArrayIfPresent(AllPrimitives.self, forKey: "myPrimitiveArray")
myPrimitiveArray = try container.decodeIfPresent([AllPrimitives].self, forKey: "myPrimitiveArray")
myPrimitive = try container.decodeIfPresent(AllPrimitives.self, forKey: "myPrimitive")
myVariableNameTest = try container.decodeIfPresent(VariableNameTest.self, forKey: "myVariableNameTest")
}

View File

@@ -28,6 +28,7 @@ open class ModelWithIntAdditionalPropertiesOnly: Codable {
}
}
// Encodable protocol methods

View File

@@ -36,6 +36,7 @@ open class ModelWithPropertiesAndAdditionalProperties: Codable {
}
}
public init(myIntegerReq: Int, myIntegerOpt: Int?, myPrimitiveReq: AllPrimitives, myPrimitiveOpt: AllPrimitives?, myStringArrayReq: [String], myStringArrayOpt: [String]?, myPrimitiveArrayReq: [AllPrimitives], myPrimitiveArrayOpt: [AllPrimitives]?) {
self.myIntegerReq = myIntegerReq
self.myIntegerOpt = myIntegerOpt
@@ -46,6 +47,7 @@ open class ModelWithPropertiesAndAdditionalProperties: Codable {
self.myPrimitiveArrayReq = myPrimitiveArrayReq
self.myPrimitiveArrayOpt = myPrimitiveArrayOpt
}
// Encodable protocol methods
@@ -57,10 +59,10 @@ open class ModelWithPropertiesAndAdditionalProperties: Codable {
try container.encodeIfPresent(myIntegerOpt, forKey: "myIntegerOpt")
try container.encode(myPrimitiveReq, forKey: "myPrimitiveReq")
try container.encodeIfPresent(myPrimitiveOpt, forKey: "myPrimitiveOpt")
try container.encodeArray(myStringArrayReq, forKey: "myStringArrayReq")
try container.encodeArrayIfPresent(myStringArrayOpt, forKey: "myStringArrayOpt")
try container.encodeArray(myPrimitiveArrayReq, forKey: "myPrimitiveArrayReq")
try container.encodeArrayIfPresent(myPrimitiveArrayOpt, forKey: "myPrimitiveArrayOpt")
try container.encode(myStringArrayReq, forKey: "myStringArrayReq")
try container.encodeIfPresent(myStringArrayOpt, forKey: "myStringArrayOpt")
try container.encode(myPrimitiveArrayReq, forKey: "myPrimitiveArrayReq")
try container.encodeIfPresent(myPrimitiveArrayOpt, forKey: "myPrimitiveArrayOpt")
try container.encodeMap(additionalProperties)
}
@@ -73,10 +75,10 @@ open class ModelWithPropertiesAndAdditionalProperties: Codable {
myIntegerOpt = try container.decodeIfPresent(Int.self, forKey: "myIntegerOpt")
myPrimitiveReq = try container.decode(AllPrimitives.self, forKey: "myPrimitiveReq")
myPrimitiveOpt = try container.decodeIfPresent(AllPrimitives.self, forKey: "myPrimitiveOpt")
myStringArrayReq = try container.decodeArray(String.self, forKey: "myStringArrayReq")
myStringArrayOpt = try container.decodeArrayIfPresent(String.self, forKey: "myStringArrayOpt")
myPrimitiveArrayReq = try container.decodeArray(AllPrimitives.self, forKey: "myPrimitiveArrayReq")
myPrimitiveArrayOpt = try container.decodeArrayIfPresent(AllPrimitives.self, forKey: "myPrimitiveArrayOpt")
myStringArrayReq = try container.decode([String].self, forKey: "myStringArrayReq")
myStringArrayOpt = try container.decodeIfPresent([String].self, forKey: "myStringArrayOpt")
myPrimitiveArrayReq = try container.decode([AllPrimitives].self, forKey: "myPrimitiveArrayReq")
myPrimitiveArrayOpt = try container.decodeIfPresent([AllPrimitives].self, forKey: "myPrimitiveArrayOpt")
var nonAdditionalPropertyKeys = Set<String>()
nonAdditionalPropertyKeys.insert("myIntegerReq")
nonAdditionalPropertyKeys.insert("myIntegerOpt")

View File

@@ -28,6 +28,7 @@ open class ModelWithStringAdditionalPropertiesOnly: Codable {
}
}
// Encodable protocol methods

View File

@@ -18,10 +18,12 @@ open class VariableNameTest: Codable {
public var _for: String?
public init(exampleName: String?, _for: String?) {
self.exampleName = exampleName
self._for = _for
}
// Encodable protocol methods