From da5924fee19abb24a07003f1c11fb20b230286b1 Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Wed, 23 Aug 2023 14:52:52 -0500 Subject: [PATCH] Update AWS docs to ignore __type in unions Some older implementations of AWS JSON protocols will unnecessarily serialize a `__type` property, even for unions. This behavior can't be changed. To account for this, deserializers should be updated to ignore an unrecognized `__type` when deserializing unions for AWS restJson1, awsJson1_0, and awsJson1_1. --- .../aws/protocols/aws-json.rst.template | 1 + .../aws/protocols/aws-restjson1-protocol.rst | 1 + .../model/awsJson1_0/unions.smithy | 27 +++++++++++++++++++ .../model/awsJson1_1/unions.smithy | 27 +++++++++++++++++++ .../model/restJson1/unions.smithy | 27 +++++++++++++++++++ 5 files changed, 83 insertions(+) diff --git a/docs/source-2.0/aws/protocols/aws-json.rst.template b/docs/source-2.0/aws/protocols/aws-json.rst.template index bd53208a515..70c789db64e 100644 --- a/docs/source-2.0/aws/protocols/aws-json.rst.template +++ b/docs/source-2.0/aws/protocols/aws-json.rst.template @@ -132,6 +132,7 @@ to convert each shape type: * - ``union`` - JSON object. A union is serialized identically as a ``structure`` shape, but only a single member can be set to a non-null value. + Deserializers MUST ignore an unrecognized ``__type`` member if present. ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source-2.0/aws/protocols/aws-restjson1-protocol.rst b/docs/source-2.0/aws/protocols/aws-restjson1-protocol.rst index 00ac52cfc55..5ebe9a71ad0 100644 --- a/docs/source-2.0/aws/protocols/aws-restjson1-protocol.rst +++ b/docs/source-2.0/aws/protocols/aws-restjson1-protocol.rst @@ -287,6 +287,7 @@ JSON shape serialization * - ``union`` - JSON object. A union is serialized identically as a ``structure`` shape, but only a single member can be set to a non-null value. + Deserializers MUST ignore an unrecognized ``__type`` member if present. -------------------------- diff --git a/smithy-aws-protocol-tests/model/awsJson1_0/unions.smithy b/smithy-aws-protocol-tests/model/awsJson1_0/unions.smithy index ec573989b93..8c4391538a1 100644 --- a/smithy-aws-protocol-tests/model/awsJson1_0/unions.smithy +++ b/smithy-aws-protocol-tests/model/awsJson1_0/unions.smithy @@ -509,4 +509,31 @@ apply JsonUnions @httpResponseTests([ } } }, + { + id: "AwsJson10DeserializeIgnoreType" + appliesTo: "client" + documentation: "Ignores an unrecognized __type property" + protocol: awsJson1_0 + code: 200 + body: """ + { + "contents": { + "__type": "aws.protocoltests.json10#MyUnion", + "structureValue": { + "hi": "hello" + } + } + }""" + bodyMediaType: "application/json" + headers: { + "Content-Type": "application/x-amz-json-1.0" + }, + params: { + contents: { + structureValue: { + hi: "hello" + } + } + } + } ]) diff --git a/smithy-aws-protocol-tests/model/awsJson1_1/unions.smithy b/smithy-aws-protocol-tests/model/awsJson1_1/unions.smithy index 53bc3d44ce1..c36bb0a6f2f 100644 --- a/smithy-aws-protocol-tests/model/awsJson1_1/unions.smithy +++ b/smithy-aws-protocol-tests/model/awsJson1_1/unions.smithy @@ -440,4 +440,31 @@ apply JsonUnions @httpResponseTests([ } } }, + { + id: "AwsJson11DeserializeIgnoreType" + appliesTo: "client" + documentation: "Ignores an unrecognized __type property" + protocol: awsJson1_1 + code: 200 + body: """ + { + "contents": { + "__type": "aws.protocoltests.json10#MyUnion", + "structureValue": { + "hi": "hello" + } + } + }""" + bodyMediaType: "application/json" + headers: { + "Content-Type": "application/x-amz-json-1.1" + } + params: { + contents: { + structureValue: { + hi: "hello" + } + } + } + } ]) diff --git a/smithy-aws-protocol-tests/model/restJson1/unions.smithy b/smithy-aws-protocol-tests/model/restJson1/unions.smithy index f71163af415..cfbaba466f5 100644 --- a/smithy-aws-protocol-tests/model/restJson1/unions.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/unions.smithy @@ -442,6 +442,33 @@ apply JsonUnions @httpResponseTests([ } } }, + { + id: "RestJsonDeserializeIgnoreType" + appliesTo: "client" + documentation: "Ignores an unrecognized __type property" + protocol: restJson1 + code: 200 + body: """ + { + "contents": { + "__type": "aws.protocoltests.json10#MyUnion", + "structureValue": { + "hi": "hello" + } + } + }""" + bodyMediaType: "application/json" + headers: { + "Content-Type": "application/json" + } + params: { + contents: { + structureValue: { + hi: "hello" + } + } + } + } ])