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 639ba0b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/verify-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:
jobs:
lint:
name: SwiftLint
runs-on: macos-latest
runs-on: macos-13-large

steps:
- name: Checkout
Expand Down
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 639ba0b

Please sign in to comment.