mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 12:32:42 +00:00
[Swift] Updates for Swift 4.2 (#1443)
* [Swift] Update Alamofire version and update tests and Swift version to 4.2 for default and RxSwift variants * Update promiseKit for Swift 4.0 * Update project files. * Merge branch 'master' of https://github.com/OpenAPITools/openapi-generator into OpenAPITools-master # Conflicts: # samples/client/petstore/swift4/default/SwaggerClientTests/SwaggerClient.xcodeproj/project.pbxproj * Merge in latest master * Remove typo in bash file
This commit is contained in:
committed by
Daiki Matsudate
parent
3896821d5e
commit
33fbd9c78b
@@ -1 +1 @@
|
||||
3.2.0-SNAPSHOT
|
||||
3.3.4-SNAPSHOT
|
||||
@@ -4,11 +4,11 @@ Pod::Spec.new do |s|
|
||||
s.osx.deployment_target = '10.11'
|
||||
s.tvos.deployment_target = '9.0'
|
||||
s.version = '0.0.1'
|
||||
s.source = { :git => 'git@github.com:openapitools/openapi-generator.git', :tag => 'v1.0.0' }
|
||||
s.source = { :git => 'git@github.com:OpenAPITools/openapi-generator.git', :tag => 'v1.0.0' }
|
||||
s.authors = ''
|
||||
s.license = 'Proprietary'
|
||||
s.homepage = 'https://github.com/openapitools/openapi-generator'
|
||||
s.summary = 'TestClient'
|
||||
s.source_files = 'TestClient/Classes/**/*.swift'
|
||||
s.dependency 'Alamofire', '~> 4.5.0'
|
||||
s.dependency 'Alamofire', '~> 4.7.0'
|
||||
end
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
import Foundation
|
||||
|
||||
open class TestClientAPI {
|
||||
open static var basePath = "http://api.example.com/basePath"
|
||||
open static var credential: URLCredential?
|
||||
open static var customHeaders: [String:String] = [:]
|
||||
open static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
|
||||
public static var basePath = "http://api.example.com/basePath"
|
||||
public static var credential: URLCredential?
|
||||
public static var customHeaders: [String:String] = [:]
|
||||
public static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
|
||||
}
|
||||
|
||||
open class RequestBuilder<T> {
|
||||
|
||||
@@ -17,8 +17,37 @@ class AlamofireRequestBuilderFactory: RequestBuilderFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private struct SynchronizedDictionary<K: Hashable, V> {
|
||||
|
||||
private var dictionary = [K: V]()
|
||||
private let queue = DispatchQueue(
|
||||
label: "SynchronizedDictionary",
|
||||
qos: DispatchQoS.userInitiated,
|
||||
attributes: [DispatchQueue.Attributes.concurrent],
|
||||
autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency.inherit,
|
||||
target: nil
|
||||
)
|
||||
|
||||
public subscript(key: K) -> V? {
|
||||
get {
|
||||
var value: V?
|
||||
|
||||
queue.sync {
|
||||
value = self.dictionary[key]
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
set {
|
||||
queue.sync(flags: DispatchWorkItemFlags.barrier) {
|
||||
self.dictionary[key] = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store manager to retain its reference
|
||||
private var managerStore: [String: Alamofire.SessionManager] = [:]
|
||||
private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManager>()
|
||||
|
||||
open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) {
|
||||
@@ -112,7 +141,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
}
|
||||
|
||||
let cleanupRequest = {
|
||||
_ = managerStore.removeValue(forKey: managerId)
|
||||
managerStore[managerId] = nil
|
||||
}
|
||||
|
||||
let validatedRequest = request.validate()
|
||||
@@ -125,7 +154,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!)
|
||||
)
|
||||
return
|
||||
}
|
||||
@@ -314,7 +343,7 @@ open class AlamofireDecodableRequestBuilder<T:Decodable>: AlamofireRequestBuilde
|
||||
}
|
||||
|
||||
let cleanupRequest = {
|
||||
_ = managerStore.removeValue(forKey: managerId)
|
||||
managerStore[managerId] = nil
|
||||
}
|
||||
|
||||
let validatedRequest = request.validate()
|
||||
@@ -327,7 +356,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!)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public typealias EncodeResult = (data: Data?, error: Error?)
|
||||
|
||||
open class CodableHelper {
|
||||
|
||||
open static var dateformatter: DateFormatter?
|
||||
public 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
|
||||
@@ -26,7 +26,7 @@ open class CodableHelper {
|
||||
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"
|
||||
formatter.dateFormat = Configuration.dateFormat
|
||||
decoder.dateDecodingStrategy = .formatted(formatter)
|
||||
}
|
||||
|
||||
@@ -47,13 +47,17 @@ open class CodableHelper {
|
||||
if prettyPrint {
|
||||
encoder.outputFormatting = .prettyPrinted
|
||||
}
|
||||
encoder.dataEncodingStrategy = .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"
|
||||
encoder.dateEncodingStrategy = .formatted(formatter)
|
||||
if let df = self.dateformatter {
|
||||
encoder.dateEncodingStrategy = .formatted(df)
|
||||
} else {
|
||||
encoder.dataEncodingStrategy = .base64
|
||||
let formatter = DateFormatter()
|
||||
formatter.calendar = Calendar(identifier: .iso8601)
|
||||
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||
formatter.timeZone = TimeZone(secondsFromGMT: 0)
|
||||
formatter.dateFormat = Configuration.dateFormat
|
||||
encoder.dateEncodingStrategy = .formatted(formatter)
|
||||
}
|
||||
|
||||
do {
|
||||
returnedData = try encoder.encode(value)
|
||||
|
||||
@@ -10,6 +10,6 @@ open class Configuration {
|
||||
|
||||
// This value is used to configure the date formatter that is used to serialize dates into JSON format.
|
||||
// You must set it prior to encoding any dates, and it will only be read once.
|
||||
open static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
|
||||
|
||||
}
|
||||
@@ -66,10 +66,16 @@ extension Data: JSONEncodable {
|
||||
}
|
||||
|
||||
private let dateFormatter: DateFormatter = {
|
||||
let fmt = DateFormatter()
|
||||
fmt.dateFormat = Configuration.dateFormat
|
||||
fmt.locale = Locale(identifier: "en_US_POSIX")
|
||||
return fmt
|
||||
if let formatter = CodableHelper.dateformatter {
|
||||
return formatter
|
||||
} else {
|
||||
let formatter = DateFormatter()
|
||||
formatter.calendar = Calendar(identifier: .iso8601)
|
||||
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||
formatter.timeZone = TimeZone(secondsFromGMT: 0)
|
||||
formatter.dateFormat = Configuration.dateFormat
|
||||
return formatter
|
||||
}
|
||||
}()
|
||||
|
||||
extension Date: JSONEncodable {
|
||||
|
||||
@@ -15,9 +15,9 @@ public enum ErrorResponse : Error {
|
||||
}
|
||||
|
||||
open class Response<T> {
|
||||
open let statusCode: Int
|
||||
open let header: [String: String]
|
||||
open let body: T?
|
||||
public let statusCode: Int
|
||||
public let header: [String: String]
|
||||
public let body: T?
|
||||
|
||||
public init(statusCode: Int, header: [String: String], body: T?) {
|
||||
self.statusCode = statusCode
|
||||
|
||||
Reference in New Issue
Block a user