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

Update json protocol tests #473

Merged
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
106 changes: 106 additions & 0 deletions smithy-aws-protocol-tests/model/awsJson1_1/enums.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
$version: "1.0"

namespace aws.protocoltests.json

use aws.protocols#awsJson1_1
use aws.protocoltests.shared#FooEnum
use aws.protocoltests.shared#FooEnumList
use aws.protocoltests.shared#FooEnumSet
use aws.protocoltests.shared#FooEnumMap
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

/// This example serializes enums as top level properties, in lists, sets, and maps.
@idempotent
operation JsonEnums {
input: JsonEnumsInputOutput,
output: JsonEnumsInputOutput
}

apply JsonEnums @httpRequestTests([
{
id: "AwsJson11Enums",
documentation: "Serializes simple scalar properties",
protocol: awsJson1_1,
method: "POST",
uri: "/",
body: """
{
"fooEnum1": "Foo",
"fooEnum2": "0",
"fooEnum3": "1",
"fooEnumList": [
"Foo",
"0"
],
"fooEnumSet": [
"Foo",
"0"
],
"fooEnumMap": {
"hi": "Foo",
"zero": "0"
}
}""",
bodyMediaType: "application/json",
params: {
fooEnum1: "Foo",
fooEnum2: "0",
fooEnum3: "1",
fooEnumList: ["Foo", "0"],
fooEnumSet: ["Foo", "0"],
fooEnumMap: {
"hi": "Foo",
"zero": "0"
}
}
}
])

apply JsonEnums @httpResponseTests([
{
id: "AwsJson11Enums",
documentation: "Serializes simple scalar properties",
protocol: awsJson1_1,
code: 200,
body: """
{
"fooEnum1": "Foo",
"fooEnum2": "0",
"fooEnum3": "1",
"fooEnumList": [
"Foo",
"0"
],
"fooEnumSet": [
"Foo",
"0"
],
"fooEnumMap": {
"hi": "Foo",
"zero": "0"
}
}""",
bodyMediaType: "application/json",
params: {
fooEnum1: "Foo",
fooEnum2: "0",
fooEnum3: "1",
fooEnumList: ["Foo", "0"],
fooEnumSet: ["Foo", "0"],
fooEnumMap: {
"hi": "Foo",
"zero": "0"
}
}
}
])

structure JsonEnumsInputOutput {
fooEnum1: FooEnum,
fooEnum2: FooEnum,
fooEnum3: FooEnum,
fooEnumList: FooEnumList,
fooEnumSet: FooEnumSet,
fooEnumMap: FooEnumMap,
}
Original file line number Diff line number Diff line change
@@ -545,21 +545,21 @@ use smithy.test#httpResponseTests
id: "parses_iso8601_timestamps",
protocol: awsJson1_1,
documentation: "Parses iso8601 timestamps",
body: "{\"Timestamp\":\"2000-01-02T20:34:56.000Z\"}",
body: "{\"Iso8601Timestamp\":\"2000-01-02T20:34:56.000Z\"}",
bodyMediaType: "application/json",
params: {
Timestamp: 946845296,
Iso8601Timestamp: 946845296,
},
code: 200,
},
{
id: "parses_httpdate_timestamps",
protocol: awsJson1_1,
documentation: "Parses httpdate timestamps",
body: "{\"Timestamp\":\"Sun, 02 Jan 2000 20:34:56.000 GMT\"}",
body: "{\"HttpdateTimestamp\":\"Sun, 02 Jan 2000 20:34:56.000 GMT\"}",
bodyMediaType: "application/json",
params: {
Timestamp: 946845296,
HttpdateTimestamp: 946845296,
},
code: 200,
},
4 changes: 3 additions & 1 deletion smithy-aws-protocol-tests/model/awsJson1_1/main.smithy
Original file line number Diff line number Diff line change
@@ -23,7 +23,9 @@ service JsonProtocol {
EmptyOperation,
KitchenSinkOperation,
OperationWithOptionalInputOutput,
PutAndGetInlineDocuments
PutAndGetInlineDocuments,
JsonEnums,
NullOperation,
],
}

118 changes: 118 additions & 0 deletions smithy-aws-protocol-tests/model/awsJson1_1/null.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
$version: "1.0"

namespace aws.protocoltests.json

use aws.protocols#awsJson1_1
use aws.protocoltests.shared#StringList
use aws.protocoltests.shared#StringMap
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

@httpRequestTests([
{
id: "AwsJson11StructuresDontSerializeNullValues",
documentation: "Null structure values are dropped",
protocol: awsJson1_1,
body: "{}",
bodyMediaType: "application/json",
params: {
string: null
},
method: "POST",
uri: "/",
},
{
id: "AwsJson11MapsSerializeNullValues",
documentation: "Serializes null values in maps",
protocol: awsJson1_1,
body: """
{
"stringMap": {
"foo": null
}
}""",
bodyMediaType: "application/json",
params: {
stringMap: {
"foo": null
}
},
method: "POST",
uri: "/",
},
{
id: "AwsJson11ListsSerializeNull",
documentation: "Serializes null values in lists",
protocol: awsJson1_1,
body: """
{
"stringList": [
null
]
}""",
bodyMediaType: "application/json",
params: {
stringList: [null]
},
method: "POST",
uri: "/",
}
])
@httpResponseTests([
{
id: "AwsJson11StructuresDontDeserializeNullValues",
documentation: "Null structure values are dropped",
protocol: awsJson1_1,
code: 200,
body: """
{
"string": null
}""",
bodyMediaType: "application/json",
params: {},
},
{
id: "AwsJson11MapsDeserializeNullValues",
documentation: "Deserializes null values in maps",
protocol: awsJson1_1,
code: 200,
body: """
{
"stringMap": {
"foo": null
}
}""",
bodyMediaType: "application/json",
params: {
stringMap: {
"foo": null
}
},
},
{
id: "AwsJson11ListsDeserializeNull",
documentation: "Deserializes null values in lists",
protocol: awsJson1_1,
code: 200,
body: """
{
"stringList": [
null
]
}""",
bodyMediaType: "application/json",
params: {
stringList: [null]
},
}
])
operation NullOperation {
input: NullOperationInputOutput,
output: NullOperationInputOutput,
}

structure NullOperationInputOutput {
string: String,
stringList: StringList,
stringMap: StringMap,
}
49 changes: 46 additions & 3 deletions smithy-aws-protocol-tests/model/restJson1/json-maps.smithy
Original file line number Diff line number Diff line change
@@ -49,13 +49,35 @@ apply JsonMaps @httpRequestTests([
}
}
}
}
},
{
id: "RestJsonSerializesNullMapValues",
documentation: "Serializes null JSON map values",
protocol: restJson1,
method: "POST",
uri: "/JsonMaps",
body: """
{
"myMap": {
"foo": null
}
}""",
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/json"
},
params: {
myMap: {
"foo": null
}
}
},
])

apply JsonMaps @httpResponseTests([
{
id: "RestJsonJsonMaps",
documentation: "Serializes JSON maps",
documentation: "Deserializes JSON maps",
protocol: restJson1,
code: 200,
body: """
@@ -83,7 +105,28 @@ apply JsonMaps @httpResponseTests([
}
}
}
}
},
{
id: "RestJsonDeserializesNullMapValues",
documentation: "Deserializes null JSON map values",
protocol: restJson1,
code: 200,
body: """
{
"myMap": {
"foo": null
}
}""",
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/json"
},
params: {
myMap: {
"foo": null
}
}
},
])

structure JsonMapsInputOutput {
32 changes: 30 additions & 2 deletions smithy-aws-protocol-tests/model/restJson1/json-structs.smithy
Original file line number Diff line number Diff line change
@@ -58,7 +58,21 @@ apply SimpleScalarProperties @httpRequestTests([
floatValue: 5.5,
doubleValue: 6.5,
}
}
},
{
id: "RestJsonDoesntSerializeNullStructureValues",
documentation: "Rest Json should not serialize null structure values",
protocol: restJson1,
method: "PUT",
uri: "/SimpleScalarProperties",
body: "{}",
headers: {
"Content-Type": "application/json",
},
params: {
stringValue: null
},
},
])

apply SimpleScalarProperties @httpResponseTests([
@@ -96,7 +110,21 @@ apply SimpleScalarProperties @httpResponseTests([
floatValue: 5.5,
doubleValue: 6.5,
}
}
},
{
id: "RestJsonDoesntDeserializeNullStructureValues",
documentation: "Rest Json should not deserialize null structure values",
protocol: restJson1,
code: 200,
body: """
{
"stringValue": null
}""",
headers: {
"Content-Type": "application/json",
},
params: {},
},
])

structure SimpleScalarPropertiesInputOutput {