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 protocol tests relating to Content-Type and @httpPayload #2314

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
138 changes: 138 additions & 0 deletions smithy-aws-protocol-tests/model/restJson1/http-payload.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $version: "2.0"
namespace aws.protocoltests.restjson

use aws.protocols#restJson1
use smithy.test#httpMalformedRequestTests
use aws.protocoltests.shared#TextPlainBlob
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests
Expand Down Expand Up @@ -76,6 +77,26 @@ apply HttpPayloadTraits @httpRequestTests([
},
appliesTo: "server",
},
{
id: "RestJsonHttpPayloadTraitsWithBlobAcceptsNoContentType",
documentation: """
Servers must accept no content type for blob inputs
without the media type trait.""",
protocol: restJson1,
method: "POST",
uri: "/HttpPayloadTraits",
body: "This is definitely a jpeg",
bodyMediaType: "application/octet-stream",
headers: {
"X-Foo": "Foo",
},
params: {
foo: "Foo",
blob: "This is definitely a jpeg"
},
appliesTo: "server",
tags: [ "content-type" ]
},
{
id: "RestJsonHttpPayloadTraitsWithBlobAcceptsAllAccepts",
documentation: """
Expand Down Expand Up @@ -353,3 +374,120 @@ structure HttpPayloadWithUnionInputOutput {
union UnionPayload {
greeting: String
}

/// This example serializes a string shape in the payload.
///
/// In this example, no JSON document is synthesized because the payload is
/// not a structure or a union type.
@http(uri: "/HttpPayloadTraitOnString", method: "POST")
operation HttpPayloadTraitOnString {
david-perez marked this conversation as resolved.
Show resolved Hide resolved
input: HttpPayloadTraitOnStringInputOutput,
output: HttpPayloadTraitOnStringInputOutput
}

structure HttpPayloadTraitOnStringInputOutput {
@httpPayload
foo: String,
}

apply HttpPayloadTraitOnString @httpRequestTests([
{
id: "RestJsonHttpPayloadTraitOnString",
documentation: "Serializes a string in the HTTP payload",
protocol: restJson1,
method: "POST",
uri: "/HttpPayloadTraitOnString",
body: "Foo",
bodyMediaType: "text/plain",
headers: {
"Content-Type": "text/plain",
},
requireHeaders: [
"Content-Length"
],
params: {
foo: "Foo",
}
},
])

apply HttpPayloadTraitOnString @httpResponseTests([
{
id: "RestJsonHttpPayloadTraitOnString",
documentation: "Serializes a string in the HTTP payload",
protocol: restJson1,
code: 200,
body: "Foo",
bodyMediaType: "text/plain",
headers: {
"Content-Type": "text/plain",
},
params: {
foo: "Foo",
}
},
])

apply HttpPayloadTraitOnString @httpMalformedRequestTests([
{
id: "RestJsonHttpPayloadTraitOnStringNoContentType",
documentation: "Serializes a string in the HTTP payload without a content-type header",
protocol: restJson1,
request: {
method: "POST",
uri: "/HttpPayloadTraitOnString",
body: "Foo",
// We expect a `Content-Type` header but none was provided.
},
response: {
code: 415,
headers: {
"x-amzn-errortype": "UnsupportedMediaTypeException"
}
},
tags: [ "content-type" ]
},
{
id: "RestJsonHttpPayloadTraitOnStringWrongContentType",
documentation: "Serializes a string in the HTTP payload without the expected content-type header",
protocol: restJson1,
request: {
method: "POST",
uri: "/HttpPayloadTraitOnString",
body: "Foo",
headers: {
// We expect `text/plain`.
"Content-Type": "application/json",
},
},
response: {
code: 415,
headers: {
"x-amzn-errortype": "UnsupportedMediaTypeException"
}
},
tags: [ "content-type" ]
},
{
id: "RestJsonHttpPayloadTraitOnStringUnsatisfiableAccept",
documentation: "Serializes a string in the HTTP payload with an unstatisfiable accept header",
protocol: restJson1,
request: {
method: "POST",
uri: "/HttpPayloadTraitOnString",
body: "Foo",
headers: {
"Content-Type": "text/plain",
// We can't satisfy this requirement; the server will return `text/plain`.
"Accept": "application/json",
},
},
response: {
code: 406,
headers: {
"x-amzn-errortype": "NotAcceptableException"
}
},
tags: [ "accept" ]
},
])
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use smithy.test#httpResponseTests
{
id: "RestJsonEnumPayloadRequest",
uri: "/EnumPayload",
headers: { "Content-Type": "text/plain" },
body: "enumvalue",
params: { payload: "enumvalue" },
method: "POST",
Expand All @@ -19,6 +20,7 @@ use smithy.test#httpResponseTests
@httpResponseTests([
{
id: "RestJsonEnumPayloadResponse",
headers: { "Content-Type": "text/plain" },
body: "enumvalue",
params: { payload: "enumvalue" },
protocol: "aws.protocols#restJson1",
Expand All @@ -44,6 +46,7 @@ enum StringEnum {
{
id: "RestJsonStringPayloadRequest",
uri: "/StringPayload",
headers: { "Content-Type": "text/plain" },
body: "rawstring",
params: { payload: "rawstring" },
method: "POST",
Expand All @@ -53,6 +56,7 @@ enum StringEnum {
@httpResponseTests([
{
id: "RestJsonStringPayloadResponse",
headers: { "Content-Type": "text/plain" },
body: "rawstring",
params: { payload: "rawstring" },
protocol: "aws.protocols#restJson1",
Expand Down
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 @@ -62,6 +62,7 @@ service RestJson {
HttpEnumPayload,
HttpStringPayload,
HttpPayloadWithUnion,
HttpPayloadTraitOnString,

// @httpResponseCode tests
HttpResponseCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use smithy.test#httpResponseTests
{
id: "RestXmlEnumPayloadRequest",
uri: "/EnumPayload",
headers: { "Content-Type": "text/plain" },
body: "enumvalue",
params: { payload: "enumvalue" },
method: "POST",
Expand All @@ -19,6 +20,7 @@ use smithy.test#httpResponseTests
@httpResponseTests([
{
id: "RestXmlEnumPayloadResponse",
headers: { "Content-Type": "text/plain" },
body: "enumvalue",
params: { payload: "enumvalue" },
protocol: "aws.protocols#restXml",
Expand All @@ -44,6 +46,7 @@ enum StringEnum {
{
id: "RestXmlStringPayloadRequest",
uri: "/StringPayload",
headers: { "Content-Type": "text/plain" },
body: "rawstring",
params: { payload: "rawstring" },
method: "POST",
Expand All @@ -53,6 +56,7 @@ enum StringEnum {
@httpResponseTests([
{
id: "RestXmlStringPayloadResponse",
headers: { "Content-Type": "text/plain" },
body: "rawstring",
params: { payload: "rawstring" },
protocol: "aws.protocols#restXml",
Expand Down
Loading