[swift4] Add swift package manager and update dependencies (#4141)

* [swift4] add Swift Package Manager

* [swift] update petstore projects

* [swift4] try to run CI again
This commit is contained in:
Bruno Coelho
2019-10-18 03:38:31 +01:00
committed by William Cheng
parent 3f3559020a
commit c2ad14ea02
256 changed files with 3541 additions and 3833 deletions

View File

@@ -7,7 +7,7 @@
import Foundation
public struct APIHelper {
public static func rejectNil(_ source: [String:Any?]) -> [String:Any]? {
public static func rejectNil(_ source: [String: Any?]) -> [String: Any]? {
let destination = source.reduce(into: [String: Any]()) { (result, item) in
if let value = item.value {
result[item.key] = value
@@ -20,17 +20,17 @@ public struct APIHelper {
return destination
}
public static func rejectNilHeaders(_ source: [String:Any?]) -> [String:String] {
public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
return source.reduce(into: [String: String]()) { (result, item) in
if let collection = item.value as? Array<Any?> {
result[item.key] = collection.filter({ $0 != nil }).map{ "\($0!)" }.joined(separator: ",")
result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",")
} else if let value: Any = item.value {
result[item.key] = "\(value)"
}
}
}
public static func convertBoolToString(_ source: [String: Any]?) -> [String:Any]? {
public static func convertBoolToString(_ source: [String: Any]?) -> [String: Any]? {
guard let source = source else {
return nil
}
@@ -52,7 +52,7 @@ public struct APIHelper {
return source
}
public static func mapValuesToQueryItems(_ source: [String:Any?]) -> [URLQueryItem]? {
public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in
if let collection = item.value as? Array<Any?> {
let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
@@ -68,4 +68,3 @@ public struct APIHelper {
return destination
}
}

View File

@@ -9,22 +9,22 @@ import Foundation
open class TestClientAPI {
public static var basePath = "http://api.example.com/basePath"
public static var credential: URLCredential?
public static var customHeaders: [String:String] = [:]
public static var customHeaders: [String: String] = [:]
public static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
}
open class RequestBuilder<T> {
var credential: URLCredential?
var headers: [String:String]
public let parameters: [String:Any]?
var headers: [String: String]
public let parameters: [String: Any]?
public let isBody: Bool
public let method: String
public let URLString: String
/// Optional block to obtain a reference to the request's progress instance when available.
public var onProgressReady: ((Progress) -> ())?
public var onProgressReady: ((Progress) -> Void)?
required public init(method: String, URLString: String, parameters: [String:Any]?, isBody: Bool, headers: [String:String] = [:]) {
required public init(method: String, URLString: String, parameters: [String: Any]?, isBody: Bool, headers: [String: String] = [:]) {
self.method = method
self.URLString = URLString
self.parameters = parameters
@@ -34,7 +34,7 @@ open class RequestBuilder<T> {
addHeaders(TestClientAPI.customHeaders)
}
open func addHeaders(_ aHeaders:[String:String]) {
open func addHeaders(_ aHeaders: [String: String]) {
for (header, value) in aHeaders {
headers[header] = value
}
@@ -57,5 +57,5 @@ open class RequestBuilder<T> {
public protocol RequestBuilderFactory {
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type
func getBuilder<T:Decodable>() -> RequestBuilder<T>.Type
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type
}

View File

@@ -8,8 +8,6 @@
import Foundation
import Alamofire
open class Swift4TestAPI {
/**
Get all of the models
@@ -17,7 +15,7 @@ open class Swift4TestAPI {
- parameter clientId: (query) id that represent the Api client
- parameter completion: completion handler to receive the data and the error objects
*/
open class func getAllModels(clientId: String, completion: @escaping ((_ data: GetAllModelsResult?,_ error: Error?) -> Void)) {
open class func getAllModels(clientId: String, completion: @escaping ((_ data: GetAllModelsResult?, _ error: Error?) -> Void)) {
getAllModelsWithRequestBuilder(clientId: clientId).execute { (response, error) -> Void in
completion(response?.body, error)
}
@@ -33,8 +31,8 @@ open class Swift4TestAPI {
open class func getAllModelsWithRequestBuilder(clientId: String) -> RequestBuilder<GetAllModelsResult> {
let path = "/allModels"
let URLString = TestClientAPI.basePath + path
let parameters: [String:Any]? = nil
let parameters: [String: Any]? = nil
var url = URLComponents(string: URLString)
url?.queryItems = APIHelper.mapValuesToQueryItems([
"client_id": clientId

View File

@@ -12,7 +12,7 @@ class AlamofireRequestBuilderFactory: RequestBuilderFactory {
return AlamofireRequestBuilder<T>.self
}
func getBuilder<T:Decodable>() -> RequestBuilder<T>.Type {
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type {
return AlamofireDecodableRequestBuilder<T>.self
}
}
@@ -50,7 +50,7 @@ private struct SynchronizedDictionary<K: Hashable, V> {
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] = [:]) {
required public init(method: String, URLString: String, parameters: [String: Any]?, isBody: Bool, headers: [String: String] = [:]) {
super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody, headers: headers)
}
@@ -88,17 +88,17 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
May be overridden by a subclass if you want to control the request
configuration (e.g. to override the cache policy).
*/
open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding, headers: [String:String]) -> DataRequest {
open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) -> DataRequest {
return manager.request(URLString, method: method, parameters: parameters, encoding: encoding, headers: headers)
}
override open func execute(_ completion: @escaping (_ response: Response<T>?, _ error: Error?) -> Void) {
let managerId:String = UUID().uuidString
let managerId: String = UUID().uuidString
// Create a new manager for each request to customize its request header
let manager = createSessionManager()
managerStore[managerId] = manager
let encoding:ParameterEncoding = isBody ? JSONDataEncoding() : URLEncoding()
let encoding: ParameterEncoding = isBody ? JSONDataEncoding() : URLEncoding()
let xMethod = Alamofire.HTTPMethod(rawValue: method)
let fileKeys = parameters == nil ? [] : parameters!.filter { $1 is NSURL }
@@ -111,8 +111,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
case let fileURL as URL:
if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) {
mpForm.append(fileURL, withName: k, fileName: fileURL.lastPathComponent, mimeType: mimeType)
}
else {
} else {
mpForm.append(fileURL, withName: k)
}
case let string as String:
@@ -276,7 +275,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
return httpHeaders
}
fileprivate func getFileName(fromContentDisposition contentDisposition : String?) -> String? {
fileprivate func getFileName(fromContentDisposition contentDisposition: String?) -> String? {
guard let contentDisposition = contentDisposition else {
return nil
@@ -284,7 +283,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
let items = contentDisposition.components(separatedBy: ";")
var filename : String? = nil
var filename: String?
for contentItem in items {
@@ -295,7 +294,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
filename = contentItem
return filename?
.replacingCharacters(in: range, with:"")
.replacingCharacters(in: range, with: "")
.replacingOccurrences(of: "\"", with: "")
.trimmingCharacters(in: .whitespacesAndNewlines)
}
@@ -304,7 +303,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
}
fileprivate func getPath(from url : URL) throws -> String {
fileprivate func getPath(from url: URL) throws -> String {
guard var path = URLComponents(url: url, resolvingAgainstBaseURL: true)?.path else {
throw DownloadException.requestMissingPath
@@ -318,7 +317,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
}
fileprivate func getURL(from urlRequest : URLRequest) throws -> URL {
fileprivate func getURL(from urlRequest: URLRequest) throws -> URL {
guard let url = urlRequest.url else {
throw DownloadException.requestMissingURL
@@ -329,7 +328,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
}
fileprivate enum DownloadException : Error {
private enum DownloadException: Error {
case responseDataMissing
case responseFailed
case requestMissing
@@ -344,7 +343,7 @@ public enum AlamofireDecodableRequestBuilderError: Error {
case generalError(Error)
}
open class AlamofireDecodableRequestBuilder<T:Decodable>: AlamofireRequestBuilder<T> {
open class AlamofireDecodableRequestBuilder<T: Decodable>: AlamofireRequestBuilder<T> {
override fileprivate func processRequest(request: DataRequest, _ managerId: String, _ completion: @escaping (_ response: Response<T>?, _ error: Error?) -> Void) {
if let credential = self.credential {
@@ -436,7 +435,7 @@ open class AlamofireDecodableRequestBuilder<T:Decodable>: AlamofireRequestBuilde
return
}
var responseObj: Response<T>? = nil
var responseObj: Response<T>?
let decodeResult: (decodableObj: T?, error: Error?) = CodableHelper.decode(T.self, from: data)
if decodeResult.error == nil {

View File

@@ -13,9 +13,9 @@ open class CodableHelper {
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
var returnedError: Error? = nil
open class func decode<T>(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T: Decodable {
var returnedDecodable: T?
var returnedError: Error?
let decoder = JSONDecoder()
if let df = self.dateformatter {
@@ -39,9 +39,9 @@ open class CodableHelper {
return (returnedDecodable, returnedError)
}
open class func encode<T>(_ value: T, prettyPrint: Bool = false) -> EncodeResult where T : Encodable {
open class func encode<T>(_ value: T, prettyPrint: Bool = false) -> EncodeResult where T: Encodable {
var returnedData: Data?
var returnedError: Error? = nil
var returnedError: Error?
let encoder = JSONEncoder()
if prettyPrint {

View File

@@ -7,9 +7,9 @@
import Foundation
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.
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
}
}

View File

@@ -112,24 +112,24 @@ extension String: CodingKey {
extension KeyedEncodingContainerProtocol {
public mutating func encodeArray<T>(_ values: [T], forKey key: Self.Key) throws where T : Encodable {
public mutating func encodeArray<T>(_ values: [T], forKey key: Self.Key) throws where T: Encodable {
var arrayContainer = nestedUnkeyedContainer(forKey: key)
try arrayContainer.encode(contentsOf: values)
}
public mutating func encodeArrayIfPresent<T>(_ values: [T]?, forKey key: Self.Key) throws where T : Encodable {
public mutating func encodeArrayIfPresent<T>(_ values: [T]?, forKey key: Self.Key) throws where T: Encodable {
if let values = values {
try encodeArray(values, forKey: key)
}
}
public mutating func encodeMap<T>(_ pairs: [Self.Key: T]) throws where T : Encodable {
public mutating func encodeMap<T>(_ pairs: [Self.Key: T]) throws where T: Encodable {
for (key, value) in pairs {
try encode(value, forKey: key)
}
}
public mutating func encodeMapIfPresent<T>(_ pairs: [Self.Key: T]?) throws where T : Encodable {
public mutating func encodeMapIfPresent<T>(_ pairs: [Self.Key: T]?) throws where T: Encodable {
if let pairs = pairs {
try encodeMap(pairs)
}
@@ -139,7 +139,7 @@ extension KeyedEncodingContainerProtocol {
extension KeyedDecodingContainerProtocol {
public func decodeArray<T>(_ type: T.Type, forKey key: Self.Key) throws -> [T] where T : Decodable {
public func decodeArray<T>(_ type: T.Type, forKey key: Self.Key) throws -> [T] where T: Decodable {
var tmpArray = [T]()
var nestedContainer = try nestedUnkeyedContainer(forKey: key)
@@ -151,8 +151,8 @@ extension KeyedDecodingContainerProtocol {
return tmpArray
}
public func decodeArrayIfPresent<T>(_ type: T.Type, forKey key: Self.Key) throws -> [T]? where T : Decodable {
var tmpArray: [T]? = nil
public func decodeArrayIfPresent<T>(_ type: T.Type, forKey key: Self.Key) throws -> [T]? where T: Decodable {
var tmpArray: [T]?
if contains(key) {
tmpArray = try decodeArray(T.self, forKey: key)
@@ -161,8 +161,8 @@ extension KeyedDecodingContainerProtocol {
return tmpArray
}
public func decodeMap<T>(_ type: T.Type, excludedKeys: Set<Self.Key>) throws -> [Self.Key: T] where T : Decodable {
var map: [Self.Key : T] = [:]
public func decodeMap<T>(_ type: T.Type, excludedKeys: Set<Self.Key>) throws -> [Self.Key: T] where T: Decodable {
var map: [Self.Key: T] = [:]
for key in allKeys {
if !excludedKeys.contains(key) {
@@ -175,5 +175,3 @@ extension KeyedDecodingContainerProtocol {
}
}

View File

@@ -42,7 +42,7 @@ public struct JSONDataEncoding: ParameterEncoding {
}
public static func encodingParameters(jsonData: Data?) -> Parameters? {
var returnedParams: Parameters? = nil
var returnedParams: Parameters?
if let jsonData = jsonData, !jsonData.isEmpty {
var params = Parameters()
params[jsonDataKey] = jsonData

View File

@@ -10,8 +10,8 @@ import Alamofire
open class JSONEncodingHelper {
open class func encodingParameters<T:Encodable>(forEncodableObject encodableObj: T?) -> Parameters? {
var params: Parameters? = nil
open class func encodingParameters<T: Encodable>(forEncodableObject encodableObj: T?) -> Parameters? {
var params: Parameters?
// Encode the Encodable object
if let encodableObj = encodableObj {
@@ -25,7 +25,7 @@ open class JSONEncodingHelper {
}
open class func encodingParameters(forEncodableObject encodableObj: Any?) -> Parameters? {
var params: Parameters? = nil
var params: Parameters?
if let encodableObj = encodableObj {
do {
@@ -39,5 +39,5 @@ open class JSONEncodingHelper {
return params
}
}

View File

@@ -10,7 +10,7 @@ protocol JSONEncodable {
func encodeToJSON() -> Any
}
public enum ErrorResponse : Error {
public enum ErrorResponse: Error {
case error(Int, Data?, Error)
}
@@ -27,7 +27,7 @@ open class Response<T> {
public convenience init(response: HTTPURLResponse, body: T?) {
let rawHeader = response.allHeaderFields
var header = [String:String]()
var header = [String: String]()
for case let (key, value) as (String, String) in rawHeader {
header[key] = value
}

View File

@@ -7,8 +7,7 @@
import Foundation
/** Object which contains lots of different primitive Swagger types */
/** Object which contains lots of different primitive OpenAPI types */
public struct AllPrimitives: Codable {
@@ -71,6 +70,4 @@ public struct AllPrimitives: Codable {
self.myInlineStringEnum = myInlineStringEnum
}
}

View File

@@ -7,7 +7,6 @@
import Foundation
/** This is a base card object which uses a &#39;cardType&#39; discriminator. */
public struct BaseCard: Codable {
@@ -18,6 +17,4 @@ public struct BaseCard: Codable {
self.cardType = cardType
}
}

View File

@@ -7,7 +7,6 @@
import Foundation
/** Example Error object */
public struct ErrorInfo: Codable {
@@ -22,6 +21,4 @@ public struct ErrorInfo: Codable {
self.details = details
}
}

View File

@@ -7,7 +7,6 @@
import Foundation
/** Response object containing AllPrimitives object */
public struct GetAllModelsResult: Codable {
@@ -22,6 +21,4 @@ public struct GetAllModelsResult: Codable {
self.myVariableNameTest = myVariableNameTest
}
}

View File

@@ -7,7 +7,6 @@
import Foundation
/** This is an empty model with no properties and only additionalProperties of type int32 */
public struct ModelWithPropertiesAndAdditionalProperties: Codable {
@@ -31,7 +30,7 @@ public struct ModelWithPropertiesAndAdditionalProperties: Codable {
self.myPrimitiveArrayReq = myPrimitiveArrayReq
self.myPrimitiveArrayOpt = myPrimitiveArrayOpt
}
public var additionalProperties: [String:String] = [:]
public var additionalProperties: [String: String] = [:]
public subscript(key: String) -> String? {
get {
@@ -88,7 +87,4 @@ public struct ModelWithPropertiesAndAdditionalProperties: Codable {
additionalProperties = try container.decodeMap(String.self, excludedKeys: nonAdditionalPropertyKeys)
}
}

View File

@@ -7,7 +7,6 @@
import Foundation
/** This is a card object for a Person derived from BaseCard. */
public struct PersonCard: Codable {
@@ -22,6 +21,4 @@ public struct PersonCard: Codable {
self.lastName = lastName
}
}

View File

@@ -7,8 +7,6 @@
import Foundation
public struct PersonCardAllOf: Codable {
public var firstName: String?
@@ -19,6 +17,4 @@ public struct PersonCardAllOf: Codable {
self.lastName = lastName
}
}

View File

@@ -7,7 +7,6 @@
import Foundation
/** This is a card object for a Person derived from BaseCard. */
public struct PlaceCard: Codable {
@@ -22,6 +21,4 @@ public struct PlaceCard: Codable {
self.placeAddress = placeAddress
}
}

View File

@@ -7,8 +7,6 @@
import Foundation
public struct PlaceCardAllOf: Codable {
public var placeName: String?
@@ -19,6 +17,4 @@ public struct PlaceCardAllOf: Codable {
self.placeAddress = placeAddress
}
}

View File

@@ -7,7 +7,6 @@
import Foundation
/** This is a base class object from which other classes will derive. */
public struct SampleBase: Codable {
@@ -20,6 +19,4 @@ public struct SampleBase: Codable {
self.baseClassIntegerProp = baseClassIntegerProp
}
}

View File

@@ -7,7 +7,6 @@
import Foundation
/** This is a subclass defived from the SampleBase class. */
public struct SampleSubClass: Codable {
@@ -24,6 +23,4 @@ public struct SampleSubClass: Codable {
self.subClassIntegerProp = subClassIntegerProp
}
}

View File

@@ -7,8 +7,6 @@
import Foundation
public struct SampleSubClassAllOf: Codable {
public var subClassStringProp: String?
@@ -19,6 +17,4 @@ public struct SampleSubClassAllOf: Codable {
self.subClassIntegerProp = subClassIntegerProp
}
}

View File

@@ -7,7 +7,6 @@
import Foundation
public enum StringEnum: String, Codable {
case stringenumvalue1 = "stringEnumValue1"
case stringenumvalue2 = "stringEnumValue2"

View File

@@ -7,7 +7,6 @@
import Foundation
/** This object contains property names which we know will be different from their variable name. Examples of this include snake case property names and property names which are Swift 4 reserved words. */
public struct VariableNameTest: Codable {
@@ -25,12 +24,10 @@ public struct VariableNameTest: Codable {
self.normalName = normalName
}
public enum CodingKeys: String, CodingKey {
public enum CodingKeys: String, CodingKey {
case exampleName = "example_name"
case _for = "for"
case normalName
}
}