Skip to content

Commit

Permalink
Add tests for unions as httpPayloads
Browse files Browse the repository at this point in the history
  • Loading branch information
kstich committed Aug 31, 2023
1 parent 023dd2b commit f08e0aa
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 6 deletions.
94 changes: 91 additions & 3 deletions smithy-aws-protocol-tests/model/restJson1/http-payload.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -268,3 +268,91 @@ 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-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-Length": "0"
},
params: {}
}
])

structure HttpPayloadWithUnionInputOutput {
@httpPayload
nested: UnionPayload,
}

union UnionPayload {
greeting: String
}
1 change: 1 addition & 0 deletions smithy-aws-protocol-tests/model/restJson1/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ service RestJson {
HttpPayloadWithStructure,
HttpEnumPayload,
HttpStringPayload,
HttpPayloadWithUnion,

// @httpResponseCode tests
HttpResponseCode,
Expand Down
95 changes: 92 additions & 3 deletions smithy-aws-protocol-tests/model/restXml/http-payload.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -530,3 +530,92 @@ 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: """
<UnionPayload>
<greeting>hello</greeting>
</UnionPayload>""",
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-Length": "0"
},
params: {}
}
])

apply HttpPayloadWithUnion @httpResponseTests([
{
id: "RestXmlHttpPayloadWithUnion",
documentation: "Serializes a union in the payload.",
protocol: restXml,
code: 200,
body: """
<UnionPayload>
<greeting>hello</greeting>
</UnionPayload>""",
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-Length": "0"
},
params: {}
}
])

structure HttpPayloadWithUnionInputOutput {
@httpPayload
nested: UnionPayload,
}

union UnionPayload {
greeting: String
}
1 change: 1 addition & 0 deletions smithy-aws-protocol-tests/model/restXml/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ service RestXml {
HttpPayloadTraits,
HttpPayloadTraitsWithMediaType,
HttpPayloadWithStructure,
HttpPayloadWithUnion,
HttpPayloadWithXmlName,
BodyWithXmlName,
HttpPayloadWithMemberXmlName,
Expand Down

0 comments on commit f08e0aa

Please sign in to comment.