Skip to content

Commit

Permalink
Smithy 1.26.2 upgrade / ensure that even empty lists are serialized (#…
Browse files Browse the repository at this point in the history
…1972)

* Ensure that even empty lists are serialized

* Add must_use annotation & unit test

* Add changelog entry

* Remove test from list of failing tests
  • Loading branch information
rcoh authored Nov 10, 2022
1 parent 4f76e35 commit 16d212e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ references = ["smithy-rs#1935"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[smithy-rs]]
message = "Upgrade to Smithy 1.26.2"
references = ["smithy-rs#1972"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "rcoh"
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,6 @@ class ServerProtocolTestGenerator(
private val ExpectFail: Set<FailingTest> = setOf(
// Pending merge from the Smithy team: see https://github.com/awslabs/smithy/pull/1477.
FailingTest(RestJson, "RestJsonWithPayloadExpectsImpliedContentType", TestType.MalformedRequest),
FailingTest(RestJson, "RestJsonBodyMalformedMapNullKey", TestType.MalformedRequest),

// Pending resolution from the Smithy team, see https://github.com/awslabs/smithy/issues/1068.
FailingTest(RestJson, "RestJsonHttpWithHeadersButNoPayload", TestType.Request),
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ kotlin.code.style=official

# codegen
smithyGradlePluginVersion=0.6.0
smithyVersion=1.26.0
smithyVersion=1.26.2

# kotlin
kotlinVersion=1.6.21
Expand Down
18 changes: 17 additions & 1 deletion rust-runtime/aws-smithy-query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl<'a> QueryWriter<'a> {
}
}

#[must_use]
pub struct QueryMapWriter<'a> {
output: &'a mut String,
prefix: Cow<'a, str>,
Expand Down Expand Up @@ -89,6 +90,7 @@ impl<'a> QueryMapWriter<'a> {
}
}

#[must_use]
pub struct QueryListWriter<'a> {
output: &'a mut String,
prefix: Cow<'a, str>,
Expand Down Expand Up @@ -132,10 +134,15 @@ impl<'a> QueryListWriter<'a> {
}

pub fn finish(self) {
// Calling this drops self
// https://github.com/awslabs/smithy/commit/715b1d94ab14764ad43496b016b0c2e85bcf1d1f
// If the list was empty, just serialize the parameter name
if self.next_index == 1 {
QueryValueWriter::new(self.output, self.prefix).write_param_name();
}
}
}

#[must_use]
pub struct QueryValueWriter<'a> {
output: &'a mut String,
prefix: Cow<'a, str>,
Expand Down Expand Up @@ -229,6 +236,15 @@ mod tests {
assert_eq!("Action=SomeAction&Version=1.0", out);
}

#[test]
fn query_list_writer_empty_list() {
let mut out = String::new();
let mut writer = QueryWriter::new(&mut out, "SomeAction", "1.0");
writer.prefix("myList").start_list(false, None).finish();
writer.finish();
assert_eq!("Action=SomeAction&Version=1.0&myList=", out);
}

#[test]
fn maps() {
let mut out = String::new();
Expand Down

0 comments on commit 16d212e

Please sign in to comment.