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

Servers must reject {} when deserializing a union #2300

Conversation

david-perez
Copy link
Contributor

Once we're inside of a {} JSON object, a known union variant must be
provided. Servers must not accept {} as "the union shape was not set"
when the union shape is optional (which was the behavior in smithy-rs
prior to smithy-lang/smithy-rs#3481).

This commit adds a protocol test to pin this behavior.

Testing

I verified that the added test fails in smithy-rs when checking out a commit
prior to smithy-lang/smithy-rs#3481

thread 'operation::server_union_with_empty_body_operation_test::rest_json_with_empty_json_object_for_union_variant_malformed_request' panicked at 'request should have been rejected, but we accepted it; we parsed operation input `UnionWithEmptyBodyOperationInput { member: None }`', rest_json_extras/rust-server-codegen/src/operation.rs:774:52

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Once we're inside of a `{}` JSON object, a known union variant must be
provided. Servers must not accept `{}` as "the union shape was not set"
when the union shape is optional (which was the behavior in smithy-rs
prior to smithy-lang/smithy-rs#3481).

This commit adds a protocol test to pin this behavior.
@david-perez david-perez requested a review from a team as a code owner May 24, 2024 16:38
@david-perez
Copy link
Contributor Author

This applies to all JSON-based protocols. But it seems like the repo only has @httpMalformedRequestTests for restJson1.

@david-perez
Copy link
Contributor Author

Note that clients should reject {} too when deserializing a union in a response (instead of setting an "unknown union variant"). But there's no @httpMalformedResponseTests to pin this behavior :(

@mtdowling mtdowling merged commit 5946fd7 into smithy-lang:main May 24, 2024
13 checks passed
@david-perez david-perez deleted the davidpz/dont-deserialize-empty-object-as-unset-union-variant branch May 24, 2024 17:24
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