From e5f9e9bc0cb5c1b801640600887f67c72b5e5687 Mon Sep 17 00:00:00 2001 From: david-perez Date: Fri, 24 May 2024 18:26:20 +0200 Subject: [PATCH] Servers must reject `{}` when deserializing a union 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 https://github.com/smithy-lang/smithy-rs/pull/3481). This commit adds a protocol test to pin this behavior. --- .../malformedRequests/malformed-union.smithy | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/smithy-aws-protocol-tests/model/restJson1/malformedRequests/malformed-union.smithy b/smithy-aws-protocol-tests/model/restJson1/malformedRequests/malformed-union.smithy index cd0ca8cd477..ab4571cdb51 100644 --- a/smithy-aws-protocol-tests/model/restJson1/malformedRequests/malformed-union.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/malformedRequests/malformed-union.smithy @@ -78,6 +78,28 @@ apply MalformedUnion @httpMalformedRequestTests([ } } }, + { + id: "RestJsonMalformedUnionEmptyObjectNoFieldsSet", + documentation: """ + When the union is an empty object, it has no fields set, so the + response should be a 400 SerializationException.""", + protocol: restJson1, + request: { + method: "POST", + uri: "/MalformedUnion", + body: """ + { "union" : { } }""", + headers: { + "content-type": "application/json" + } + }, + response: { + code: 400, + headers: { + "x-amzn-errortype": "SerializationException" + } + } + }, { id: "RestJsonMalformedUnionValueIsArray", documentation: """