diff --git a/smithy-aws-protocol-tests/model/restJson1/http-payload.smithy b/smithy-aws-protocol-tests/model/restJson1/http-payload.smithy
index d9f69d2d2f3..aec3b854660 100644
--- a/smithy-aws-protocol-tests/model/restJson1/http-payload.smithy
+++ b/smithy-aws-protocol-tests/model/restJson1/http-payload.smithy
@@ -10,7 +10,7 @@ use aws.protocoltests.shared#TextPlainBlob
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests
-/// This examples serializes a blob shape in the payload.
+/// This example serializes a blob shape in the payload.
///
/// In this example, no JSON document is synthesized because the payload is
/// not a structure or a union type.
@@ -138,7 +138,7 @@ structure HttpPayloadTraitsInputOutput {
blob: Blob,
}
-/// This examples uses a `@mediaType` trait on the payload to force a custom
+/// This example uses a `@mediaType` trait on the payload to force a custom
/// content-type to be serialized.
@http(uri: "/HttpPayloadTraitsWithMediaType", method: "POST")
operation HttpPayloadTraitsWithMediaType {
@@ -196,7 +196,7 @@ structure HttpPayloadTraitsWithMediaTypeInputOutput {
blob: TextPlainBlob,
}
-/// This examples serializes a structure in the payload.
+/// This example serializes a structure in the payload.
///
/// Note that serializing a structure changes the wrapper element name
/// to match the targeted structure.
@@ -268,3 +268,93 @@ structure NestedPayload {
greeting: String,
name: String,
}
+
+/// This example serializes a union in the payload.
+@idempotent
+@http(uri: "/HttpPayloadWithUnion", method: "PUT")
+operation HttpPayloadWithUnion {
+ input: HttpPayloadWithUnionInputOutput,
+ output: HttpPayloadWithUnionInputOutput
+}
+
+apply HttpPayloadWithUnion @httpRequestTests([
+ {
+ id: "RestJsonHttpPayloadWithUnion",
+ documentation: "Serializes a union in the payload.",
+ protocol: restJson1,
+ method: "PUT",
+ uri: "/HttpPayloadWithUnion",
+ body: """
+ {
+ "greeting": "hello"
+ }""",
+ bodyMediaType: "application/json",
+ headers: {
+ "Content-Type": "application/json"
+ },
+ requireHeaders: [
+ "Content-Length"
+ ],
+ params: {
+ nested: {
+ greeting: "hello"
+ }
+ }
+ },
+ {
+ id: "RestJsonHttpPayloadWithUnsetUnion",
+ documentation: "No payload is sent if the union has no value.",
+ protocol: restJson1,
+ method: "PUT",
+ uri: "/HttpPayloadWithUnion",
+ body: "",
+ headers: {
+ "Content-Type": "application/json",
+ "Content-Length": "0"
+ },
+ params: {}
+ }
+])
+
+apply HttpPayloadWithUnion @httpResponseTests([
+ {
+ id: "RestJsonHttpPayloadWithUnion",
+ documentation: "Serializes a union in the payload.",
+ protocol: restJson1,
+ code: 200,
+ body: """
+ {
+ "greeting": "hello"
+ }""",
+ bodyMediaType: "application/json",
+ headers: {
+ "Content-Type": "application/json"
+ },
+ params: {
+ nested: {
+ greeting: "hello"
+ }
+ }
+ },
+ {
+ id: "RestJsonHttpPayloadWithUnsetUnion",
+ documentation: "No payload is sent if the union has no value.",
+ protocol: restJson1,
+ code: 200,
+ body: "",
+ headers: {
+ "Content-Type": "application/json",
+ "Content-Length": "0"
+ },
+ params: {}
+ }
+])
+
+structure HttpPayloadWithUnionInputOutput {
+ @httpPayload
+ nested: UnionPayload,
+}
+
+union UnionPayload {
+ greeting: String
+}
diff --git a/smithy-aws-protocol-tests/model/restJson1/main.smithy b/smithy-aws-protocol-tests/model/restJson1/main.smithy
index 20a8034112e..25b59bf8abc 100644
--- a/smithy-aws-protocol-tests/model/restJson1/main.smithy
+++ b/smithy-aws-protocol-tests/model/restJson1/main.smithy
@@ -58,6 +58,7 @@ service RestJson {
HttpPayloadWithStructure,
HttpEnumPayload,
HttpStringPayload,
+ HttpPayloadWithUnion,
// @httpResponseCode tests
HttpResponseCode,
diff --git a/smithy-aws-protocol-tests/model/restXml/http-payload.smithy b/smithy-aws-protocol-tests/model/restXml/http-payload.smithy
index c63a0b077b7..7ddef195919 100644
--- a/smithy-aws-protocol-tests/model/restXml/http-payload.smithy
+++ b/smithy-aws-protocol-tests/model/restXml/http-payload.smithy
@@ -10,7 +10,7 @@ use aws.protocoltests.shared#TextPlainBlob
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests
-/// This examples serializes a blob shape in the payload.
+/// This example serializes a blob shape in the payload.
///
/// In this example, no XML document is synthesized because the payload is
/// not a structure or a union type.
@@ -93,7 +93,7 @@ structure HttpPayloadTraitsInputOutput {
blob: Blob,
}
-/// This examples uses a `@mediaType` trait on the payload to force a custom
+/// This example uses a `@mediaType` trait on the payload to force a custom
/// content-type to be serialized.
@http(uri: "/HttpPayloadTraitsWithMediaType", method: "POST")
operation HttpPayloadTraitsWithMediaType {
@@ -149,7 +149,7 @@ structure HttpPayloadTraitsWithMediaTypeInputOutput {
blob: TextPlainBlob,
}
-/// This examples serializes a structure in the payload.
+/// This example serializes a structure in the payload.
///
/// Note that serializing a structure changes the wrapper element name
/// to match the targeted structure.
@@ -530,3 +530,94 @@ structure HttpPayloadWithXmlNamespaceAndPrefixInputOutput {
structure PayloadWithXmlNamespaceAndPrefix {
name: String
}
+
+
+/// This example serializes a union in the payload.
+@idempotent
+@http(uri: "/HttpPayloadWithUnion", method: "PUT")
+operation HttpPayloadWithUnion {
+ input: HttpPayloadWithUnionInputOutput,
+ output: HttpPayloadWithUnionInputOutput
+}
+
+apply HttpPayloadWithUnion @httpRequestTests([
+ {
+ id: "RestXmlHttpPayloadWithUnion",
+ documentation: "Serializes a union in the payload.",
+ protocol: restXml,
+ method: "PUT",
+ uri: "/HttpPayloadWithUnion",
+ body: """
+
+ hello
+ """,
+ bodyMediaType: "application/xml",
+ headers: {
+ "Content-Type": "application/xml",
+ },
+ requireHeaders: [
+ "Content-Length"
+ ],
+ params: {
+ nested: {
+ greeting: "hello"
+ }
+ }
+ },
+ {
+ id: "RestXmlHttpPayloadWithUnsetUnion",
+ documentation: "No payload is sent if the union has no value.",
+ protocol: restXml,
+ method: "PUT",
+ uri: "/HttpPayloadWithUnion",
+ body: "",
+ headers: {
+ "Content-Type": "application/xml",
+ "Content-Length": "0"
+ },
+ params: {}
+ }
+])
+
+apply HttpPayloadWithUnion @httpResponseTests([
+ {
+ id: "RestXmlHttpPayloadWithUnion",
+ documentation: "Serializes a union in the payload.",
+ protocol: restXml,
+ code: 200,
+ body: """
+
+ hello
+ """,
+ bodyMediaType: "application/xml",
+ headers: {
+ "Content-Type": "application/xml",
+ },
+ params: {
+ nested: {
+ greeting: "hello"
+ }
+ }
+ },
+ {
+ id: "RestXmlHttpPayloadWithUnsetUnion",
+ documentation: "No payload is sent if the union has no value.",
+ protocol: restXml,
+ code: 200,
+ body: "",
+ headers: {
+ "Content-Type": "application/xml",
+ "Content-Length": "0"
+ },
+ params: {}
+ }
+])
+
+structure HttpPayloadWithUnionInputOutput {
+ @httpPayload
+ nested: UnionPayload,
+}
+
+union UnionPayload {
+ greeting: String
+}
diff --git a/smithy-aws-protocol-tests/model/restXml/main.smithy b/smithy-aws-protocol-tests/model/restXml/main.smithy
index 949a2658802..1775f5cbc99 100644
--- a/smithy-aws-protocol-tests/model/restXml/main.smithy
+++ b/smithy-aws-protocol-tests/model/restXml/main.smithy
@@ -50,6 +50,7 @@ service RestXml {
HttpPayloadTraits,
HttpPayloadTraitsWithMediaType,
HttpPayloadWithStructure,
+ HttpPayloadWithUnion,
HttpPayloadWithXmlName,
BodyWithXmlName,
HttpPayloadWithMemberXmlName,