Skip to content

Commit

Permalink
Implement key decoding strategy alteration capability
Browse files Browse the repository at this point in the history
  • Loading branch information
okhan-okbay-cko committed Aug 8, 2024
1 parent 53f91a4 commit 9649da7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Sources/CheckoutNetwork/CheckoutNetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public class CheckoutNetworkClient: CheckoutClientInterface {
}

do {
let dataResponse = try JSONDecoder().decode(T.self, from: data)
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = configuration.decodingStrategy
let dataResponse = try decoder.decode(T.self, from: data)

completionHandler(.success(dataResponse))
} catch {
completionHandler(.failure(error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public struct RequestConfiguration {

/// Request created from the consumers configuration
private(set) public var request: URLRequest
var decodingStrategy: JSONDecoder.KeyDecodingStrategy

/// Create request configuration with provided parameters. In case of failure will throw a `CheckoutNetworkError`
///
Expand All @@ -26,7 +27,8 @@ public struct RequestConfiguration {
queryItems: [String: String] = [:],
customHeaders: [String: String] = [:],
bodyData: Data? = nil,
mimeType: MIMEType = .JSON) throws {
mimeType: MIMEType = .JSON,
decodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys) throws {
// Validate URL can be broken down to components for formatting
guard var components = URLComponents(url: path.url(), resolvingAgainstBaseURL: true) else {
throw CheckoutNetworkError.invalidURL
Expand Down Expand Up @@ -54,7 +56,8 @@ public struct RequestConfiguration {
request.addValue(mimeType.rawValue, forHTTPHeaderField: MIMEType.key)
}
customHeaders.forEach { request.addValue($0.value, forHTTPHeaderField: $0.key) }


self.decodingStrategy = decodingStrategy
self.request = request
}

Expand Down

0 comments on commit 9649da7

Please sign in to comment.