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

Fix protocol test issues #692

Merged
merged 1 commit into from
Jan 29, 2021
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
122 changes: 94 additions & 28 deletions smithy-aws-protocol-tests/model/awsJson1_0/empty-input-output.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,97 @@ operation NoInputAndNoOutput {}

apply NoInputAndNoOutput @httpRequestTests([
{
id: "AwsJson10NoInputAndNoOutput",
documentation: "No input serializes no payload",
id: "AwsJson10MustAlwaysSendEmptyJsonPayload",
documentation: """
Clients must always send an empty JSON object payload for
operations with no input (that is, `{}`). While AWS service
implementations support requests with no payload or requests
that send `{}`, always sending `{}` from the client is
preferred for forward compatibility in case input is ever
added to an operation.""",
protocol: awsJson1_0,
method: "POST",
headers: {
"Content-Type": "application/x-amz-json-1.0",
"X-Amz-Target": "JsonRpc10.NoInputAndNoOutput",
},
uri: "/",
}
body: "{}",
bodyMediaType: "application/json"
},
{
id: "AwsJson10ServiceSupportsNoPayloadForNoInput",
documentation: """
Service implementations must support no payload or an empty
object payload for operations that define no input. However,
despite the lack of a payload, a Content-Type header is still
required in order for the service to properly detect the
protocol.""",
protocol: awsJson1_0,
method: "POST",
headers: {
"Content-Type": "application/x-amz-json-1.0",
"X-Amz-Target": "JsonRpc10.NoInputAndNoOutput",
},
uri: "/",
body: "",
appliesTo: "server"
},
])

apply NoInputAndNoOutput @httpResponseTests([
{
id: "AwsJson10NoInputAndNoOutput",
documentation: "No output serializes no payload",
{
id: "AwsJson10HandlesEmptyOutputShape",
protocol: awsJson1_0,
documentation: """
When no output is defined, the service is expected to return
an empty payload, however, client must ignore a JSON payload
if one is returned. This ensures that if output is added later,
then it will not break the client.""",
body: "{}",
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.0",
},
code: 200,
}
// Service implementations must ignore this test.
appliesTo: "client"
},
{
id: "AwsJson10HandlesUnexpectedJsonOutput",
protocol: awsJson1_0,
documentation: """
This client-only test builds on handles_empty_output_shape,
by including unexpected fields in the JSON. A client
needs to ignore JSON output that is empty or that contains
JSON object data.""",
body: """
{
"foo": true
}""",
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.0",
},
code: 200,
// Service implementations must ignore this test.
appliesTo: "client"
},
{
id: "AwsJson10ServiceRespondsWithNoPayload",
protocol: awsJson1_0,
documentation: """
When no output is defined, the service is expected to return
an empty payload. Despite the lack of a payload, the service
is expected to always send a Content-Type header. Clients must
handle cases where a service returns a JSON object and where
a service returns no JSON at all.""",
body: "",
headers: {
"Content-Type": "application/x-amz-json-1.0",
},
code: 200
}
])

/// The example tests how requests and responses are serialized when there's
Expand All @@ -51,26 +120,30 @@ operation NoInputAndOutput {
apply NoInputAndOutput @httpRequestTests([
{
id: "AwsJson10NoInputAndOutput",
documentation: "No input serializes no payload",
documentation: "A client should always send and empty JSON object payload.",
protocol: awsJson1_0,
method: "POST",
headers: {
"Content-Type": "application/x-amz-json-1.0",
"X-Amz-Target": "JsonRpc10.NoInputAndOutput",
},
uri: "/"
uri: "/",
body: "{}",
bodyMediaType: "application/json",
}
])

apply NoInputAndOutput @httpResponseTests([
{
id: "AwsJson10NoInputAndOutput",
documentation: "Empty output serializes no payload",
documentation: "Empty output always serializes an empty object payload.",
protocol: awsJson1_0,
headers: {
"Content-Type": "application/x-amz-json-1.0"
},
code: 200
code: 200,
body: "{}",
bodyMediaType: "application/json",
}
])

Expand All @@ -88,37 +161,30 @@ operation EmptyInputAndEmptyOutput {
apply EmptyInputAndEmptyOutput @httpRequestTests([
{
id: "AwsJson10EmptyInputAndEmptyOutput",
documentation: "Empty input serializes no payload",
documentation: "Clients must always send an empty object if input is modeled.",
protocol: awsJson1_0,
method: "POST",
uri: "/",
body: "",
body: "{}",
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.0",
"X-Amz-Target": "JsonRpc10.EmptyInputAndEmptyOutput",
},
bodyMediaType: "application/json"
}
},
])

