-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #554 from swagger-api/swift5-generator
Swift5 generator
- Loading branch information
Showing
24 changed files
with
2,413 additions
and
0 deletions.
There are no files selected for viewing
838 changes: 838 additions & 0 deletions
838
src/main/java/io/swagger/codegen/v3/generators/swift/Swift5Codegen.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// APIHelper.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
public struct APIHelper { | ||
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 | ||
} | ||
} | ||
|
||
if destination.isEmpty { | ||
return nil | ||
} | ||
return destination | ||
} | ||
|
||
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: ",") | ||
} else if let value: Any = item.value { | ||
result[item.key] = "\(value)" | ||
} | ||
} | ||
} | ||
|
||
public static func convertBoolToString(_ source: [String: Any]?) -> [String:Any]? { | ||
guard let source = source else { | ||
return nil | ||
} | ||
|
||
return source.reduce(into: [String: Any](), { (result, item) in | ||
switch item.value { | ||
case let x as Bool: | ||
result[item.key] = x.description | ||
default: | ||
result[item.key] = item.value | ||
} | ||
}) | ||
} | ||
|
||
|
||
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: ",") | ||
result.append(URLQueryItem(name: item.key, value: value)) | ||
} else if let value = item.value { | ||
result.append(URLQueryItem(name: item.key, value: "\(value)")) | ||
} | ||
} | ||
|
||
if destination.isEmpty { | ||
return nil | ||
} | ||
return destination | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// APIs.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
open class {{projectName}}API { | ||
public static var basePath = "{{{basePath}}}" | ||
public static var credential: URLCredential? | ||
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]? | ||
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) -> ())? | ||
required public init(method: String, URLString: String, parameters: [String:Any]?, isBody: Bool, headers: [String:String] = [:]) { | ||
self.method = method | ||
self.URLString = URLString | ||
self.parameters = parameters | ||
self.isBody = isBody | ||
self.headers = headers | ||
addHeaders({{projectName}}API.customHeaders) | ||
} | ||
open func addHeaders(_ aHeaders:[String:String]) { | ||
for (header, value) in aHeaders { | ||
headers[header] = value | ||
} | ||
} | ||
open func execute(_ completion: @escaping (_ response: Response<T>?, _ error: Error?) -> Void) { } | ||
public func addHeader(name: String, value: String) -> Self { | ||
if !value.isEmpty { | ||
headers[name] = value | ||
} | ||
return self | ||
} | ||
open func addCredential() -> Self { | ||
self.credential = {{projectName}}API.credential | ||
return self | ||
} | ||
} | ||
public protocol RequestBuilderFactory { | ||
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type | ||
func getBuilder<T:Decodable>() -> RequestBuilder<T>.Type | ||
} |
Oops, something went wrong.