Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update swift5 samples with the latest version of SwiftLint #6102

Merged
merged 1 commit into from
Apr 29, 2020
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ private class FileUploadEncoding: ParameterEncoding {

var body = urlRequest.httpBody.orEmpty

body.append("--\(boundary)--")
body.append("\r\n--\(boundary)--\r\n")

urlRequest.httpBody = body

Expand All @@ -508,14 +508,23 @@ private class FileUploadEncoding: ParameterEncoding {

let fileName = fileURL.lastPathComponent

// If we already added something then we need an additional newline.
if body.count > 0 {
body.append("\r\n")
}

// Value boundary.
body.append("--\(boundary)\r\n")
body.append("Content-Disposition: form-data; name=\"\(name)\"; filename=\"\(fileName)\"\r\n\r\n")

body.append("Content-Type: \(mimetype)\r\n\r\n")
// Value headers.
body.append("Content-Disposition: form-data; name=\"\(name)\"; filename=\"\(fileName)\"\r\n")
body.append("Content-Type: \(mimetype)\r\n")

body.append(fileData)
// Separate headers and body.
body.append("\r\n")

body.append("\r\n\r\n")
// The value data.
body.append(fileData)

urlRequest.httpBody = body

Expand All @@ -528,12 +537,22 @@ private class FileUploadEncoding: ParameterEncoding {

var body = urlRequest.httpBody.orEmpty

// If we already added something then we need an additional newline.
if body.count > 0 {
body.append("\r\n")
}

// Value boundary.
body.append("--\(boundary)\r\n")
body.append("Content-Disposition: form-data; name=\"\(name)\"\r\n\r\n")

body.append(data)
// Value headers.
body.append("Content-Disposition: form-data; name=\"\(name)\"\r\n")

body.append("\r\n\r\n")
// Separate headers and body.
body.append("\r\n")

// The value data.
body.append(data)

urlRequest.httpBody = body

Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/swift5/default/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "PetstoreClient",
targets: ["PetstoreClient"]),
targets: ["PetstoreClient"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand All @@ -26,6 +26,6 @@ let package = Package(
name: "PetstoreClient",
dependencies: [],
path: "PetstoreClient/Classes"
),
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: ",")
if let collection = item.value as? [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]? {
public static func convertBoolToString(_ source: [String: Any]?) -> [String: Any]? {
guard let source = source else {
return nil
}
Expand All @@ -46,15 +46,15 @@ public struct APIHelper {
}

public static func mapValueToPathItem(_ source: Any) -> Any {
if let collection = source as? Array<Any?> {
if let collection = source as? [Any?] {
return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
}
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?> {
if let collection = item.value as? [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 {
Expand All @@ -68,4 +68,3 @@ public struct APIHelper {
return destination
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ import Foundation
open class PetstoreClientAPI {
public static var basePath = "http://petstore.swagger.io:80/v2"
public static var credential: URLCredential?
public static var customHeaders: [String:String] = [:]
public static var customHeaders: [String: String] = [:]
public static var requestBuilderFactory: RequestBuilderFactory = URLSessionRequestBuilderFactory()
public static var apiResponseQueue: DispatchQueue = .main
}

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.
/// With the URLSession http client the request's progress only works on iOS 11.0, macOS 10.13, macCatalyst 13.0, tvOS 11.0, watchOS 4.0.
/// If you need to get the request's progress in older OS versions, please use Alamofire http client.
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
Expand All @@ -37,7 +37,7 @@ open class RequestBuilder<T> {
addHeaders(PetstoreClientAPI.customHeaders)
}

open func addHeaders(_ aHeaders:[String:String]) {
open func addHeaders(_ aHeaders: [String: String]) {
for (header, value) in aHeaders {
headers[header] = value
}
Expand All @@ -60,5 +60,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
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import Foundation



open class AnotherFakeAPI {
/**
To test special tags
Expand All @@ -17,7 +15,7 @@ open class AnotherFakeAPI {
- parameter apiResponseQueue: The queue on which api response is dispatched.
- parameter completion: completion handler to receive the data and the error objects
*/
open class func call123testSpecialTags(body: Client, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Client?,_ error: Error?) -> Void)) {
open class func call123testSpecialTags(body: Client, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Client?, _ error: Error?) -> Void)) {
call123testSpecialTagsWithRequestBuilder(body: body).execute(apiResponseQueue) { result -> Void in
switch result {
case let .success(response):
Expand Down
Loading