apply EmptyInputAndEmptyOutput @httpResponseTests([
{
id: "AwsJson10EmptyInputAndEmptyOutput",
documentation: "Empty output serializes no payload",
protocol: awsJson1_0,
code: 200,
body: "",
headers: {"Content-Type": "application/x-amz-json-1.0"},
bodyMediaType: "application/json"
},
{
id: "AwsJson10EmptyInputAndEmptyJsonObjectOutput",
documentation: "Empty output serializes no payload",
id: "AwsJson10EmptyInputAndEmptyOutputSendJsonObject",
documentation: "A service will always return a JSON object for operations with modeled output.",
protocol: awsJson1_0,
code: 200,
body: "{}",
headers: {"Content-Type": "application/x-amz-json-1.0"},
bodyMediaType: "application/json"
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.0"
},
},
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,95 @@ use smithy.test#httpResponseTests
method: "POST",
uri: "/",
},
{
id: "json_1_1_client_sends_empty_payload_for_no_input_shape",
protocol: awsJson1_1,
documentation: """
Clients must always send an empty JSON object payload for
operations with no input (that is, `{}`). While AWS service
implementations support requests with no payload or requests
that send `{}`, always sending `{}` from the client is
preferred for forward compatibility in case input is ever
added to an operation.""",
body: "{}",
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.1",
},
method: "POST",
uri: "/"
},
{
id: "json_1_1_service_supports_empty_payload_for_no_input_shape",
protocol: awsJson1_1,
documentation: """
Service implementations must support no payload or an empty
object payload for operations that define no input. However,
despite the lack of a payload, a Content-Type header is still
required in order for the service to properly detect the
protocol.""",
body: "",
headers: {
"Content-Type": "application/x-amz-json-1.1",
},
method: "POST",
uri: "/",
// Client implementations must ignore this test.
appliesTo: "server"
},
])
@httpResponseTests([
{
id: "handles_empty_output_shape",
protocol: awsJson1_1,
documentation: "Handles empty output shapes",
documentation: """
When no output is defined, the service is expected to return
an empty payload, however, client must ignore a JSON payload
if one is returned. This ensures that if output is added later,
then it will not break the client.""",
body: "{}",
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.1",
},
code: 200,
// Service implementations must ignore this test.
appliesTo: "client"
},
{
id: "handles_unexpected_json_output",
protocol: awsJson1_1,
documentation: """
This client-only test builds on handles_empty_output_shape,
by including unexpected fields in the JSON. A client
needs to ignore JSON output that is empty or that contains
JSON object data.""",
body: """
{
"foo": true
}""",
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.1",
},
code: 200,
// Service implementations must ignore this test.
appliesTo: "client"
},
{
id: "json_1_1_service_responds_with_no_payload",
protocol: awsJson1_1,
documentation: """
When no output is defined, the service is expected to return
an empty payload. Despite the lack of a payload, the service
is expected to always send a Content-Type header. Clients must
handle cases where a service returns a JSON object and where
a service returns no JSON at all.""",
body: "",
headers: {
"Content-Type": "application/x-amz-json-1.1",
},
code: 200
},
])
operation EmptyOperation {}
Loading