From 65bdb4e3fb63454b30ee33096ded2c1a9c963350 Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Thu, 29 Jun 2023 13:23:51 -0400 Subject: [PATCH] fix header serialization of empty enum lists in restxml --- CHANGELOG_PENDING.md | 2 ++ private/protocol/rest/build.go | 4 ++++ private/protocol/rest/build_test.go | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 8a1927a39ca..44916363a31 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -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. diff --git a/private/protocol/rest/build.go b/private/protocol/rest/build.go index 1d273ff0ec6..ecc521f88f1 100644 --- a/private/protocol/rest/build.go +++ b/private/protocol/rest/build.go @@ -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 { diff --git a/private/protocol/rest/build_test.go b/private/protocol/rest/build_test.go index 5b48482bc7d..4760e683721 100644 --- a/private/protocol/rest/build_test.go +++ b/private/protocol/rest/build_test.go @@ -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 {