Skip to content

Commit

Permalink
feat(codegen): add protocol tests for client side error correction
Browse files Browse the repository at this point in the history
  • Loading branch information
aajtodd committed Sep 25, 2023
1 parent 7b5747a commit 8a8aa01
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
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>"
}
])

0 comments on commit 8a8aa01

Please sign in to comment.