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 error protocol tests for json rpc #484

Merged
merged 1 commit into from
Jul 7, 2020
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
239 changes: 239 additions & 0 deletions smithy-aws-protocol-tests/model/awsJson1_1/errors.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
// This file defines test cases that test error serialization.

$version: "1.0"

namespace aws.protocoltests.json

use aws.protocols#awsJson1_1
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

/// This operation has three possible return values:
///
/// 1. A successful response in the form of GreetingWithErrorsOutput
/// 2. An InvalidGreeting error.
/// 3. A ComplexError error.
///
/// Implementations must be able to successfully take a response and
/// properly deserialize successful and error responses.
@idempotent
operation GreetingWithErrors {
output: GreetingWithErrorsOutput,
errors: [InvalidGreeting, ComplexError, FooError]
}

structure GreetingWithErrorsOutput {
greeting: String,
}

/// This error is thrown when an invalid greeting value is provided.
@error("client")
structure InvalidGreeting {
Message: String,
}

apply InvalidGreeting @httpResponseTests([
{
id: "AwsJson11InvalidGreetingError",
documentation: "Parses simple JSON errors",
protocol: awsJson1_1,
code: 400,
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
body: """
{
"__type": "InvalidGreeting",
"Message": "Hi"
}""",
bodyMediaType: "application/json"
},
])

/// This error is thrown when a request is invalid.
@error("client")
structure ComplexError {
TopLevel: String,
Nested: ComplexNestedErrorData,
}

structure ComplexNestedErrorData {
@jsonName("Fooooo")
Foo: String,
}

apply ComplexError @httpResponseTests([
{
id: "AwsJson11ComplexError",
documentation: "Parses a complex error with no message member",
protocol: awsJson1_1,
code: 400,
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
body: """
{
"__type": "ComplexError",
"TopLevel": "Top level",
"Nested": {
"Fooooo": "bar"
}
}""",
bodyMediaType: "application/json"
},
{
id: "AwsJson11EmptyComplexError",
protocol: awsJson1_1,
code: 400,
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
body: """
{
"__type": "ComplexError"
}""",
bodyMediaType: "application/json"
},
])

/// This error has test cases that test some of the dark corners of Amazon service
/// framework history. It should only be implemented by clients.
@error("server")
@tags(["client-only"])
structure FooError {}

apply FooError @httpResponseTests([
{
id: "AwsJson11FooErrorUsingXAmznErrorType",
documentation: "Serializes the X-Amzn-ErrorType header. For an example service, see Amazon EKS.",
protocol: awsJson1_1,
code: 500,
headers: {
"X-Amzn-Errortype": "FooError",
},
},
{
id: "AwsJson11FooErrorUsingXAmznErrorTypeWithUri",
documentation: """
Some X-Amzn-Errortype headers contain URLs. Clients need to split the URL on ':' and take \
only the first half of the string. For example, 'ValidationException:http://internal.amazon.com/coral/com.amazon.coral.validate/'
is to be interpreted as 'ValidationException'.

For an example service see Amazon Polly.""",
protocol: awsJson1_1,
code: 500,
headers: {
"X-Amzn-Errortype": "FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/",
},
},
{
id: "AwsJson11FooErrorUsingXAmznErrorTypeWithUriAndNamespace",
documentation: """
X-Amzn-Errortype might contain a URL and a namespace. Client should extract only the shape \
name. This is a pathalogical case that might not actually happen in any deployed AWS service.""",
protocol: awsJson1_1,
code: 500,
headers: {
"X-Amzn-Errortype": "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/",
},
},
{
id: "AwsJson11FooErrorUsingCode",
documentation: """
This example uses the 'code' property in the output rather than X-Amzn-Errortype. Some \
services do this though it's preferable to send the X-Amzn-Errortype. Client implementations \
must first check for the X-Amzn-Errortype and then check for a top-level 'code' property.

For example service see Amazon S3 Glacier.""",
protocol: awsJson1_1,
code: 500,
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
body: """
{
"code": "FooError"
}""",
bodyMediaType: "application/json",
},
{
id: "AwsJson11FooErrorUsingCodeAndNamespace",
documentation: """
Some services serialize errors using code, and it might contain a namespace. \
Clients should just take the last part of the string after '#'.""",
protocol: awsJson1_1,
code: 500,
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
body: """
{
"code": "aws.protocoltests.restjson#FooError"
}""",
bodyMediaType: "application/json",
},
{
id: "AwsJson11FooErrorUsingCodeUriAndNamespace",
documentation: """
Some services serialize errors using code, and it might contain a namespace. It also might \
contain a URI. Clients should just take the last part of the string after '#' and before ":". \
This is a pathalogical case that might not occur in any deployed AWS service.""",
protocol: awsJson1_1,
code: 500,
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
body: """
{
"code": "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/"
}""",
bodyMediaType: "application/json",
},
{
id: "AwsJson11FooErrorWithDunderType",
documentation: "Some services serialize errors using __type.",
protocol: awsJson1_1,
code: 500,
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
body: """
{
"__type": "FooError"
}""",
bodyMediaType: "application/json",
},
{
id: "AwsJson11FooErrorWithDunderTypeAndNamespace",
documentation: """
Some services serialize errors using __type, and it might contain a namespace. \
Clients should just take the last part of the string after '#'.""",
protocol: awsJson1_1,
code: 500,
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
body: """
{
"__type": "aws.protocoltests.restjson#FooError"
}""",
bodyMediaType: "application/json",
},
{
id: "AwsJson11FooErrorWithDunderTypeUriAndNamespace",
documentation: """
Some services serialize errors using __type, and it might contain a namespace. It also might \
contain a URI. Clients should just take the last part of the string after '#' and before ":". \
This is a pathalogical case that might not occur in any deployed AWS service.""",
protocol: awsJson1_1,
code: 500,
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
body: """
{
"__type": "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/"
}""",
bodyMediaType: "application/json",
}
])
1 change: 1 addition & 0 deletions smithy-aws-protocol-tests/model/awsJson1_1/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ service JsonProtocol {
PutAndGetInlineDocuments,
JsonEnums,
NullOperation,
GreetingWithErrors,
],
}

Expand Down