Skip to content

Commit ae8408f

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

File tree

4 files changed

+186
-6
lines changed

4 files changed

+186
-6
lines changed

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

+91-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,91 @@ 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-Length": "0"
313+
},
314+
params: {}
315+
}
316+
])
317+
318+
apply HttpPayloadWithUnion @httpResponseTests([
319+
{
320+
id: "RestJsonHttpPayloadWithUnion",
321+
documentation: "Serializes a union in the payload.",
322+
protocol: restJson1,
323+
code: 200,
324+
body: """
325+
{
326+
"greeting": "hello"
327+
}""",
328+
bodyMediaType: "application/json",
329+
headers: {
330+
"Content-Type": "application/json"
331+
},
332+
params: {
333+
nested: {
334+
greeting: "hello"
335+
}
336+
}
337+
},
338+
{
339+
id: "RestJsonHttpPayloadWithUnsetUnion",
340+
documentation: "No payload is sent if the union has no value.",
341+
protocol: restJson1,
342+
code: 200,
343+
body: "",
344+
headers: {
345+
"Content-Length": "0"
346+
},
347+
params: {}
348+
}
349+
])
350+
351+
structure HttpPayloadWithUnionInputOutput {
352+
@httpPayload
353+
nested: UnionPayload,
354+
}
355+
356+
union UnionPayload {
357+
greeting: String
358+
}

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-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,93 @@ 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-Length": "0"
610+
},
611+
params: {}
612+
}
613+
])
614+
615+
structure HttpPayloadWithUnionInputOutput {
616+
@httpPayload
617+
nested: UnionPayload,
618+
}
619+
620+
union UnionPayload {
621+
greeting: String
622+
}

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)