forked from loafle/openapi-generator-original
[swift3] empty model with only additional properties (#6273)
This commit is contained in:
parent
ab28c7c825
commit
c2ababbb5b
@ -277,7 +277,7 @@ class Decoders {
|
|||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{^isEnum}}
|
{{^isEnum}}
|
||||||
{{#allVars.isEmpty}}
|
{{#allVars.isEmpty}}
|
||||||
if let source = source as? {{dataType}} {
|
if let source = source as? {{classname}} {
|
||||||
return .success(source)
|
return .success(source)
|
||||||
} else {
|
} else {
|
||||||
return .failure(.typeMismatch(expected: "Typealias {{classname}}", actual: "\(source)"))
|
return .failure(.typeMismatch(expected: "Typealias {{classname}}", actual: "\(source)"))
|
||||||
@ -335,8 +335,11 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for key in propsDictionary.keys {
|
for key in propsDictionary.keys {
|
||||||
if let decodedValue = Decoders.decodeOptional(clazz: String.self, source: propsDictionary[key] as AnyObject?) {
|
switch Decoders.decodeOptional(clazz: String.self, source: propsDictionary[key] as AnyObject?) {
|
||||||
result[key] = decodedValue
|
|
||||||
|
case let .success(value): result[key] = value
|
||||||
|
default: continue
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/additionalPropertiesType}}
|
{{/additionalPropertiesType}}
|
||||||
|
@ -24,10 +24,6 @@ public enum {{classname}}: {{dataType}} {
|
|||||||
}
|
}
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{^isEnum}}
|
{{^isEnum}}
|
||||||
{{#vars.isEmpty}}
|
|
||||||
public typealias {{classname}} = {{dataType}}
|
|
||||||
{{/vars.isEmpty}}
|
|
||||||
{{^vars.isEmpty}}
|
|
||||||
open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}JSONEncodable{{/parent}} {
|
open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}JSONEncodable{{/parent}} {
|
||||||
|
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
@ -102,7 +98,7 @@ open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}JSONEncod
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/vars.isEmpty}}
|
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{/isArrayModel}}
|
{{/isArrayModel}}
|
||||||
{{/model}}
|
{{/model}}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
2.3.0-SNAPSHOT
|
@ -8,6 +8,6 @@ Pod::Spec.new do |s|
|
|||||||
s.license = 'Proprietary'
|
s.license = 'Proprietary'
|
||||||
s.homepage = 'https://github.com/swagger-api/swagger-codegen'
|
s.homepage = 'https://github.com/swagger-api/swagger-codegen'
|
||||||
s.summary = 'SwaggerClient Swift SDK'
|
s.summary = 'SwaggerClient Swift SDK'
|
||||||
s.source_files = 'SwaggerClient/Classes/Swaggers/**/*.swift'
|
s.source_files = 'SwaggerClient/Classes/**/*.swift'
|
||||||
s.dependency 'Alamofire', '~> 3.4.1'
|
s.dependency 'Alamofire', '~> 3.5.1'
|
||||||
end
|
end
|
||||||
|
@ -83,4 +83,97 @@ extension NSUUID: JSONEncodable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents an ISO-8601 full-date (RFC-3339).
|
||||||
|
/// ex: 12-31-1999
|
||||||
|
/// https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||||
|
public final class ISOFullDate: CustomStringConvertible {
|
||||||
|
|
||||||
|
public let year: Int
|
||||||
|
public let month: Int
|
||||||
|
public let day: Int
|
||||||
|
|
||||||
|
public init(year year: Int, month: Int, day: Int) {
|
||||||
|
self.year = year
|
||||||
|
self.month = month
|
||||||
|
self.day = day
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Converts an NSDate to an ISOFullDate. Only interested in the year, month, day components.
|
||||||
|
|
||||||
|
- parameter date: The date to convert.
|
||||||
|
|
||||||
|
- returns: An ISOFullDate constructed from the year, month, day of the date.
|
||||||
|
*/
|
||||||
|
public static func from(date date: NSDate) -> ISOFullDate? {
|
||||||
|
guard let calendar = NSCalendar(identifier: NSCalendarIdentifierGregorian) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let components = calendar.components(
|
||||||
|
[
|
||||||
|
.Year,
|
||||||
|
.Month,
|
||||||
|
.Day,
|
||||||
|
],
|
||||||
|
fromDate: date
|
||||||
|
)
|
||||||
|
return ISOFullDate(
|
||||||
|
year: components.year,
|
||||||
|
month: components.month,
|
||||||
|
day: components.day
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Converts a ISO-8601 full-date string to an ISOFullDate.
|
||||||
|
|
||||||
|
- parameter string: The ISO-8601 full-date format string to convert.
|
||||||
|
|
||||||
|
- returns: An ISOFullDate constructed from the string.
|
||||||
|
*/
|
||||||
|
public static func from(string string: String) -> ISOFullDate? {
|
||||||
|
let components = string
|
||||||
|
.characters
|
||||||
|
.split("-")
|
||||||
|
.map(String.init)
|
||||||
|
.flatMap { Int($0) }
|
||||||
|
guard components.count == 3 else { return nil }
|
||||||
|
|
||||||
|
return ISOFullDate(
|
||||||
|
year: components[0],
|
||||||
|
month: components[1],
|
||||||
|
day: components[2]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Converts the receiver to an NSDate, in the default time zone.
|
||||||
|
|
||||||
|
- returns: An NSDate from the components of the receiver, in the default time zone.
|
||||||
|
*/
|
||||||
|
public func toDate() -> NSDate? {
|
||||||
|
let components = NSDateComponents()
|
||||||
|
components.year = year
|
||||||
|
components.month = month
|
||||||
|
components.day = day
|
||||||
|
components.timeZone = NSTimeZone.defaultTimeZone()
|
||||||
|
let calendar = NSCalendar(identifier: NSCalendarIdentifierGregorian)
|
||||||
|
return calendar?.dateFromComponents(components)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: CustomStringConvertible
|
||||||
|
|
||||||
|
public var description: String {
|
||||||
|
return "\(year)-\(month)-\(day)"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ISOFullDate: JSONEncodable {
|
||||||
|
public func encodeToJSON() -> AnyObject {
|
||||||
|
return "\(year)-\(month)-\(day)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,7 +140,16 @@ class Decoders {
|
|||||||
return NSDate(timeIntervalSince1970: Double(sourceInt / 1000) )
|
return NSDate(timeIntervalSince1970: Double(sourceInt / 1000) )
|
||||||
}
|
}
|
||||||
fatalError("formatter failed to parse \(source)")
|
fatalError("formatter failed to parse \(source)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decoder for ISOFullDate
|
||||||
|
Decoders.addDecoder(clazz: ISOFullDate.self, decoder: { (source: AnyObject) -> ISOFullDate in
|
||||||
|
if let string = source as? String,
|
||||||
|
let isoDate = ISOFullDate.from(string: string) {
|
||||||
|
return isoDate
|
||||||
|
}
|
||||||
|
fatalError("formatter failed to parse \(source)")
|
||||||
|
})
|
||||||
|
|
||||||
// Decoder for [Return]
|
// Decoder for [Return]
|
||||||
Decoders.addDecoder(clazz: [Return].self) { (source: AnyObject) -> [Return] in
|
Decoders.addDecoder(clazz: [Return].self) { (source: AnyObject) -> [Return] in
|
||||||
|
@ -824,7 +824,7 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
// Decoder for OuterBoolean
|
// Decoder for OuterBoolean
|
||||||
Decoders.addDecoder(clazz: OuterBoolean.self) { (source: AnyObject, instance: AnyObject?) -> Decoded<OuterBoolean> in
|
Decoders.addDecoder(clazz: OuterBoolean.self) { (source: AnyObject, instance: AnyObject?) -> Decoded<OuterBoolean> in
|
||||||
if let source = source as? Bool {
|
if let source = source as? OuterBoolean {
|
||||||
return .success(source)
|
return .success(source)
|
||||||
} else {
|
} else {
|
||||||
return .failure(.typeMismatch(expected: "Typealias OuterBoolean", actual: "\(source)"))
|
return .failure(.typeMismatch(expected: "Typealias OuterBoolean", actual: "\(source)"))
|
||||||
@ -864,7 +864,7 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
// Decoder for OuterNumber
|
// Decoder for OuterNumber
|
||||||
Decoders.addDecoder(clazz: OuterNumber.self) { (source: AnyObject, instance: AnyObject?) -> Decoded<OuterNumber> in
|
Decoders.addDecoder(clazz: OuterNumber.self) { (source: AnyObject, instance: AnyObject?) -> Decoded<OuterNumber> in
|
||||||
if let source = source as? Double {
|
if let source = source as? OuterNumber {
|
||||||
return .success(source)
|
return .success(source)
|
||||||
} else {
|
} else {
|
||||||
return .failure(.typeMismatch(expected: "Typealias OuterNumber", actual: "\(source)"))
|
return .failure(.typeMismatch(expected: "Typealias OuterNumber", actual: "\(source)"))
|
||||||
@ -872,7 +872,7 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
// Decoder for OuterString
|
// Decoder for OuterString
|
||||||
Decoders.addDecoder(clazz: OuterString.self) { (source: AnyObject, instance: AnyObject?) -> Decoded<OuterString> in
|
Decoders.addDecoder(clazz: OuterString.self) { (source: AnyObject, instance: AnyObject?) -> Decoded<OuterString> in
|
||||||
if let source = source as? String {
|
if let source = source as? OuterString {
|
||||||
return .success(source)
|
return .success(source)
|
||||||
} else {
|
} else {
|
||||||
return .failure(.typeMismatch(expected: "Typealias OuterString", actual: "\(source)"))
|
return .failure(.typeMismatch(expected: "Typealias OuterString", actual: "\(source)"))
|
||||||
|
@ -25,3 +25,4 @@ open class AdditionalPropertiesClass: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,3 +25,4 @@ open class Animal: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,3 +27,4 @@ open class ApiResponse: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +23,4 @@ open class ArrayOfArrayOfNumberOnly: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +23,4 @@ open class ArrayOfNumberOnly: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,3 +27,4 @@ open class ArrayTest: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,3 +34,4 @@ open class Capitalization: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +23,4 @@ open class Cat: Animal {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,3 +25,4 @@ open class Category: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,3 +24,4 @@ open class ClassModel: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +23,4 @@ open class Client: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +23,4 @@ open class Dog: Animal {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,3 +33,4 @@ open class EnumArrays: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,3 +42,4 @@ open class EnumTest: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,3 +47,4 @@ open class FormatTest: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,3 +25,4 @@ open class HasOnlyReadOnly: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +23,4 @@ open class List: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,3 +28,4 @@ open class MapTest: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,3 +27,4 @@ open class MixedPropertiesAndAdditionalPropertiesClass: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,3 +26,4 @@ open class Model200Response: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,3 +30,4 @@ open class Name: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +23,4 @@ open class NumberOnly: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,3 +39,4 @@ open class Order: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,4 +8,17 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
public typealias OuterBoolean = Bool
|
open class OuterBoolean: JSONEncodable {
|
||||||
|
|
||||||
|
|
||||||
|
public init() {}
|
||||||
|
|
||||||
|
// MARK: JSONEncodable
|
||||||
|
open func encodeToJSON() -> Any {
|
||||||
|
var nillableDictionary = [String:Any?]()
|
||||||
|
|
||||||
|
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||||
|
return dictionary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -27,3 +27,4 @@ open class OuterComposite: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,4 +8,17 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
public typealias OuterNumber = Double
|
open class OuterNumber: JSONEncodable {
|
||||||
|
|
||||||
|
|
||||||
|
public init() {}
|
||||||
|
|
||||||
|
// MARK: JSONEncodable
|
||||||
|
open func encodeToJSON() -> Any {
|
||||||
|
var nillableDictionary = [String:Any?]()
|
||||||
|
|
||||||
|
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||||
|
return dictionary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -8,4 +8,17 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
public typealias OuterString = String
|
open class OuterString: JSONEncodable {
|
||||||
|
|
||||||
|
|
||||||
|
public init() {}
|
||||||
|
|
||||||
|
// MARK: JSONEncodable
|
||||||
|
open func encodeToJSON() -> Any {
|
||||||
|
var nillableDictionary = [String:Any?]()
|
||||||
|
|
||||||
|
let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||||
|
return dictionary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -39,3 +39,4 @@ open class Pet: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,3 +25,4 @@ open class ReadOnlyFirst: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,3 +24,4 @@ open class Return: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +23,4 @@ open class SpecialModelName: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,3 +25,4 @@ open class Tag: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,3 +38,4 @@ open class User: JSONEncodable {
|
|||||||
return dictionary
|
return dictionary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user