Skip to content

Commit

Permalink
dependency: upgrade smithy to 1.27.2 and correct query empty list ser…
Browse files Browse the repository at this point in the history
…ialization
  • Loading branch information
lucix-aws committed Feb 2, 2023
1 parent 0d94f22 commit bd3003e
Show file tree
Hide file tree
Showing 103 changed files with 7,147 additions and 1,770 deletions.
31 changes: 31 additions & 0 deletions .changelog/c3a62c73ab624737a829d8c85167835e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "c3a62c73-ab62-4737-a829-d8c85167835e",
"type": "dependency",
"description": "Upgrade smithy to 1.27.2 and correct empty query list serialization.",
"modules": [
"internal/protocoltest/awsrestjson",
"internal/protocoltest/ec2query",
"internal/protocoltest/jsonrpc",
"internal/protocoltest/jsonrpc10",
"internal/protocoltest/query",
"internal/protocoltest/restxml",
"service/autoscaling",
"service/cloudformation",
"service/cloudsearch",
"service/cloudwatch",
"service/docdb",
"service/ec2",
"service/elasticache",
"service/elasticbeanstalk",
"service/elasticloadbalancing",
"service/elasticloadbalancingv2",
"service/iam",
"service/neptune",
"service/rds",
"service/redshift",
"service/ses",
"service/sns",
"service/sqs",
"service/sts"
]
}
11 changes: 11 additions & 0 deletions aws/protocol/query/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,31 @@ type Array struct {
memberName string
// Elements are stored in values, so we keep track of the list size here.
size int32
// Empty lists are encoded as "<prefix>=", if we add a value later we will
// remove this encoding
emptyValue Value
}

func newArray(values url.Values, prefix string, flat bool, memberName string) *Array {
emptyValue := newValue(values, prefix, flat)
emptyValue.String("")

return &Array{
values: values,
prefix: prefix,
flat: flat,
memberName: memberName,
emptyValue: emptyValue,
}
}

// Value adds a new element to the Query Array. Returns a Value type used to
// encode the array element.
func (a *Array) Value() Value {
if a.size == 0 {
delete(a.values, a.emptyValue.key)
}

// Query lists start a 1, so adjust the size first
a.size++
prefix := a.prefix
Expand Down
17 changes: 16 additions & 1 deletion aws/protocol/query/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package query
import (
"bytes"
"fmt"
smithytesting "github.com/aws/smithy-go/testing"
"testing"

smithytesting "github.com/aws/smithy-go/testing"
)

func TestEncode(t *testing.T) {
Expand Down Expand Up @@ -35,6 +36,13 @@ func TestEncode(t *testing.T) {
},
Expect: []byte(`list.spam.1=spam&list.spam.2=eggs`),
},
"empty list": {
Encode: func(e *Encoder) error {
e.Object().Key("list").Array("spam")
return e.Encode()
},
Expect: []byte(`list=`),
},
"flat list": {
Encode: func(e *Encoder) error {
list := e.Object().FlatKey("list").Array("spam")
Expand All @@ -44,6 +52,13 @@ func TestEncode(t *testing.T) {
},
Expect: []byte(`list.1=spam&list.2=eggs`),
},
"empty flat list": {
Encode: func(e *Encoder) error {
e.Object().FlatKey("list").Array("spam")
return e.Encode()
},
Expect: []byte(`list=`),
},
"map": {
Encode: func(e *Encoder) error {
mapValue := e.Object().Key("map").Map("key", "value")
Expand Down
2 changes: 1 addition & 1 deletion codegen/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
smithyVersion=1.25.2
smithyVersion=1.27.2
smithyGradleVersion=0.6.0
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ protected void serializeCollection(GenerationContext context, CollectionShape sh
MemberShape member = shape.getMember();
Shape target = context.getModel().expectShape(member.getTarget());

// If the list is empty, exit early to avoid extra effort.
writer.write("if len(v) == 0 { return nil }");

writer.write("array := value.Array($S)", getSerializedLocationName(member, "member"));
writer.write("");

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions internal/protocoltest/awsrestjson/api_op_DatetimeOffsets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bd3003e

Please sign in to comment.