Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oracle64-1.8.0.152
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class AlamofireRequestBuilder<T>: RequestBuilder<T> {
}
self.processRequest(uploadRequest, managerId, completion)
case .Failure(let encodingError):
completion(response: nil, error: ErrorResponse.Error(415, nil, encodingError))
completion(response: nil, error: ErrorResponse.error(415, nil, encodingError))
}
}
)
Expand Down Expand Up @@ -121,7 +121,7 @@ class AlamofireRequestBuilder<T>: RequestBuilder<T> {
if stringResponse.result.isFailure {
completion(
response: nil,
error: ErrorResponse.Error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error!)
error: ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error!)
)
return
}
Expand All @@ -141,7 +141,7 @@ class AlamofireRequestBuilder<T>: RequestBuilder<T> {
if voidResponse.result.isFailure {
completion(
response: nil,
error: ErrorResponse.Error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.result.error!)
error: ErrorResponse.error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.result.error!)
)
return
}
Expand All @@ -158,10 +158,10 @@ class AlamofireRequestBuilder<T>: RequestBuilder<T> {
validatedRequest.responseData(completionHandler: { (dataResponse) in
cleanupRequest()

if (dataResponse.result.isFailure) {
if dataResponse.result.isFailure {
completion(
response: nil,
error: ErrorResponse.Error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!)
error: ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!)
)
return
}
Expand All @@ -179,7 +179,7 @@ class AlamofireRequestBuilder<T>: RequestBuilder<T> {
cleanupRequest()

if response.result.isFailure {
completion(response: nil, error: ErrorResponse.Error(response.response?.statusCode ?? 500, response.data, response.result.error!))
completion(response: nil, error: ErrorResponse.error(response.response?.statusCode ?? 500, response.data, response.result.error!))
return
}

Expand All @@ -198,7 +198,7 @@ class AlamofireRequestBuilder<T>: RequestBuilder<T> {
return
}

completion(response: nil, error: ErrorResponse.Error(500, nil, NSError(domain: "localhost", code: 500, userInfo: ["reason": "unreacheable code"])))
completion(response: nil, error: ErrorResponse.error(500, nil, NSError(domain: "localhost", code: 500, userInfo: ["reason": "unreacheable code"])))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class Response<T> {
public convenience init(response: NSHTTPURLResponse, body: T?) {
let rawHeader = response.allHeaderFields
var header = [String:String]()
for (key, value) in rawHeader {
header[key as! String] = value as? String
for case let (key, value) as (String, String) in rawHeader {
header[key] = value
}
self.init(statusCode: response.statusCode, header: header, body: body)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,12 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
else {
mpForm.append(fileURL, withName: k)
}
break
case let string as String:
mpForm.append(string.data(using: String.Encoding.utf8)!, withName: k)
break
case let number as NSNumber:
mpForm.append(number.stringValue.data(using: String.Encoding.utf8)!, withName: k)
break
default:
fatalError("Unprocessable value \(v) with key \(k)")
break
}
}
}, to: URLString, method: xMethod!, headers: nil, encodingCompletion: { encodingResult in
Expand Down Expand Up @@ -206,7 +202,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
validatedRequest.responseData(completionHandler: { (dataResponse) in
cleanupRequest()

if (dataResponse.result.isFailure) {
if dataResponse.result.isFailure {
completion(
nil,
ErrorResponse.HttpError(statusCode: dataResponse.response?.statusCode ?? 500, data: dataResponse.data, error: dataResponse.result.error!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Alamofire/Alamofire" >= 3.1.0{{#usePromiseKit}}
github "mxcl/PromiseKit" >=1.5.3{{/usePromiseKit}}{{#useRxSwift}}
github "ReactiveX/RxSwift" ~> 2.0{{/useRxSwift}}
github "Alamofire/Alamofire" ~> 4.5{{#usePromiseKit}}
github "mxcl/PromiseKit" ~> 4.4{{/usePromiseKit}}{{#useRxSwift}}
github "ReactiveX/RxSwift" "rxswift-3.0"{{/useRxSwift}}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension Dictionary: JSONEncodable {
func encodeToJSON() -> Any {
var dictionary = [AnyHashable: Any]()
for (key, value) in self {
dictionary[key as! NSObject] = encodeIfPossible(value)
dictionary[key] = encodeIfPossible(value)
}
return dictionary as Any
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ open class Response<T> {
public convenience init(response: HTTPURLResponse, body: T?) {
let rawHeader = response.allHeaderFields
var header = [String:String]()
for (key, value) in rawHeader {
header[key as! String] = value as? String
for case let (key, value) as (String, String) in rawHeader {
header[key] = value
}
self.init(statusCode: response.statusCode, header: header, body: body)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Pod::Spec.new do |s|
s.documentation_url = '{{podDocumentationURL}}'{{/podDocumentationURL}}
s.source_files = '{{projectName}}/Classes/**/*.swift'{{#usePromiseKit}}
s.dependency 'PromiseKit/CorePromise', '~> 4.4.0'{{/usePromiseKit}}{{#useRxSwift}}
s.dependency 'RxSwift', '~> 3.4.1'{{/useRxSwift}}
s.dependency 'RxSwift', '3.6.1'{{/useRxSwift}}
s.dependency 'Alamofire', '~> 4.5.0'
end
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,12 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
else {
mpForm.append(fileURL, withName: k)
}
break
case let string as String:
mpForm.append(string.data(using: String.Encoding.utf8)!, withName: k)
break
case let number as NSNumber:
mpForm.append(number.stringValue.data(using: String.Encoding.utf8)!, withName: k)
break
default:
fatalError("Unprocessable value \(v) with key \(k)")
break
}
}
}, to: URLString, method: xMethod!, headers: nil, encodingCompletion: { encodingResult in
Expand All @@ -97,7 +93,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
}
self.processRequest(request: upload, managerId, completion)
case .failure(let encodingError):
completion(nil, ErrorResponse.Error(415, nil, encodingError))
completion(nil, ErrorResponse.error(415, nil, encodingError))
}
})
} else {
Expand Down Expand Up @@ -129,7 +125,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
if stringResponse.result.isFailure {
completion(
nil,
ErrorResponse.Error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!)
ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!)
)
return
}
Expand Down Expand Up @@ -186,9 +182,9 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
)

} catch let requestParserError as DownloadException {
completion(nil, ErrorResponse.Error(400, dataResponse.data, requestParserError))
completion(nil, ErrorResponse.error(400, dataResponse.data, requestParserError))
} catch let error {
completion(nil, ErrorResponse.Error(400, dataResponse.data, error))
completion(nil, ErrorResponse.error(400, dataResponse.data, error))
}
return
})
Expand All @@ -199,7 +195,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
if voidResponse.result.isFailure {
completion(
nil,
ErrorResponse.Error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.result.error!)
ErrorResponse.error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.result.error!)
)
return
}
Expand All @@ -215,10 +211,10 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
validatedRequest.responseData(completionHandler: { (dataResponse) in
cleanupRequest()

if (dataResponse.result.isFailure) {
if dataResponse.result.isFailure {
completion(
nil,
ErrorResponse.Error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!)
ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!)
)
return
}
Expand Down Expand Up @@ -331,7 +327,7 @@ open class AlamofireDecodableRequestBuilder<T:Decodable>: AlamofireRequestBuilde
if stringResponse.result.isFailure {
completion(
nil,
ErrorResponse.Error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!)
ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!)
)
return
}
Expand All @@ -351,7 +347,7 @@ open class AlamofireDecodableRequestBuilder<T:Decodable>: AlamofireRequestBuilde
if voidResponse.result.isFailure {
completion(
nil,
ErrorResponse.Error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.result.error!)
ErrorResponse.error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.result.error!)
)
return
}
Expand All @@ -367,10 +363,10 @@ open class AlamofireDecodableRequestBuilder<T:Decodable>: AlamofireRequestBuilde
validatedRequest.responseData(completionHandler: { (dataResponse) in
cleanupRequest()

if (dataResponse.result.isFailure) {
if dataResponse.result.isFailure {
completion(
nil,
ErrorResponse.Error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!)
ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!)
)
return
}
Expand All @@ -388,17 +384,17 @@ open class AlamofireDecodableRequestBuilder<T:Decodable>: AlamofireRequestBuilde
cleanupRequest()

guard dataResponse.result.isSuccess else {
completion(nil, ErrorResponse.Error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!))
completion(nil, ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!))
return
}

guard let data = dataResponse.data, !data.isEmpty else {
completion(nil, ErrorResponse.Error(-1, nil, AlamofireDecodableRequestBuilderError.emptyDataResponse))
completion(nil, ErrorResponse.error(-1, nil, AlamofireDecodableRequestBuilderError.emptyDataResponse))
return
}

guard let httpResponse = dataResponse.response else {
completion(nil, ErrorResponse.Error(-2, nil, AlamofireDecodableRequestBuilderError.nilHTTPResponse))
completion(nil, ErrorResponse.error(-2, nil, AlamofireDecodableRequestBuilderError.nilHTTPResponse))
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Alamofire/Alamofire" >= 3.1.0{{#usePromiseKit}}
github "mxcl/PromiseKit" >=1.5.3{{/usePromiseKit}}{{#useRxSwift}}
github "ReactiveX/RxSwift" ~> 2.0{{/useRxSwift}}
github "Alamofire/Alamofire" ~> 4.5.0{{#usePromiseKit}}
github "mxcl/PromiseKit" ~> 4.4{{/usePromiseKit}}{{#useRxSwift}}
github "ReactiveX/RxSwift" ~> 4.0{{/useRxSwift}}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ open class CodableHelper {
decoder.dateDecodingStrategy = .formatted(df)
} else {
decoder.dataDecodingStrategy = .base64
if #available(iOS 10.0, *) {
decoder.dateDecodingStrategy = .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"
decoder.dateDecodingStrategy = .formatted(formatter)
}

do {
Expand All @@ -45,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension Dictionary: JSONEncodable {
func encodeToJSON() -> Any {
var dictionary = [AnyHashable: Any]()
for (key, value) in self {
dictionary[key as! NSObject] = encodeIfPossible(value)
dictionary[key] = encodeIfPossible(value)
}
return dictionary as Any
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protocol JSONEncodable {
}

public enum ErrorResponse : Error {
case Error(Int, Data?, Error)
case error(Int, Data?, Error)
}

open class Response<T> {
Expand All @@ -28,8 +28,8 @@ open class Response<T> {
public convenience init(response: HTTPURLResponse, body: T?) {
let rawHeader = response.allHeaderFields
var header = [String:String]()
for (key, value) in rawHeader {
header[key as! String] = value as? String
for case let (key, value) as (String, String) in rawHeader {
header[key] = value
}
self.init(statusCode: response.statusCode, header: header, body: body)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Pod::Spec.new do |s|
s.documentation_url = '{{podDocumentationURL}}'{{/podDocumentationURL}}
s.source_files = '{{projectName}}/Classes/**/*.swift'{{#usePromiseKit}}
s.dependency 'PromiseKit/CorePromise', '~> 4.4.0'{{/usePromiseKit}}{{#useRxSwift}}
s.dependency 'RxSwift', '~> 3.4.1'{{/useRxSwift}}
s.dependency 'RxSwift', '~> 4.0'{{/useRxSwift}}
s.dependency 'Alamofire', '~> 4.5.0'
end
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ open class {{classname}} {
return Observable.create { observer -> Disposable in
{{operationId}}({{#allParams}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{#returnType}}data, {{/returnType}}error in
if let error = error {
observer.on(.error(error as Error))
observer.on(.error(error))
} else {
observer.on(.next({{#returnType}}data!{{/returnType}}))
observer.on(.next({{#returnType}}data!{{/returnType}}{{^returnType}}(){{/returnType}}))
}
observer.on(.completed)
}
Expand Down
13 changes: 8 additions & 5 deletions modules/swagger-codegen/src/main/resources/swift4/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}Codable{{
}
{{/additionalPropertiesType}}

{{#hasVars}}
{{^parent}}{{#hasVars}}
public init({{#vars}}{{name}}: {{{datatypeWithEnum}}}{{^required}}?{{/required}}{{#hasMore}}, {{/hasMore}}{{/vars}}) {
{{#vars}}
self.{{name}} = {{name}}
{{/vars}}
}
{{/hasVars}}
{{/hasVars}}{{/parent}}

// Encodable protocol methods

Expand All @@ -79,7 +79,7 @@ open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}Codable{{
var container = encoder.container(keyedBy: String.self)

{{#vars}}
try container.encode{{#isListContainer}}Array{{/isListContainer}}{{^required}}IfPresent{{/required}}({{{name}}}, forKey: "{{{baseName}}}")
try container.encode{{^required}}IfPresent{{/required}}({{{name}}}, forKey: "{{{baseName}}}")
{{/vars}}
{{#additionalPropertiesType}}
try container.encodeMap(additionalProperties)
Expand All @@ -88,11 +88,11 @@ open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}Codable{{

// Decodable protocol methods

public {{#parent}}override {{/parent}}required init(from decoder: Decoder) throws {
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)

{{#vars}}
{{name}} = try container.decode{{#isListContainer}}Array{{/isListContainer}}{{^required}}IfPresent{{/required}}({{#isListContainer}}{{{items.datatype}}}{{/isListContainer}}{{^isListContainer}}{{{datatypeWithEnum}}}{{/isListContainer}}.self, forKey: "{{{baseName}}}")
{{name}} = try container.decode{{^required}}IfPresent{{/required}}({{{datatypeWithEnum}}}.self, forKey: "{{{baseName}}}")
{{/vars}}
{{#additionalPropertiesType}}
var nonAdditionalPropertyKeys = Set<String>()
Expand All @@ -101,6 +101,9 @@ open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}Codable{{
{{/vars}}
additionalProperties = try container.decodeMap({{{additionalPropertiesType}}}.self, excludedKeys: nonAdditionalPropertyKeys)
{{/additionalPropertiesType}}
{{#parent}}
try super.init(from: decoder)
{{/parent}}
}
}

Expand Down
Loading