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

Decode response header data from Codable userInfo #565

Merged
merged 10 commits into from
Jul 18, 2023
Merged

Conversation

adam-fowler
Copy link
Member

@adam-fowler adam-fowler commented Jul 14, 2023

One of the things that has bugged me most about Soto is we had to copy our own version of JSONDecoder(), to extract the DictionaryDecoding from it. This means we were dependent on an old version of the decoder which hasn't kept up with changes being made to the original. This'll be more important as we move to the swift foundation which has introduced more optimisations.

This PR gets rid of our dependency on DictionaryDecoder and allows us to use the latest JSONEncoder. It creates a container that holds the raw response which is passed to the decoder via userInfo. It is then the responsibility of the individual init(decoder:) functions to extract the values from the correct place. Because the individual response shapes are now responsible for extracting their data from the correct place generateOutputShape is considerably simplified.

See companion commits soto-project/soto-codegenerator#73 and soto-project/soto#685

@codecov
Copy link

codecov bot commented Jul 14, 2023

Codecov Report

Merging #565 (7869961) into 7.x.x (f3d3461) will increase coverage by 1.49%.
The diff coverage is 58.20%.

@@            Coverage Diff             @@
##            7.x.x     #565      +/-   ##
==========================================
+ Coverage   77.38%   78.87%   +1.49%     
==========================================
  Files          71       71              
  Lines        7447     6292    -1155     
==========================================
- Hits         5763     4963     -800     
+ Misses       1684     1329     -355     
Impacted Files Coverage Δ
Sources/SotoCore/AWSClient.swift 89.91% <ø> (ø)
Sources/SotoCore/AWSService.swift 94.44% <ø> (ø)
...ources/SotoCore/Concurrency/AnyAsyncSequence.swift 100.00% <ø> (ø)
Sources/SotoCore/Doc/AWSShape.swift 50.72% <0.00%> (-21.02%) ⬇️
Sources/SotoCore/Encoder/ResponseContainer.swift 37.17% <37.17%> (ø)
Sources/SotoCore/HTTP/AWSHTTPTypes.swift 81.53% <66.66%> (ø)
Sources/SotoCore/Message/AWSResponse+HAL.swift 96.15% <83.33%> (-0.15%) ⬇️
Sources/SotoCore/Message/AWSResponse.swift 96.13% <97.29%> (+1.63%) ⬆️
Sources/SotoCore/Message/AWSRequest.swift 94.87% <100.00%> (ø)
...otoCore/Message/Middleware/LoggingMiddleware.swift 95.65% <100.00%> (ø)

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Sources/SotoCore/Encoder/ResponseContainer.swift Outdated Show resolved Hide resolved
@adam-fowler adam-fowler merged commit 15744ff into 7.x.x Jul 18, 2023
@adam-fowler adam-fowler deleted the codable-userinfo branch July 18, 2023 07:09
adam-fowler added a commit that referenced this pull request Jul 24, 2023
* Rename HTTPBody to AWSHTTPBody

* Add AWSResponse to Codable userInfo

* Add decode functions for AWSResponse

* ResponseContainer for decoding

* Fix tests after userInfo changes

* Remove DictionaryDecoder

Now we pass the response via uesrInfo to the decoder and decode header, body and payload in the init(from) function, we can use the JSONDecoder for decoding responses.

* Fix tests

* Re-organise root element code

* Fix after merge

* Update Sources/SotoCore/Encoder/ResponseContainer.swift

Co-authored-by: Tim Condon <[email protected]>

---------

Co-authored-by: Tim Condon <[email protected]>
adam-fowler added a commit that referenced this pull request Jul 29, 2023
* Rename HTTPBody to AWSHTTPBody

* Add AWSResponse to Codable userInfo

* Add decode functions for AWSResponse

* ResponseContainer for decoding

* Fix tests after userInfo changes

* Remove DictionaryDecoder

Now we pass the response via uesrInfo to the decoder and decode header, body and payload in the init(from) function, we can use the JSONDecoder for decoding responses.

* Fix tests

* Re-organise root element code

* Fix after merge

* Update Sources/SotoCore/Encoder/ResponseContainer.swift

Co-authored-by: Tim Condon <[email protected]>

---------

Co-authored-by: Tim Condon <[email protected]>
adam-fowler added a commit that referenced this pull request Aug 12, 2023
* Rename HTTPBody to AWSHTTPBody

* Add AWSResponse to Codable userInfo

* Add decode functions for AWSResponse

* ResponseContainer for decoding

* Fix tests after userInfo changes

* Remove DictionaryDecoder

Now we pass the response via uesrInfo to the decoder and decode header, body and payload in the init(from) function, we can use the JSONDecoder for decoding responses.

* Fix tests

* Re-organise root element code

* Fix after merge

* Update Sources/SotoCore/Encoder/ResponseContainer.swift

Co-authored-by: Tim Condon <[email protected]>

---------

Co-authored-by: Tim Condon <[email protected]>
adam-fowler added a commit that referenced this pull request Dec 24, 2023
* Rename HTTPBody to AWSHTTPBody

* Add AWSResponse to Codable userInfo

* Add decode functions for AWSResponse

* ResponseContainer for decoding

* Fix tests after userInfo changes

* Remove DictionaryDecoder

Now we pass the response via uesrInfo to the decoder and decode header, body and payload in the init(from) function, we can use the JSONDecoder for decoding responses.

* Fix tests

* Re-organise root element code

* Fix after merge

* Update Sources/SotoCore/Encoder/ResponseContainer.swift

Co-authored-by: Tim Condon <[email protected]>

---------

Co-authored-by: Tim Condon <[email protected]>
adam-fowler added a commit that referenced this pull request Apr 5, 2024
* Rename HTTPBody to AWSHTTPBody

* Add AWSResponse to Codable userInfo

* Add decode functions for AWSResponse

* ResponseContainer for decoding

* Fix tests after userInfo changes

* Remove DictionaryDecoder

Now we pass the response via uesrInfo to the decoder and decode header, body and payload in the init(from) function, we can use the JSONDecoder for decoding responses.

* Fix tests

* Re-organise root element code

* Fix after merge

* Update Sources/SotoCore/Encoder/ResponseContainer.swift

Co-authored-by: Tim Condon <[email protected]>

---------

Co-authored-by: Tim Condon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants