Skip to content

Commit 9a0d0a3

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

File tree

4 files changed

+189
-6
lines changed

4 files changed

+189
-6
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

+94-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 XML document is synthesized because the payload is
1616
/// not a structure or a union type.
@@ -93,7 +93,7 @@ structure HttpPayloadTraitsInputOutput {
9393
blob: Blob,
9494
}
9595

96-
/// This examples uses a `@mediaType` trait on the payload to force a custom
96+
/// This example uses a `@mediaType` trait on the payload to force a custom
9797
/// content-type to be serialized.
9898
@http(uri: "/HttpPayloadTraitsWithMediaType", method: "POST")
9999
operation HttpPayloadTraitsWithMediaType {
@@ -149,7 +149,7 @@ structure HttpPayloadTraitsWithMediaTypeInputOutput {
149149
blob: TextPlainBlob,
150150
}
151151

152-
/// This examples serializes a structure in the payload.
152+
/// This example serializes a structure in the payload.
153153
///
154154
/// Note that serializing a structure changes the wrapper element name
155155
/// to match the targeted structure.
@@ -530,3 +530,94 @@ structure HttpPayloadWithXmlNamespaceAndPrefixInputOutput {
530530
structure PayloadWithXmlNamespaceAndPrefix {
531531
name: String
532532
}
533+
534+
535+
/// This example 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: "No payload is sent if the union has no value.",
570+
protocol: restXml,
571+
method: "PUT",
572+
uri: "/HttpPayloadWithUnion",
573+
body: "",
574+
headers: {
575+
"Content-Type": "application/xml",
576+
"Content-Length": "0"
577+
},
578+
params: {}
579+
}
580+
])
581+
582+
apply HttpPayloadWithUnion @httpResponseTests([
583+
{
584+
id: "RestXmlHttpPayloadWithUnion",
585+
documentation: "Serializes a union in the payload.",
586+
protocol: restXml,
587+
code: 200,
588+
body: """
589+
<UnionPayload>
590+
<greeting>hello</greeting>
591+
</UnionPayload>""",
592+
bodyMediaType: "application/xml",
593+
headers: {
594+
"Content-Type": "application/xml",
595+
},
596+
params: {
597+
nested: {
598+
greeting: "hello"
599+
}
600+
}
601+
},
602+
{
603+
id: "RestXmlHttpPayloadWithUnsetUnion",
604+
documentation: "No payload is sent if the union has no value.",
605+
protocol: restXml,
606+
code: 200,
607+
body: "",
608+
headers: {
609+
"Content-Type": "application/xml",
610+
"Content-Length": "0"
611+
},
612+
params: {}
613+
}
614+
])
615+
616+
structure HttpPayloadWithUnionInputOutput {
617+
@httpPayload
618+
nested: UnionPayload,
619+
}
620+
621+
union UnionPayload {
622+
greeting: String
623+
}

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)