Skip to content

Commit 6404325

Browse files
committed
Add tests for unions as httpPayloads
1 parent 023dd2b commit 6404325

File tree

4 files changed

+188
-3
lines changed

4 files changed

+188
-3
lines changed

smithy-aws-protocol-tests/model/restJson1/http-payload.smithy

+93-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use aws.protocoltests.shared#TextPlainBlob
1010
use smithy.test#httpRequestTests
1111
use smithy.test#httpResponseTests
1212

13-
/// This examples serializes a blob shape in the payload.
13+
/// This example serializes a blob shape in the payload.
1414
///
1515
/// In this example, no JSON document is synthesized because the payload is
1616
/// not a structure or a union type.
@@ -138,7 +138,7 @@ structure HttpPayloadTraitsInputOutput {
138138
blob: Blob,
139139
}
140140

141-
/// This examples uses a `@mediaType` trait on the payload to force a custom
141+
/// This example uses a `@mediaType` trait on the payload to force a custom
142142
/// content-type to be serialized.
143143
@http(uri: "/HttpPayloadTraitsWithMediaType", method: "POST")
144144
operation HttpPayloadTraitsWithMediaType {
@@ -196,7 +196,7 @@ structure HttpPayloadTraitsWithMediaTypeInputOutput {
196196
blob: TextPlainBlob,
197197
}
198198

199-
/// This examples serializes a structure in the payload.
199+
/// This example serializes a structure in the payload.
200200
///
201201
/// Note that serializing a structure changes the wrapper element name
202202
/// to match the targeted structure.
@@ -268,3 +268,93 @@ structure NestedPayload {
268268
greeting: String,
269269
name: String,
270270
}
271+
272+
/// This example serializes a union in the payload.
273+
@idempotent
274+
@http(uri: "/HttpPayloadWithUnion", method: "PUT")
275+
operation HttpPayloadWithUnion {
276+
input: HttpPayloadWithUnionInputOutput,
277+
output: HttpPayloadWithUnionInputOutput
278+
}
279+
280+
apply HttpPayloadWithUnion @httpRequestTests([
281+
{
282+
id: "RestJsonHttpPayloadWithUnion",
283+
documentation: "Serializes a union in the payload.",
284+
protocol: restJson1,
285+
method: "PUT",
286+
uri: "/HttpPayloadWithUnion",
287+
body: """
288+
{
289+
"greeting": "hello"
290+
}""",
291+
bodyMediaType: "application/json",
292+
headers: {
293+
"Content-Type": "application/json"
294+
},
295+
requireHeaders: [
296+
"Content-Length"
297+
],
298+
params: {
299+
nested: {
300+
greeting: "hello"
301+
}
302+
}
303+
},
304+
{
305+
id: "RestJsonHttpPayloadWithUnsetUnion",
306+
documentation: "No payload is sent if the union has no value.",
307+
protocol: restJson1,
308+
method: "PUT",
309+
uri: "/HttpPayloadWithUnion",
310+
body: "",
311+
headers: {
312+
"Content-Type": "application/json",
313+
"Content-Length": "0"
314+
},
315+
params: {}
316+
}
317+
])
318+
319+
apply HttpPayloadWithUnion @httpResponseTests([
320+
{
321+
id: "RestJsonHttpPayloadWithUnion",
322+
documentation: "Serializes a union in the payload.",
323+
protocol: restJson1,
324+
code: 200,
325+
body: """
326+
{
327+
"greeting": "hello"
328+
}""",
329+
bodyMediaType: "application/json",
330+
headers: {
331+
"Content-Type": "application/json"
332+
},
333+
params: {
334+
nested: {
335+
greeting: "hello"
336+
}
337+
}
338+
},
339+
{
340+
id: "RestJsonHttpPayloadWithUnsetUnion",
341+
documentation: "No payload is sent if the union has no value.",
342+
protocol: restJson1,
343+
code: 200,
344+
body: "",
345+
headers: {
346+
"Content-Type": "application/json",
347+
"Content-Length": "0"
348+
},
349+
params: {}
350+
}
351+
])
352+
353+
structure HttpPayloadWithUnionInputOutput {
354+
@httpPayload
355+
nested: UnionPayload,
356+
}
357+
358+
union UnionPayload {
359+
greeting: String
360+
}

smithy-aws-protocol-tests/model/restJson1/main.smithy

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ service RestJson {
5858
HttpPayloadWithStructure,
5959
HttpEnumPayload,
6060
HttpStringPayload,
61+
HttpPayloadWithUnion,
6162

6263
// @httpResponseCode tests
6364
HttpResponseCode,

smithy-aws-protocol-tests/model/restXml/http-payload.smithy

+93
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,96 @@ structure HttpPayloadWithXmlNamespaceAndPrefixInputOutput {
530530
structure PayloadWithXmlNamespaceAndPrefix {
531531
name: String
532532
}
533+
534+
535+
/// This examples serializes a union in the payload.
536+
@idempotent
537+
@http(uri: "/HttpPayloadWithUnion", method: "PUT")
538+
operation HttpPayloadWithUnion {
539+
input: HttpPayloadWithUnionInputOutput,
540+
output: HttpPayloadWithUnionInputOutput
541+
}
542+
543+
apply HttpPayloadWithUnion @httpRequestTests([
544+
{
545+
id: "RestXmlHttpPayloadWithUnion",
546+
documentation: "Serializes a union in the payload",
547+
protocol: restXml,
548+
method: "PUT",
549+
uri: "/HttpPayloadWithUnion",
550+
body: """
551+
<UnionPayload>
552+
<greeting>hello</greeting>
553+
</UnionPayload>""",
554+
bodyMediaType: "application/xml",
555+
headers: {
556+
"Content-Type": "application/xml",
557+
},
558+
requireHeaders: [
559+
"Content-Length"
560+
],
561+
params: {
562+
nested: {
563+
greeting: "hello"
564+
}
565+
}
566+
},
567+
{
568+
id: "RestXmlHttpPayloadWithUnsetUnion",
569+
documentation: "Serializes an unset union in the payload",
570+
protocol: restXml,
571+
method: "PUT",
572+
uri: "/HttpPayloadWithUnion",
573+
body: "",
574+
headers: {
575+
"Content-Length": "0"
576+
},
577+
forbidHeaders: [
578+
"Content-Type"
579+
],
580+
params: {}
581+
}
582+
])
583+
584+
apply HttpPayloadWithUnion @httpResponseTests([
585+
{
586+
id: "RestXmlHttpPayloadWithUnion",
587+
documentation: "Serializes a union in the payload",
588+
protocol: restXml,
589+
code: 200,
590+
body: """
591+
<UnionPayload>
592+
<greeting>hello</greeting>
593+
</UnionPayload>""",
594+
bodyMediaType: "application/xml",
595+
headers: {
596+
"Content-Type": "application/xml",
597+
},
598+
params: {
599+
nested: {
600+
greeting: "hello"
601+
}
602+
}
603+
},
604+
{
605+
id: "RestXmlHttpPayloadWithUnsetUnion",
606+
documentation: "Serializes an unset union in the payload",
607+
protocol: restXml,
608+
code: 200,
609+
body: "",
610+
headers: {
611+
"Content-Type": "application/xml",
612+
"Content-Length": "0"
613+
},
614+
params: {}
615+
}
616+
])
617+
618+
structure HttpPayloadWithUnionInputOutput {
619+
@httpPayload
620+
nested: UnionPayload,
621+
}
622+
623+
union UnionPayload {
624+
greeting: String
625+
}

smithy-aws-protocol-tests/model/restXml/main.smithy

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ service RestXml {
5050
HttpPayloadTraits,
5151
HttpPayloadTraitsWithMediaType,
5252
HttpPayloadWithStructure,
53+
HttpPayloadWithUnion,
5354
HttpPayloadWithXmlName,
5455
BodyWithXmlName,
5556
HttpPayloadWithMemberXmlName,

0 commit comments

Comments
 (0)