-
Notifications
You must be signed in to change notification settings - Fork 96
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
feat: allow to pass a custom JSONDecoder
to OnRequestHandler
#155
feat: allow to pass a custom JSONDecoder
to OnRequestHandler
#155
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution and for validating it with tests, @DominikPalo! 🚀
Code Coverage Report
SwiftLint found issues
Generated by 🚫 Danger Swift against 47cdf02 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 nice!
This PR allows providing a custom instance of
JSONEncoder
while initializing theOnRequestHandler
.Motivation
Some API endpoints require all JSON keys in payloads to adhere to the snake-case naming convention. However, to be consistent with the Swift naming convention, we use camelCase naming convention for declaring properties in underlying Codable structures (JSON models). When calling the API, we configure the Alamofire key encoding strategy to snake-case (
encoder.keyEncodingStrategy = .convertToSnakeCase
). Unfortunately, with the current implementation, it is not possible to mock such endpoints, as the request handler always uses the defaultJSONDecoder()
for parsing/decoding the request body.After applying this PR, it will be possible to configure the
JSONDecoder
as needed; for example, in our case, to set the key decoding strategy to snake_case: