Skip to content

Commit

Permalink
Add protocol tests for default values for awsJson1_0
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFossAWS committed Oct 11, 2023
1 parent 428c8a1 commit 3a778f5
Show file tree
Hide file tree
Showing 4 changed files with 949 additions and 1 deletion.
342 changes: 342 additions & 0 deletions smithy-aws-protocol-tests/model/awsJson1_0/defaults.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,342 @@
$version: "2.0"

namespace aws.protocoltests.json10

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

apply OperationWithDefaults @httpRequestTests([
{
id: "AwsJson10ClientPopulatesDefaultValuesInOutputWhenMissing"
documentation: "Client populates default values in output when missing."
appliesTo: "client"
tags: ["defaults"]
protocol: awsJson1_0
method: "POST"
bodyMediaType: "application/json"
uri: "/"
headers: {"Content-Type": "application/x-amz-json-1.0"}
body: """
{
"defaults": {
"defaultString": "hi",
"defaultBoolean": true,
"defaultList": [],
"defaultDocumentMap": {},
"defaultDocumentString": "hi",
"defaultDocumentBoolean": true,
"defaultDocumentList": [],
"defaultNullDocument": null,
"defaultTimestamp": 0,
"defaultBlob": "{}",
"defaultByte": 1,
"defaultShort": 1,
"defaultInteger": 10,
"defaultLong": 100,
"defaultFloat": 0,
"defaultDouble": 0,
"defaultMap": {},
"defaultBigInteger": 0,
"defaultBigDecimal": 0,
"defaultEnum": "FOO",
"defaultIntEnum": 1
}
}"""
params: {
defaults: {}
}
}
{
id: "AwsJson10ClientUsesExplicitlyProvidedMemberValuesOverDefaults"
documentation: "Client uses explicitly provided member values over defaults"
appliesTo: "client"
tags: ["defaults"]
protocol: awsJson1_0
method: "POST"
bodyMediaType: "application/json"
uri: "/"
headers: {"Content-Type": "application/x-amz-json-1.0"}
params: {
defaults: {
defaultString: "bye"
defaultBoolean: false
defaultList: ["a"]
defaultDocumentMap: {name: "Jack"}
defaultDocumentString: "bye"
defaultDocumentBoolean: false
defaultDocumentList: ["b"]
defaultNullDocument: "notNull"
defaultTimestamp: 1
defaultBlob: "abc"
defaultByte: 2
defaultShort: 2
defaultInteger: 20
defaultLong: 200
defaultFloat: 1
defaultDouble: 1
defaultMap: {name: "Jack"}
defaultBigInteger: 1
defaultBigDecimal: 1
defaultEnum: "BAR"
defaultIntEnum: 2
}
}
body: """
{
"defaults": {
"defaultString": "bye",
"defaultBoolean": false,
"defaultList": ["a"],
"defaultDocumentMap": {"name": "Jack"},
"defaultDocumentString": "bye",
"defaultDocumentBoolean": false,
"defaultDocumentList": ["b"],
"defaultNullDocument": "notNull",
"defaultTimestamp": 1,
"defaultBlob": "abc",
"defaultByte": 2,
"defaultShort": 2,
"defaultInteger": 20,
"defaultLong": 200,
"defaultFloat": 1,
"defaultDouble": 1,
"defaultMap": {"name": "Jack"},
"defaultBigInteger": 1,
"defaultBigDecimal": 1,
"defaultEnum": "BAR",
"defaultIntEnum": 2
}
}"""
}
{
id: "AwsJson10ServerPopulatesDefaultsWhenMissingInRequestBody"
documentation: "Server populates default values when missing in request body."
appliesTo: "server"
tags: ["defaults"]
protocol: awsJson1_0
method: "POST"
bodyMediaType: "application/json"
uri: "/"
headers: {"Content-Type": "application/x-amz-json-1.0"}
body: """
{
"defaults": {}
}"""
params: {
defaults: {
defaultString: "hi"
defaultBoolean: true
defaultList: []
defaultDocumentMap: {}
defaultDocumentString: "hi"
defaultDocumentBoolean: true
defaultDocumentList: []
defaultNullDocument: null
defaultTimestamp: 0
defaultBlob: "{}"
defaultByte: 1
defaultShort: 1
defaultInteger: 10
defaultLong: 100
defaultFloat: 0
defaultDouble: 0
defaultMap: {}
defaultBigInteger: 0
defaultBigDecimal: 0
defaultEnum: "FOO"
defaultIntEnum: 1
}
}
}
])

apply OperationWithDefaults @httpResponseTests([
{
id: "AwsJson10ClientPopulatesDefaultsValuesWhenMissingInResponse"
documentation: "Client populates default values when missing in response."
appliesTo: "client"
tags: ["defaults"]
protocol: awsJson1_0
code: 200
bodyMediaType: "application/json"
headers: {"Content-Type": "application/x-amz-json-1.0"}
body: "{}"
params: {
defaultString: "hi"
defaultBoolean: true
defaultList: []
defaultDocumentMap: {}
defaultDocumentString: "hi"
defaultDocumentBoolean: true
defaultDocumentList: []
defaultNullDocument: null
defaultTimestamp: 0
defaultBlob: "{}"
defaultByte: 1
defaultShort: 1
defaultInteger: 10
defaultLong: 100
defaultFloat: 0
defaultDouble: 0
defaultMap: {}
defaultBigInteger: 0
defaultBigDecimal: 0
defaultEnum: "FOO"
defaultIntEnum: 1
}
}
{
id: "AwsJson10ClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse"
documentation: "Client ignores default values if member values are present in the response."
appliesTo: "client"
tags: ["defaults"]
protocol: awsJson1_0
code: 200
bodyMediaType: "application/json"
headers: {"Content-Type": "application/x-amz-json-1.0"}
body: """
{
"defaultString": "bye",
"defaultBoolean": false,
"defaultList": ["a"],
"defaultDocumentMap": {"name": "Jack"},
"defaultDocumentString": "bye",
"defaultDocumentBoolean": false,
"defaultDocumentList": ["b"],
"defaultNullDocument": "notNull",
"defaultTimestamp": 1,
"defaultBlob": "abc",
"defaultByte": 2,
"defaultShort": 2,
"defaultInteger": 20,
"defaultLong": 200,
"defaultFloat": 1,
"defaultDouble": 1,
"defaultMap": {"name": "Jack"},
"defaultBigInteger": 1,
"defaultBigDecimal": 1,
"defaultEnum": "BAR",
"defaultIntEnum": 2
}"""
params: {
defaultString: "bye"
defaultBoolean: false
defaultList: ["a"]
defaultDocumentMap: {name: "Jack"}
defaultDocumentString: "bye"
defaultDocumentBoolean: false
defaultDocumentList: ["b"]
defaultNullDocument: "notNull"
defaultTimestamp: 1
defaultBlob: "abc"
defaultByte: 2
defaultShort: 2
defaultInteger: 20
defaultLong: 200
defaultFloat: 1
defaultDouble: 1
defaultMap: {name: "Jack"}
defaultBigInteger: 1
defaultBigDecimal: 1
defaultEnum: "BAR"
defaultIntEnum: 2
}
}
{
id: "AwsJson10ServerPopulatesDefaultsInResponseWhenMissingInParams"
documentation: "Server populates default values in response when missing in params."
appliesTo: "server"
tags: ["defaults"]
protocol: awsJson1_0
code: 200
bodyMediaType: "application/json"
headers: {"Content-Type": "application/x-amz-json-1.0"}
body: """
{
"defaultString": "hi",
"defaultBoolean": true,
"defaultList": [],
"defaultDocumentMap": {},
"defaultDocumentString": "hi",
"defaultDocumentBoolean": true,
"defaultDocumentList": [],
"defaultNullDocument": null,
"defaultTimestamp": 0,
"defaultBlob": "{}",
"defaultByte": 1,
"defaultShort": 1,
"defaultInteger": 10,
"defaultLong": 100,
"defaultFloat": 0,
"defaultDouble": 0,
"defaultMap": {},
"defaultBigInteger": 0,
"defaultBigDecimal": 0,
"defaultEnum": "FOO",
"defaultIntEnum": 1
}"""
params: {
}
}
])

operation OperationWithDefaults {
input := {
@required
defaults: Defaults

topLevelDefault: String = "hi" // Client should ignore default values in input shape
}

output := with [DefaultsMixin] {
}
}

structure Defaults with [DefaultsMixin] {
}

@mixin
structure DefaultsMixin {
defaultString: String = "hi"
defaultBoolean: Boolean = true
defaultList: TestStringList = []
defaultDocumentMap: Document = {}
defaultDocumentString: Document = "hi"
defaultDocumentBoolean: Document = true
defaultDocumentList: Document = []
defaultNullDocument: Document = null
defaultTimestamp: Timestamp = 0
defaultBlob: Blob = "{}"
defaultByte: Byte = 1
defaultShort: Short = 1
defaultInteger: Integer = 10
defaultLong: Long = 100
defaultFloat: Float = 0
defaultDouble: Double = 0
defaultMap: TestStringMap = {}
defaultBigInteger: BigInteger = 0
defaultBigDecimal: BigDecimal = 0
defaultEnum: TestEnum = "FOO"
defaultIntEnum: TestIntEnum = 1
}

list TestStringList {
member: String
}

map TestStringMap {
key: String
value: String
}

enum TestEnum {
FOO
BAR
BAZ
}

intEnum TestIntEnum {
ONE = 1
TWO = 2
}
6 changes: 5 additions & 1 deletion smithy-aws-protocol-tests/model/awsJson1_0/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ service JsonRpc10 {
HostWithPathOperation,

// requestCompression trait tests
PutWithContentEncoding
PutWithContentEncoding,

OperationWithDefaults,
OperationWithRequiredMembers,
OperationWithNestedStructure
]
}
Loading

0 comments on commit 3a778f5

Please sign in to comment.