Skip to content

Commit

Permalink
[swift3] empty model with only additional properties
Browse files Browse the repository at this point in the history
  • Loading branch information
dwbiid authored and Michael Kaye committed Aug 9, 2017
1 parent 974a2ab commit fa43b61
Show file tree
Hide file tree
Showing 43 changed files with 287 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class Decoders {
{{/isEnum}}
{{^isEnum}}
{{#allVars.isEmpty}}
if let source = source as? {{dataType}} {
if let source = source as? {{classname}} {
return .success(source)
} else {
return .failure(.typeMismatch(expected: "Typealias {{classname}}", actual: "\(source)"))
Expand Down Expand Up @@ -335,8 +335,11 @@ class Decoders {
}

for key in propsDictionary.keys {
if let decodedValue = Decoders.decodeOptional(clazz: String.self, source: propsDictionary[key] as AnyObject?) {
result[key] = decodedValue
switch Decoders.decodeOptional(clazz: String.self, source: propsDictionary[key] as AnyObject?) {
case let .success(value): result[key] = value
default: continue
}
}
{{/additionalPropertiesType}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public enum {{classname}}: {{dataType}} {
}
{{/isEnum}}
{{^isEnum}}
{{#vars.isEmpty}}
public typealias {{classname}} = {{dataType}}
{{/vars.isEmpty}}
{{^vars.isEmpty}}
open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}JSONEncodable{{/parent}} {
{{#vars}}
Expand Down Expand Up @@ -102,7 +98,7 @@ open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}JSONEncod
return dictionary
}
}
{{/vars.isEmpty}}

{{/isEnum}}
{{/isArrayModel}}
{{/model}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Pod::Spec.new do |s|
s.license = 'Proprietary'
s.homepage = 'https://github.com/swagger-api/swagger-codegen'
s.summary = 'SwaggerClient Swift SDK'
s.source_files = 'SwaggerClient/Classes/Swaggers/**/*.swift'
s.dependency 'Alamofire', '~> 3.4.1'
s.source_files = 'SwaggerClient/Classes/**/*.swift'
s.dependency 'Alamofire', '~> 3.5.1'
end
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,16 @@ class Decoders {
return NSDate(timeIntervalSince1970: Double(sourceInt / 1000) )
}
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]
Decoders.addDecoder(clazz: [Return].self) { (source: AnyObject) -> [Return] in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ open class FakeAPI: APIBase {
- To test \"client\" model
- examples: [{contentType=application/json, example={
"client" : "client"
"client" : "aeiou"
}}]
- parameter body: (body) client model
- returns: RequestBuilder<Client>
Expand Down Expand Up @@ -191,7 +191,7 @@ open class FakeAPI: APIBase {
- parameter callback: (form) None (optional)
- parameter completion: completion handler to receive the data and the error objects
*/
open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int32? = nil, int32: Int32? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: ISOFullDate? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int32? = nil, int32: Int32? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute { (response, error) -> Void in
completion(error)
}
Expand Down Expand Up @@ -221,7 +221,7 @@ open class FakeAPI: APIBase {
- parameter callback: (form) None (optional)
- returns: RequestBuilder<Void>
*/
open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int32? = nil, int32: Int32? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: ISOFullDate? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> {
open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int32? = nil, int32: Int32? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> {
let path = "/fake"
let URLString = PetstoreClientAPI.basePath + path
let formParams: [String:Any?] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ open class Fake_classname_tags123API: APIBase {
- type: apiKey api_key_query (QUERY)
- name: api_key_query
- examples: [{contentType=application/json, example={
"client" : "client"
"client" : "aeiou"
}}]
- parameter body: (body) client model
- returns: RequestBuilder<Client>
Expand Down
Loading

0 comments on commit fa43b61

Please sign in to comment.