fixing bugs

This commit is contained in:
Ali Fakih 2020-04-19 01:58:09 +03:00
parent 99e5af54ab
commit c786bcc740
2 changed files with 7 additions and 2 deletions

View File

@ -38,6 +38,7 @@ public class Endpoint<R>: ResponseRequestable {
public var queryParameters: [String : Any]
public var bodyEncoding: BodyEncoding
public var responseDecoder: ResponseDecoder
public var bodyJsonSerializationOption: JSONSerialization.WritingOptions?
public init(path: String,
isFullPath: Bool = false,
@ -46,7 +47,8 @@ public class Endpoint<R>: ResponseRequestable {
bodyParameters: [String: Any] = [:],
queryParameters: [String: Any] = [:],
bodyEncoding: BodyEncoding = .jsonSerializationData,
responseDecoder: ResponseDecoder = JSONResponseDecoder()) {
responseDecoder: ResponseDecoder = JSONResponseDecoder(),
bodyJsonSerializationOption: JSONSerialization.WritingOptions? = nil) {
self.path = path
self.isFullPath = isFullPath
self.method = method
@ -55,6 +57,7 @@ public class Endpoint<R>: ResponseRequestable {
self.queryParameters = queryParameters
self.bodyEncoding = bodyEncoding
self.responseDecoder = responseDecoder
self.bodyJsonSerializationOption = bodyJsonSerializationOption
}
}
@ -68,6 +71,7 @@ public protocol Requestable {
var bodyParameter: [String: Any] { get }
var queryParameters: [String: Any] { get }
var bodyEncoding: BodyEncoding { get }
var bodyJsonSerializationOption: JSONSerialization.WritingOptions? { get }
func urlRequest(with networkConfig: NetworkConfigurable) throws -> URLRequest
}
@ -104,7 +108,7 @@ extension Requestable {
headerParameter.forEach { allHeaders.updateValue($0.key, forKey: $0.value) }
if !bodyParameter.isEmpty {
urlRequest.httpBody = encodeBody(bodyParameters: bodyParameter, bodyEncoding: bodyEncoding)
urlRequest.httpBody = encodeBody(bodyParameters: bodyParameter, bodyEncoding: bodyEncoding, with: bodyJsonSerializationOption)
}
urlRequest.httpMethod = method.rawValue
urlRequest.allHTTPHeaderFields = allHeaders

View File

@ -20,6 +20,7 @@ class NetworkServiceTests: XCTestCase {
var bodyParameter: [String : Any] = [:]
var queryParameters: [String : Any] = [:]
var bodyEncoding: BodyEncoding = .stringEncodingAscii
var bodyJsonSerializationOption: JSONSerialization.WritingOptions?
init(path: String, method: HTTPMethod) {
self.path = path