forked from loafle/openapi-generator-original
[Swift3][bug#4318] Bug when handling java date (#4332)
* fix bug #4318 * swift3 samples update
This commit is contained in:
parent
8153f0e89b
commit
b7984e55a7
@ -126,7 +126,8 @@ class Decoders {
|
|||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ",
|
"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss'Z'",
|
"yyyy-MM-dd'T'HH:mm:ss'Z'",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSS"
|
"yyyy-MM-dd'T'HH:mm:ss.SSS",
|
||||||
|
"yyyy-MM-dd HH:mm:ss"
|
||||||
].map { (format: String) -> DateFormatter in
|
].map { (format: String) -> DateFormatter in
|
||||||
let formatter = DateFormatter()
|
let formatter = DateFormatter()
|
||||||
formatter.dateFormat = format
|
formatter.dateFormat = format
|
||||||
@ -141,7 +142,7 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let sourceInt = source as? Int {
|
if let sourceInt = source as? Int64 {
|
||||||
// treat as a java date
|
// treat as a java date
|
||||||
return Date(timeIntervalSince1970: Double(sourceInt / 1000) )
|
return Date(timeIntervalSince1970: Double(sourceInt / 1000) )
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,8 @@ class Decoders {
|
|||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ",
|
"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss'Z'",
|
"yyyy-MM-dd'T'HH:mm:ss'Z'",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSS"
|
"yyyy-MM-dd'T'HH:mm:ss.SSS",
|
||||||
|
"yyyy-MM-dd HH:mm:ss"
|
||||||
].map { (format: String) -> DateFormatter in
|
].map { (format: String) -> DateFormatter in
|
||||||
let formatter = DateFormatter()
|
let formatter = DateFormatter()
|
||||||
formatter.dateFormat = format
|
formatter.dateFormat = format
|
||||||
@ -141,7 +142,7 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let sourceInt = source as? Int {
|
if let sourceInt = source as? Int64 {
|
||||||
// treat as a java date
|
// treat as a java date
|
||||||
return Date(timeIntervalSince1970: Double(sourceInt / 1000) )
|
return Date(timeIntervalSince1970: Double(sourceInt / 1000) )
|
||||||
}
|
}
|
||||||
@ -284,6 +285,20 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Decoder for [ClassModel]
|
||||||
|
Decoders.addDecoder(clazz: [ClassModel].self) { (source: AnyObject) -> [ClassModel] in
|
||||||
|
return Decoders.decode(clazz: [ClassModel].self, source: source)
|
||||||
|
}
|
||||||
|
// Decoder for ClassModel
|
||||||
|
Decoders.addDecoder(clazz: ClassModel.self) { (source: AnyObject) -> ClassModel in
|
||||||
|
let sourceDictionary = source as! [AnyHashable: Any]
|
||||||
|
|
||||||
|
let instance = ClassModel()
|
||||||
|
instance._class = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["_class"] as AnyObject?)
|
||||||
|
return instance
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Decoder for [Client]
|
// Decoder for [Client]
|
||||||
Decoders.addDecoder(clazz: [Client].self) { (source: AnyObject) -> [Client] in
|
Decoders.addDecoder(clazz: [Client].self) { (source: AnyObject) -> [Client] in
|
||||||
return Decoders.decode(clazz: [Client].self, source: source)
|
return Decoders.decode(clazz: [Client].self, source: source)
|
||||||
@ -371,6 +386,7 @@ class Decoders {
|
|||||||
instance.enumNumber = EnumTest.EnumNumber(rawValue: (enumNumber))
|
instance.enumNumber = EnumTest.EnumNumber(rawValue: (enumNumber))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance.outerEnum = Decoders.decodeOptional(clazz: OuterEnum.self, source: sourceDictionary["outerEnum"] as AnyObject?)
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,6 +547,21 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Decoder for [OuterEnum]
|
||||||
|
Decoders.addDecoder(clazz: [OuterEnum].self) { (source: AnyObject) -> [OuterEnum] in
|
||||||
|
return Decoders.decode(clazz: [OuterEnum].self, source: source)
|
||||||
|
}
|
||||||
|
// Decoder for OuterEnum
|
||||||
|
Decoders.addDecoder(clazz: OuterEnum.self) { (source: AnyObject) -> OuterEnum in
|
||||||
|
if let source = source as? String {
|
||||||
|
if let result = OuterEnum(rawValue: source) {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fatalError("Source \(source) is not convertible to enum type OuterEnum: Maybe swagger file is insufficient")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Decoder for [Pet]
|
// Decoder for [Pet]
|
||||||
Decoders.addDecoder(clazz: [Pet].self) { (source: AnyObject) -> [Pet] in
|
Decoders.addDecoder(clazz: [Pet].self) { (source: AnyObject) -> [Pet] in
|
||||||
return Decoders.decode(clazz: [Pet].self, source: source)
|
return Decoders.decode(clazz: [Pet].self, source: source)
|
||||||
|
@ -24,6 +24,7 @@ open class EnumTest: JSONEncodable {
|
|||||||
public var enumString: EnumString?
|
public var enumString: EnumString?
|
||||||
public var enumInteger: EnumInteger?
|
public var enumInteger: EnumInteger?
|
||||||
public var enumNumber: EnumNumber?
|
public var enumNumber: EnumNumber?
|
||||||
|
public var outerEnum: OuterEnum?
|
||||||
|
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ open class EnumTest: JSONEncodable {
|
|||||||
nillableDictionary["enum_string"] = self.enumString?.rawValue
|
nillableDictionary["enum_string"] = self.enumString?.rawValue
|
||||||
nillableDictionary["enum_integer"] = self.enumInteger?.rawValue
|
nillableDictionary["enum_integer"] = self.enumInteger?.rawValue
|
||||||
nillableDictionary["enum_number"] = self.enumNumber?.rawValue
|
nillableDictionary["enum_number"] = self.enumNumber?.rawValue
|
||||||
|
nillableDictionary["outerEnum"] = self.outerEnum?.encodeToJSON()
|
||||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,8 @@ class Decoders {
|
|||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ",
|
"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss'Z'",
|
"yyyy-MM-dd'T'HH:mm:ss'Z'",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSS"
|
"yyyy-MM-dd'T'HH:mm:ss.SSS",
|
||||||
|
"yyyy-MM-dd HH:mm:ss"
|
||||||
].map { (format: String) -> DateFormatter in
|
].map { (format: String) -> DateFormatter in
|
||||||
let formatter = DateFormatter()
|
let formatter = DateFormatter()
|
||||||
formatter.dateFormat = format
|
formatter.dateFormat = format
|
||||||
@ -141,7 +142,7 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let sourceInt = source as? Int {
|
if let sourceInt = source as? Int64 {
|
||||||
// treat as a java date
|
// treat as a java date
|
||||||
return Date(timeIntervalSince1970: Double(sourceInt / 1000) )
|
return Date(timeIntervalSince1970: Double(sourceInt / 1000) )
|
||||||
}
|
}
|
||||||
@ -284,6 +285,20 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Decoder for [ClassModel]
|
||||||
|
Decoders.addDecoder(clazz: [ClassModel].self) { (source: AnyObject) -> [ClassModel] in
|
||||||
|
return Decoders.decode(clazz: [ClassModel].self, source: source)
|
||||||
|
}
|
||||||
|
// Decoder for ClassModel
|
||||||
|
Decoders.addDecoder(clazz: ClassModel.self) { (source: AnyObject) -> ClassModel in
|
||||||
|
let sourceDictionary = source as! [AnyHashable: Any]
|
||||||
|
|
||||||
|
let instance = ClassModel()
|
||||||
|
instance._class = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["_class"] as AnyObject?)
|
||||||
|
return instance
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Decoder for [Client]
|
// Decoder for [Client]
|
||||||
Decoders.addDecoder(clazz: [Client].self) { (source: AnyObject) -> [Client] in
|
Decoders.addDecoder(clazz: [Client].self) { (source: AnyObject) -> [Client] in
|
||||||
return Decoders.decode(clazz: [Client].self, source: source)
|
return Decoders.decode(clazz: [Client].self, source: source)
|
||||||
@ -371,6 +386,7 @@ class Decoders {
|
|||||||
instance.enumNumber = EnumTest.EnumNumber(rawValue: (enumNumber))
|
instance.enumNumber = EnumTest.EnumNumber(rawValue: (enumNumber))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance.outerEnum = Decoders.decodeOptional(clazz: OuterEnum.self, source: sourceDictionary["outerEnum"] as AnyObject?)
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,6 +547,21 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Decoder for [OuterEnum]
|
||||||
|
Decoders.addDecoder(clazz: [OuterEnum].self) { (source: AnyObject) -> [OuterEnum] in
|
||||||
|
return Decoders.decode(clazz: [OuterEnum].self, source: source)
|
||||||
|
}
|
||||||
|
// Decoder for OuterEnum
|
||||||
|
Decoders.addDecoder(clazz: OuterEnum.self) { (source: AnyObject) -> OuterEnum in
|
||||||
|
if let source = source as? String {
|
||||||
|
if let result = OuterEnum(rawValue: source) {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fatalError("Source \(source) is not convertible to enum type OuterEnum: Maybe swagger file is insufficient")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Decoder for [Pet]
|
// Decoder for [Pet]
|
||||||
Decoders.addDecoder(clazz: [Pet].self) { (source: AnyObject) -> [Pet] in
|
Decoders.addDecoder(clazz: [Pet].self) { (source: AnyObject) -> [Pet] in
|
||||||
return Decoders.decode(clazz: [Pet].self, source: source)
|
return Decoders.decode(clazz: [Pet].self, source: source)
|
||||||
|
@ -24,6 +24,7 @@ open class EnumTest: JSONEncodable {
|
|||||||
public var enumString: EnumString?
|
public var enumString: EnumString?
|
||||||
public var enumInteger: EnumInteger?
|
public var enumInteger: EnumInteger?
|
||||||
public var enumNumber: EnumNumber?
|
public var enumNumber: EnumNumber?
|
||||||
|
public var outerEnum: OuterEnum?
|
||||||
|
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ open class EnumTest: JSONEncodable {
|
|||||||
nillableDictionary["enum_string"] = self.enumString?.rawValue
|
nillableDictionary["enum_string"] = self.enumString?.rawValue
|
||||||
nillableDictionary["enum_integer"] = self.enumInteger?.rawValue
|
nillableDictionary["enum_integer"] = self.enumInteger?.rawValue
|
||||||
nillableDictionary["enum_number"] = self.enumNumber?.rawValue
|
nillableDictionary["enum_number"] = self.enumNumber?.rawValue
|
||||||
|
nillableDictionary["outerEnum"] = self.outerEnum?.encodeToJSON()
|
||||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,8 @@ class Decoders {
|
|||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ",
|
"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss'Z'",
|
"yyyy-MM-dd'T'HH:mm:ss'Z'",
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSS"
|
"yyyy-MM-dd'T'HH:mm:ss.SSS",
|
||||||
|
"yyyy-MM-dd HH:mm:ss"
|
||||||
].map { (format: String) -> DateFormatter in
|
].map { (format: String) -> DateFormatter in
|
||||||
let formatter = DateFormatter()
|
let formatter = DateFormatter()
|
||||||
formatter.dateFormat = format
|
formatter.dateFormat = format
|
||||||
@ -141,7 +142,7 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let sourceInt = source as? Int {
|
if let sourceInt = source as? Int64 {
|
||||||
// treat as a java date
|
// treat as a java date
|
||||||
return Date(timeIntervalSince1970: Double(sourceInt / 1000) )
|
return Date(timeIntervalSince1970: Double(sourceInt / 1000) )
|
||||||
}
|
}
|
||||||
@ -284,6 +285,20 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Decoder for [ClassModel]
|
||||||
|
Decoders.addDecoder(clazz: [ClassModel].self) { (source: AnyObject) -> [ClassModel] in
|
||||||
|
return Decoders.decode(clazz: [ClassModel].self, source: source)
|
||||||
|
}
|
||||||
|
// Decoder for ClassModel
|
||||||
|
Decoders.addDecoder(clazz: ClassModel.self) { (source: AnyObject) -> ClassModel in
|
||||||
|
let sourceDictionary = source as! [AnyHashable: Any]
|
||||||
|
|
||||||
|
let instance = ClassModel()
|
||||||
|
instance._class = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["_class"] as AnyObject?)
|
||||||
|
return instance
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Decoder for [Client]
|
// Decoder for [Client]
|
||||||
Decoders.addDecoder(clazz: [Client].self) { (source: AnyObject) -> [Client] in
|
Decoders.addDecoder(clazz: [Client].self) { (source: AnyObject) -> [Client] in
|
||||||
return Decoders.decode(clazz: [Client].self, source: source)
|
return Decoders.decode(clazz: [Client].self, source: source)
|
||||||
@ -371,6 +386,7 @@ class Decoders {
|
|||||||
instance.enumNumber = EnumTest.EnumNumber(rawValue: (enumNumber))
|
instance.enumNumber = EnumTest.EnumNumber(rawValue: (enumNumber))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance.outerEnum = Decoders.decodeOptional(clazz: OuterEnum.self, source: sourceDictionary["outerEnum"] as AnyObject?)
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,6 +547,21 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Decoder for [OuterEnum]
|
||||||
|
Decoders.addDecoder(clazz: [OuterEnum].self) { (source: AnyObject) -> [OuterEnum] in
|
||||||
|
return Decoders.decode(clazz: [OuterEnum].self, source: source)
|
||||||
|
}
|
||||||
|
// Decoder for OuterEnum
|
||||||
|
Decoders.addDecoder(clazz: OuterEnum.self) { (source: AnyObject) -> OuterEnum in
|
||||||
|
if let source = source as? String {
|
||||||
|
if let result = OuterEnum(rawValue: source) {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fatalError("Source \(source) is not convertible to enum type OuterEnum: Maybe swagger file is insufficient")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Decoder for [Pet]
|
// Decoder for [Pet]
|
||||||
Decoders.addDecoder(clazz: [Pet].self) { (source: AnyObject) -> [Pet] in
|
Decoders.addDecoder(clazz: [Pet].self) { (source: AnyObject) -> [Pet] in
|
||||||
return Decoders.decode(clazz: [Pet].self, source: source)
|
return Decoders.decode(clazz: [Pet].self, source: source)
|
||||||
|
@ -24,6 +24,7 @@ open class EnumTest: JSONEncodable {
|
|||||||
public var enumString: EnumString?
|
public var enumString: EnumString?
|
||||||
public var enumInteger: EnumInteger?
|
public var enumInteger: EnumInteger?
|
||||||
public var enumNumber: EnumNumber?
|
public var enumNumber: EnumNumber?
|
||||||
|
public var outerEnum: OuterEnum?
|
||||||
|
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ open class EnumTest: JSONEncodable {
|
|||||||
nillableDictionary["enum_string"] = self.enumString?.rawValue
|
nillableDictionary["enum_string"] = self.enumString?.rawValue
|
||||||
nillableDictionary["enum_integer"] = self.enumInteger?.rawValue
|
nillableDictionary["enum_integer"] = self.enumInteger?.rawValue
|
||||||
nillableDictionary["enum_number"] = self.enumNumber?.rawValue
|
nillableDictionary["enum_number"] = self.enumNumber?.rawValue
|
||||||
|
nillableDictionary["outerEnum"] = self.outerEnum?.encodeToJSON()
|
||||||
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user