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

Implement key decoding strategy alteration capability #20

Merged
merged 1 commit into from
Aug 8, 2024
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
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
Loading