Skip to content

Commit

Permalink
Merge pull request #4898 from aws/fix-restxml-emptyheaderlist
Browse files Browse the repository at this point in the history
fix header serialization of empty enum lists in restxml
  • Loading branch information
lucix-aws committed Jun 29, 2023
2 parents 8edbac8 + 65bdb4e commit 2144988
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
### SDK Enhancements

### SDK Bugs
* `private/protocol`: Fix header serialization of empty enum lists in restxml.
* Header was serialized as the empty string if list was nil/empty.
4 changes: 4 additions & 0 deletions private/protocol/rest/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ func convertType(v reflect.Value, tag reflect.StructTag) (str string, err error)
if tag.Get("location") != "header" || tag.Get("enum") == "" {
return "", fmt.Errorf("%T is only supported with location header and enum shapes", value)
}
if len(value) == 0 {
return "", errValueNotSet
}

buff := &bytes.Buffer{}
for i, sv := range value {
if sv == nil || len(*sv) == 0 {
Expand Down
22 changes: 22 additions & 0 deletions private/protocol/rest/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ func TestListOfEnums(t *testing.T) {
"X-Amz-Test-Header": {`"f,o,o","\"bar\""`},
},
},
{
Input: func() interface{} {
type v struct {
List []*string `type:"list" location:"header" locationName:"x-amz-test-header" enum:"FooBar"`
}
return &v{
List: nil,
}
}(),
Expected: http.Header{},
},
{
Input: func() interface{} {
type v struct {
List []*string `type:"list" location:"header" locationName:"x-amz-test-header" enum:"FooBar"`
}
return &v{
List: []*string{},
}
}(),
Expected: http.Header{},
},
}

for i, tt := range cases {
Expand Down

0 comments on commit 2144988

Please sign in to comment.