fixing bugs
This commit is contained in:
parent
99e5af54ab
commit
c786bcc740
|
@ -38,6 +38,7 @@ public class Endpoint<R>: ResponseRequestable {
|
||||||
public var queryParameters: [String : Any]
|
public var queryParameters: [String : Any]
|
||||||
public var bodyEncoding: BodyEncoding
|
public var bodyEncoding: BodyEncoding
|
||||||
public var responseDecoder: ResponseDecoder
|
public var responseDecoder: ResponseDecoder
|
||||||
|
public var bodyJsonSerializationOption: JSONSerialization.WritingOptions?
|
||||||
|
|
||||||
public init(path: String,
|
public init(path: String,
|
||||||
isFullPath: Bool = false,
|
isFullPath: Bool = false,
|
||||||
|
@ -46,7 +47,8 @@ public class Endpoint<R>: ResponseRequestable {
|
||||||
bodyParameters: [String: Any] = [:],
|
bodyParameters: [String: Any] = [:],
|
||||||
queryParameters: [String: Any] = [:],
|
queryParameters: [String: Any] = [:],
|
||||||
bodyEncoding: BodyEncoding = .jsonSerializationData,
|
bodyEncoding: BodyEncoding = .jsonSerializationData,
|
||||||
responseDecoder: ResponseDecoder = JSONResponseDecoder()) {
|
responseDecoder: ResponseDecoder = JSONResponseDecoder(),
|
||||||
|
bodyJsonSerializationOption: JSONSerialization.WritingOptions? = nil) {
|
||||||
self.path = path
|
self.path = path
|
||||||
self.isFullPath = isFullPath
|
self.isFullPath = isFullPath
|
||||||
self.method = method
|
self.method = method
|
||||||
|
@ -55,6 +57,7 @@ public class Endpoint<R>: ResponseRequestable {
|
||||||
self.queryParameters = queryParameters
|
self.queryParameters = queryParameters
|
||||||
self.bodyEncoding = bodyEncoding
|
self.bodyEncoding = bodyEncoding
|
||||||
self.responseDecoder = responseDecoder
|
self.responseDecoder = responseDecoder
|
||||||
|
self.bodyJsonSerializationOption = bodyJsonSerializationOption
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +71,7 @@ public protocol Requestable {
|
||||||
var bodyParameter: [String: Any] { get }
|
var bodyParameter: [String: Any] { get }
|
||||||
var queryParameters: [String: Any] { get }
|
var queryParameters: [String: Any] { get }
|
||||||
var bodyEncoding: BodyEncoding { get }
|
var bodyEncoding: BodyEncoding { get }
|
||||||
|
var bodyJsonSerializationOption: JSONSerialization.WritingOptions? { get }
|
||||||
|
|
||||||
func urlRequest(with networkConfig: NetworkConfigurable) throws -> URLRequest
|
func urlRequest(with networkConfig: NetworkConfigurable) throws -> URLRequest
|
||||||
}
|
}
|
||||||
|
@ -104,7 +108,7 @@ extension Requestable {
|
||||||
headerParameter.forEach { allHeaders.updateValue($0.key, forKey: $0.value) }
|
headerParameter.forEach { allHeaders.updateValue($0.key, forKey: $0.value) }
|
||||||
|
|
||||||
if !bodyParameter.isEmpty {
|
if !bodyParameter.isEmpty {
|
||||||
urlRequest.httpBody = encodeBody(bodyParameters: bodyParameter, bodyEncoding: bodyEncoding)
|
urlRequest.httpBody = encodeBody(bodyParameters: bodyParameter, bodyEncoding: bodyEncoding, with: bodyJsonSerializationOption)
|
||||||
}
|
}
|
||||||
urlRequest.httpMethod = method.rawValue
|
urlRequest.httpMethod = method.rawValue
|
||||||
urlRequest.allHTTPHeaderFields = allHeaders
|
urlRequest.allHTTPHeaderFields = allHeaders
|
||||||
|
|
|
@ -20,6 +20,7 @@ class NetworkServiceTests: XCTestCase {
|
||||||
var bodyParameter: [String : Any] = [:]
|
var bodyParameter: [String : Any] = [:]
|
||||||
var queryParameters: [String : Any] = [:]
|
var queryParameters: [String : Any] = [:]
|
||||||
var bodyEncoding: BodyEncoding = .stringEncodingAscii
|
var bodyEncoding: BodyEncoding = .stringEncodingAscii
|
||||||
|
var bodyJsonSerializationOption: JSONSerialization.WritingOptions?
|
||||||
|
|
||||||
init(path: String, method: HTTPMethod) {
|
init(path: String, method: HTTPMethod) {
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
Loading…
Reference in New Issue