Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for unions as httpPayloads #1908

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
96 changes: 93 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,93 @@ 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-Type": "application/xml",
"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