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 30, 2023
1 parent 023dd2b commit 6404325
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 3 deletions.
96 changes: 93 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,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
}
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
93 changes: 93 additions & 0 deletions smithy-aws-protocol-tests/model/restXml/http-payload.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,96 @@ structure HttpPayloadWithXmlNamespaceAndPrefixInputOutput {
structure PayloadWithXmlNamespaceAndPrefix {
name: String
}


/// This examples 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: "Serializes an unset union in the payload",
protocol: restXml,
method: "PUT",
uri: "/HttpPayloadWithUnion",
body: "",
headers: {
"Content-Length": "0"
},
forbidHeaders: [
"Content-Type"
],
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: "Serializes an unset union in the payload",
protocol: restXml,
code: 200,
body: "",
headers: {
"Content-Type": "application/xml",
"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 6404325

Please sign in to comment.