Skip to content

Commit

Permalink
Add restJson1 protocol test for content-type and POST operation with …
Browse files Browse the repository at this point in the history
…no input (#2342)
  • Loading branch information
haydenbaker committed Jul 12, 2024
1 parent 26ff08f commit 6466fe7
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 13 deletions.
95 changes: 84 additions & 11 deletions smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,22 @@ structure TestPayloadBlobInputOutput {
data: Blob
}

/// This example operation serializes a request without an HTTP body.
/// This example GET operation serializes a request without a modeled HTTP body.
///
/// These tests are to ensure we do not attach a body or related headers
/// (Content-Length, Content-Type) to operations that semantically
/// cannot produce an HTTP body.
///
@readonly
@http(uri: "/no_payload", method: "GET")
operation TestNoPayload {
operation TestGetNoPayload {
input: TestNoPayloadInputOutput,
output: TestNoPayloadInputOutput
}

apply TestNoPayload @httpRequestTests([
apply TestGetNoPayload @httpRequestTests([
{
id: "RestJsonHttpWithNoModeledBody",
id: "RestJsonHttpGetWithNoModeledBody",
documentation: "Serializes a GET request with no modeled body",
protocol: restJson1,
method: "GET",
Expand All @@ -257,9 +257,9 @@ apply TestNoPayload @httpRequestTests([
}
])

apply TestNoPayload @httpRequestTests([
apply TestGetNoPayload @httpRequestTests([
{
id: "RestJsonHttpWithHeaderMemberNoModeledBody",
id: "RestJsonHttpGetWithHeaderMemberNoModeledBody",
documentation: "Serializes a GET request with header member but no modeled body",
protocol: restJson1,
method: "GET",
Expand All @@ -278,33 +278,106 @@ apply TestNoPayload @httpRequestTests([
}
])

/// This example POST operation serializes a request without a modeled HTTP body.
///
/// These tests are to ensure we do not attach a body or related headers
/// (Content-Type) to a POST operation with no modeled payload.
///
@readonly
@http(uri: "/no_payload", method: "POST")
operation TestPostNoPayload {
input: TestNoPayloadInputOutput,
output: TestNoPayloadInputOutput
}

apply TestPostNoPayload @httpRequestTests([
{
id: "RestJsonHttpPostWithNoModeledBody",
documentation: "Serializes a POST request with no modeled body",
protocol: restJson1,
method: "POST",
uri: "/no_payload",
body: "",
forbidHeaders: [
"Content-Type"
],
params: {}
}
])

apply TestPostNoPayload @httpRequestTests([
{
id: "RestJsonHttpWithPostHeaderMemberNoModeledBody",
documentation: "Serializes a POST request with header member but no modeled body",
protocol: restJson1,
method: "POST",
uri: "/no_payload",
body: "",
headers: {
"X-Amz-Test-Id": "t-12345"
},
forbidHeaders: [
"Content-Type"
],
params: {
testId: "t-12345"
}
}
])

structure TestNoPayloadInputOutput {
@httpHeader("X-Amz-Test-Id")
testId: String,
}

/// This example operation has no input and serializes a request without an HTTP body.
/// This example GET operation has no input and serializes a request without a HTTP body.
///
/// These tests are to ensure we do not attach a body or related headers
/// (Content-Length, Content-Type) to operations that semantically
/// cannot produce an HTTP body.
///
@readonly
@http(uri: "/no_input_no_payload", method: "GET")
operation TestNoInputNoPayload {
operation TestGetNoInputNoPayload {
output: TestNoPayloadInputOutput
}

apply TestNoInputNoPayload @httpRequestTests([
apply TestGetNoInputNoPayload @httpRequestTests([
{
id: "RestJsonHttpWithNoInput",
id: "RestJsonHttpGetWithNoInput",
documentation: "Serializes a GET request for an operation with no input, and therefore no modeled body",
protocol: restJson1,
method: "GET",
uri: "/no_input_no_payload",
body: "",
forbidHeaders: [
"Content-Length",
"Content-Type",
"Content-Length"
],
params: {}
}
])

/// This example POST operation has no input and serializes a request without a HTTP body.
///
/// These tests are to ensure we do not attach a body or related headers
/// (Content-Type) to a POST operation with no modeled input.
///
@readonly
@http(uri: "/no_input_no_payload", method: "POST")
operation TestPostNoInputNoPayload {
output: TestNoPayloadInputOutput
}

apply TestPostNoInputNoPayload @httpRequestTests([
{
id: "RestJsonHttpPostWithNoInput",
documentation: "Serializes a POST request for an operation with no input, and therefore no modeled body",
protocol: restJson1,
method: "POST",
uri: "/no_input_no_payload",
body: "",
forbidHeaders: [
"Content-Type"
],
params: {}
Expand Down
6 changes: 4 additions & 2 deletions smithy-aws-protocol-tests/model/restJson1/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ service RestJson {
TestBodyStructure,
TestPayloadStructure,
TestPayloadBlob,
TestNoPayload,
TestNoInputNoPayload,
TestGetNoPayload
TestPostNoPayload,
TestGetNoInputNoPayload,
TestPostNoInputNoPayload,

// client-only timestamp parsing tests
DatetimeOffsets,
Expand Down

0 comments on commit 6466fe7

Please sign in to comment.