Skip to content

Commit

Permalink
Update AWS docs to ignore __type in unions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mtdowling committed Aug 23, 2023
1 parent f44e494 commit da5924f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source-2.0/aws/protocols/aws-json.rst.template
Original file line number Diff line number Diff line change
Expand Up @@ -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.


~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions docs/source-2.0/aws/protocols/aws-restjson1-protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.


--------------------------
Expand Down
27 changes: 27 additions & 0 deletions smithy-aws-protocol-tests/model/awsJson1_0/unions.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
])
27 changes: 27 additions & 0 deletions smithy-aws-protocol-tests/model/awsJson1_1/unions.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
])
27 changes: 27 additions & 0 deletions smithy-aws-protocol-tests/model/restJson1/unions.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
])


Expand Down

0 comments on commit da5924f

Please sign in to comment.