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

feat(codegen): add protocol tests for client side error correction #1051

Merged
merged 1 commit into from
Sep 26, 2023
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
4 changes: 4 additions & 0 deletions codegen/protocol-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ val enabledProtocols = listOf(
ProtocolTest("apigateway", "com.amazonaws.apigateway#BackplaneControlService"),
ProtocolTest("glacier", "com.amazonaws.glacier#Glacier"),
ProtocolTest("machinelearning", "com.amazonaws.machinelearning#AmazonML_20141212", sdkId = "Machine Learning"),

// Custom hand written tests
ProtocolTest("error-correction-json", "aws.protocoltests.errorcorrection#RequiredValueJson"),
ProtocolTest("error-correction-xml", "aws.protocoltests.errorcorrection#RequiredValueXml"),
)

codegen {
Expand Down
156 changes: 156 additions & 0 deletions codegen/protocol-tests/model/error-correction-tests.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
$version: "2.0"

namespace aws.protocoltests.errorcorrection

use aws.api#service
use aws.protocols#awsJson1_0
use aws.protocols#restXml
use smithy.test#httpResponseTests

@service(sdkId: "Error Correction Json")
@awsJson1_0
service RequiredValueJson {
operations: [SayHello],
version: "1"
}


@service(sdkId: "Error Correction Xml")
@restXml
service RequiredValueXml {
operations: [SayHelloXml],
version: "1"
}

@error("client")
structure Error {
@required
requestId: String

@required
message: String
}

@http(method: "POST", uri: "/")
operation SayHello { output: TestOutputDocument, errors: [Error] }

@http(method: "POST", uri: "/")
operation SayHelloXml { output: TestOutput, errors: [Error] }

structure TestOutputDocument with [TestStruct] { innerField: Nested, @required document: Document }
structure TestOutput with [TestStruct] { innerField: Nested }

@mixin
structure TestStruct {
@required
foo: String,

@required
byteValue: Byte,

@required
intValue: Integer,

@required
listValue: StringList,

@required
mapValue: ListMap,

@required
nestedListValue: NestedList

@required
nested: Nested

@required
blob: Blob

@required
enum: MyEnum

@required
union: MyUnion

notRequired: String

@required
timestampValue: Timestamp
}

enum MyEnum {
A,
B,
C
}

union MyUnion {
A: Integer,
B: String,
C: Unit
}

structure Nested {
@required
a: String
}

list StringList {
member: String
}

list NestedList {
member: StringList
}

map ListMap {
key: String,
value: StringList
}

// NOTE: there is no way to model enum or union defaults in an `httpResponseTest` because the default is the generated
// "SdkUnknown" variant.
apply SayHello @httpResponseTests([
{
id: "error_recovery_json",
protocol: awsJson1_0,
params: {
union: { A: 5 },
enum: "A",
foo: "",
byteValue: 0,
intValue: 0,
blob: "",
listValue: [],
mapValue: {},
nestedListValue: [],
document: null,
nested: { a: "" },
timestampValue: 0
},
code: 200,
body: "{\"union\": { \"A\": 5 }, \"enum\": \"A\" }"
}
])

apply SayHelloXml @httpResponseTests([
{
id: "error_recovery_xml",
protocol: restXml,
params: {
union: { A: 5 },
enum: "A",
foo: "",
byteValue: 0,
intValue: 0,
blob: "",
listValue: [],
mapValue: {},
nestedListValue: [],
nested: { a: "" },
timestampValue: 0
},
code: 200,
body: "<TestOutput><union><A>5</A></union><enum>A</enum></TestOutput>"
}
])
Loading