-
Notifications
You must be signed in to change notification settings - Fork 49
Additional unit tests for OpenAPIObjectContainer #24
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
Conversation
@swift-server-bot add to allowlist |
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.
@rboyce Thanks for the patch—and for adding some tests for it.
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.
Oops, meant to mark as "Request changes", with some minor fixups in https://github.com/apple/swift-openapi-runtime/pull/24/files#r1262219996.
Fix OpenAPIValueContainer serialization of nested values ### Motivation Credit goes to @rboyce for discovering this bug! When I saw the PR #24, I realized we didn't have any unit tests for the `OpenAPI*Container` types, which was an oversight. This PR adds those missing unit tests, and fixes the bug in casting that motivated #24. ### Modifications Adds unit tests and fixes the casting bug that expected wrapped, instead of raw stdlib values. ### Result Now all the new unit tests pass and serializing nested values in OpenAPIValueContainer and friends works correctly. ### Test Plan Most of this PR is new unit tests, verified they pass locally. Reviewed by: simonjbeaumont Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (docc test) - Build finished. ✔︎ pull request validation (integration test) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. ✖︎ pull request validation (api breakage) - Build finished. #25
@rboyce Okay I landed the base unit tests - if you'd like, you could port your additional unit tests to the new place ( |
538c735
to
eadd49a
Compare
eadd49a
to
9297cc4
Compare
Rebased past #25. This PR now just contains the additional unit tests for mixed nested values; thanks for the fix @czechboy0! |
let encoder: JSONEncoder = .init() | ||
encoder.outputFormatting = [.prettyPrinted, .sortedKeys] | ||
let data = try encoder.encode(value) | ||
XCTAssertEqual( |
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.
Please make it consistent with the other tests by using the utility functions that does the encoding/decoding and equality checks.
var dict: OpenAPIObjectContainer = .init() | ||
} | ||
|
||
do { |
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.
Why is this extra do scope here?
var dict: OpenAPIObjectContainer = .init() | ||
} | ||
|
||
do { |
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.
Same here about the do scope.
Thanks, please also update the PR description to reflect the remaining changes. |
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.
Looks good overall, I'll open another PR bringing it to our style in a bit.
Fixing up the style: #33 |
Motivation
Trying to encode an
OpenAPIValueContainer
would previously throw anEncodingError
if the untyped container contained nested dictionary or array structures. (e.g.{"dict": {"foo": "bar"}}
) Data could be decoded into this format, but it could not be re-encoded successfully.Modifications
When encoding the value of a nested JSON array or object in
OpenAPIValueContainer
, we now handle arrays and dicts by wrapping the inner value inOpenAPIValueContainer
before passing it to the encoder.(note: Based on the rest of the
encode()
implementation, it seems that this may have been expected to happen previously during decoding. Let me know if making changes on the decode side of things is preferable.)Result
Additional unit tests added to validate that encoder generates correct output for nested data structures in
OpenAPIValueContainer
, and that these data structures can be decoded and successfully re-endcoded afterward.Test Plan
Run
Test_CodableExtensions
tests, see all tests pass.