diff --git a/codegen/gradle.properties b/codegen/gradle.properties index 3e83354c7bf..5de7797920b 100644 --- a/codegen/gradle.properties +++ b/codegen/gradle.properties @@ -1,2 +1,2 @@ -smithyVersion=1.45.0 +smithyVersion=1.47.0 smithyGradleVersion=0.7.0 diff --git a/internal/protocoltest/awsrestjson/api_op_AllQueryStringTypes_test.go b/internal/protocoltest/awsrestjson/api_op_AllQueryStringTypes_test.go index 30c77cd0894..6e59e4b0c04 100644 --- a/internal/protocoltest/awsrestjson/api_op_AllQueryStringTypes_test.go +++ b/internal/protocoltest/awsrestjson/api_op_AllQueryStringTypes_test.go @@ -341,10 +341,10 @@ func TestClient_AllQueryStringTypes_awsRestjson1Serialize(t *testing.T) { QueryInteger: ptr.Int32(0), QueryBoolean: ptr.Bool(false), QueryParamsMapOfStringList: map[string][]string{ - "queryInteger": { + "Integer": { "0", }, - "queryBoolean": { + "Boolean": { "false", }, }, diff --git a/internal/protocoltest/awsrestjson/api_op_JsonLists.go b/internal/protocoltest/awsrestjson/api_op_JsonLists.go index 711a0c1c1d3..68e6cf7a328 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonLists.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonLists.go @@ -45,8 +45,6 @@ type JsonListsInput struct { // A list of lists of strings. NestedStringList [][]string - SparseStringList []*string - StringList []string StringSet []string @@ -70,8 +68,6 @@ type JsonListsOutput struct { // A list of lists of strings. NestedStringList [][]string - SparseStringList []*string - StringList []string StringSet []string diff --git a/internal/protocoltest/awsrestjson/api_op_JsonLists_test.go b/internal/protocoltest/awsrestjson/api_op_JsonLists_test.go index 80e349191df..0ae9ff49686 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonLists_test.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonLists_test.go @@ -168,30 +168,6 @@ func TestClient_JsonLists_awsRestjson1Serialize(t *testing.T) { }`)) }, }, - // Serializes null values in lists - "RestJsonListsSerializeNull": { - Params: &JsonListsInput{ - SparseStringList: []*string{ - nil, - ptr.String("hi"), - }, - }, - ExpectMethod: "PUT", - ExpectURIPath: "/JsonLists", - ExpectQuery: []smithytesting.QueryItem{}, - ExpectHeader: http.Header{ - "Content-Type": []string{"application/json"}, - }, - BodyMediaType: "application/json", - BodyAssert: func(actual io.Reader) error { - return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ - "sparseStringList": [ - null, - "hi" - ] - }`)) - }, - }, } for name, c := range cases { t.Run(name, func(t *testing.T) { @@ -387,26 +363,6 @@ func TestClient_JsonLists_awsRestjson1Deserialize(t *testing.T) { StringList: []string{}, }, }, - // Serializes null values in sparse lists - "RestJsonListsSerializeNull": { - StatusCode: 200, - Header: http.Header{ - "Content-Type": []string{"application/json"}, - }, - BodyMediaType: "application/json", - Body: []byte(`{ - "sparseStringList": [ - null, - "hi" - ] - }`), - ExpectResult: &JsonListsOutput{ - SparseStringList: []*string{ - nil, - ptr.String("hi"), - }, - }, - }, } for name, c := range cases { t.Run(name, func(t *testing.T) { diff --git a/internal/protocoltest/awsrestjson/api_op_JsonMaps.go b/internal/protocoltest/awsrestjson/api_op_JsonMaps.go index 029cf2b7589..fca823a6370 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonMaps.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonMaps.go @@ -38,16 +38,6 @@ type JsonMapsInput struct { DenseStructMap map[string]types.GreetingStruct - SparseBooleanMap map[string]*bool - - SparseNumberMap map[string]*int32 - - SparseSetMap map[string][]string - - SparseStringMap map[string]*string - - SparseStructMap map[string]*types.GreetingStruct - noSmithyDocumentSerde } @@ -62,16 +52,6 @@ type JsonMapsOutput struct { DenseStructMap map[string]types.GreetingStruct - SparseBooleanMap map[string]*bool - - SparseNumberMap map[string]*int32 - - SparseSetMap map[string][]string - - SparseStringMap map[string]*string - - SparseStructMap map[string]*types.GreetingStruct - // Metadata pertaining to the operation's result. ResultMetadata middleware.Metadata diff --git a/internal/protocoltest/awsrestjson/api_op_JsonMaps_test.go b/internal/protocoltest/awsrestjson/api_op_JsonMaps_test.go index 78228a2ea5e..98dd427136c 100644 --- a/internal/protocoltest/awsrestjson/api_op_JsonMaps_test.go +++ b/internal/protocoltest/awsrestjson/api_op_JsonMaps_test.go @@ -47,14 +47,6 @@ func TestClient_JsonMaps_awsRestjson1Serialize(t *testing.T) { Hi: ptr.String("bye"), }, }, - SparseStructMap: map[string]*types.GreetingStruct{ - "foo": { - Hi: ptr.String("there"), - }, - "baz": { - Hi: ptr.String("bye"), - }, - }, }, ExpectMethod: "POST", ExpectURIPath: "/JsonMaps", @@ -72,54 +64,6 @@ func TestClient_JsonMaps_awsRestjson1Serialize(t *testing.T) { "baz": { "hi": "bye" } - }, - "sparseStructMap": { - "foo": { - "hi": "there" - }, - "baz": { - "hi": "bye" - } - } - }`)) - }, - }, - // Serializes JSON map values in sparse maps - "RestJsonSerializesNullMapValues": { - Params: &JsonMapsInput{ - SparseBooleanMap: map[string]*bool{ - "x": nil, - }, - SparseNumberMap: map[string]*int32{ - "x": nil, - }, - SparseStringMap: map[string]*string{ - "x": nil, - }, - SparseStructMap: map[string]*types.GreetingStruct{ - "x": nil, - }, - }, - ExpectMethod: "POST", - ExpectURIPath: "/JsonMaps", - ExpectQuery: []smithytesting.QueryItem{}, - ExpectHeader: http.Header{ - "Content-Type": []string{"application/json"}, - }, - BodyMediaType: "application/json", - BodyAssert: func(actual io.Reader) error { - return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ - "sparseBooleanMap": { - "x": null - }, - "sparseNumberMap": { - "x": null - }, - "sparseStringMap": { - "x": null - }, - "sparseStructMap": { - "x": null } }`)) }, @@ -130,15 +74,9 @@ func TestClient_JsonMaps_awsRestjson1Serialize(t *testing.T) { DenseNumberMap: map[string]int32{ "x": 0, }, - SparseNumberMap: map[string]*int32{ - "x": ptr.Int32(0), - }, DenseBooleanMap: map[string]bool{ "x": false, }, - SparseBooleanMap: map[string]*bool{ - "x": ptr.Bool(false), - }, }, ExpectMethod: "POST", ExpectURIPath: "/JsonMaps", @@ -152,41 +90,8 @@ func TestClient_JsonMaps_awsRestjson1Serialize(t *testing.T) { "denseNumberMap": { "x": 0 }, - "sparseNumberMap": { - "x": 0 - }, "denseBooleanMap": { "x": false - }, - "sparseBooleanMap": { - "x": false - } - }`)) - }, - }, - // A request that contains a sparse map of sets - "RestJsonSerializesSparseSetMap": { - Params: &JsonMapsInput{ - SparseSetMap: map[string][]string{ - "x": {}, - "y": { - "a", - "b", - }, - }, - }, - ExpectMethod: "POST", - ExpectURIPath: "/JsonMaps", - ExpectQuery: []smithytesting.QueryItem{}, - ExpectHeader: http.Header{ - "Content-Type": []string{"application/json"}, - }, - BodyMediaType: "application/json", - BodyAssert: func(actual io.Reader) error { - return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ - "sparseSetMap": { - "x": [], - "y": ["a", "b"] } }`)) }, @@ -218,35 +123,6 @@ func TestClient_JsonMaps_awsRestjson1Serialize(t *testing.T) { }`)) }, }, - // A request that contains a sparse map of sets. - "RestJsonSerializesSparseSetMapAndRetainsNull": { - Params: &JsonMapsInput{ - SparseSetMap: map[string][]string{ - "x": {}, - "y": { - "a", - "b", - }, - "z": nil, - }, - }, - ExpectMethod: "POST", - ExpectURIPath: "/JsonMaps", - ExpectQuery: []smithytesting.QueryItem{}, - ExpectHeader: http.Header{ - "Content-Type": []string{"application/json"}, - }, - BodyMediaType: "application/json", - BodyAssert: func(actual io.Reader) error { - return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ - "sparseSetMap": { - "x": [], - "y": ["a", "b"], - "z": null - } - }`)) - }, - }, } for name, c := range cases { t.Run(name, func(t *testing.T) { @@ -335,15 +211,7 @@ func TestClient_JsonMaps_awsRestjson1Deserialize(t *testing.T) { "baz": { "hi": "bye" } - }, - "sparseStructMap": { - "foo": { - "hi": "there" - }, - "baz": { - "hi": "bye" - } - } + } }`), ExpectResult: &JsonMapsOutput{ DenseStructMap: map[string]types.GreetingStruct{ @@ -354,50 +222,6 @@ func TestClient_JsonMaps_awsRestjson1Deserialize(t *testing.T) { Hi: ptr.String("bye"), }, }, - SparseStructMap: map[string]*types.GreetingStruct{ - "foo": { - Hi: ptr.String("there"), - }, - "baz": { - Hi: ptr.String("bye"), - }, - }, - }, - }, - // Deserializes null JSON map values - "RestJsonDeserializesNullMapValues": { - StatusCode: 200, - Header: http.Header{ - "Content-Type": []string{"application/json"}, - }, - BodyMediaType: "application/json", - Body: []byte(`{ - "sparseBooleanMap": { - "x": null - }, - "sparseNumberMap": { - "x": null - }, - "sparseStringMap": { - "x": null - }, - "sparseStructMap": { - "x": null - } - }`), - ExpectResult: &JsonMapsOutput{ - SparseBooleanMap: map[string]*bool{ - "x": nil, - }, - SparseNumberMap: map[string]*int32{ - "x": nil, - }, - SparseStringMap: map[string]*string{ - "x": nil, - }, - SparseStructMap: map[string]*types.GreetingStruct{ - "x": nil, - }, }, }, // Ensure that 0 and false are sent over the wire in all maps and lists @@ -411,52 +235,17 @@ func TestClient_JsonMaps_awsRestjson1Deserialize(t *testing.T) { "denseNumberMap": { "x": 0 }, - "sparseNumberMap": { - "x": 0 - }, "denseBooleanMap": { "x": false - }, - "sparseBooleanMap": { - "x": false } }`), ExpectResult: &JsonMapsOutput{ DenseNumberMap: map[string]int32{ "x": 0, }, - SparseNumberMap: map[string]*int32{ - "x": ptr.Int32(0), - }, DenseBooleanMap: map[string]bool{ "x": false, }, - SparseBooleanMap: map[string]*bool{ - "x": ptr.Bool(false), - }, - }, - }, - // A response that contains a sparse map of sets - "RestJsonDeserializesSparseSetMap": { - StatusCode: 200, - Header: http.Header{ - "Content-Type": []string{"application/json"}, - }, - BodyMediaType: "application/json", - Body: []byte(`{ - "sparseSetMap": { - "x": [], - "y": ["a", "b"] - } - }`), - ExpectResult: &JsonMapsOutput{ - SparseSetMap: map[string][]string{ - "x": {}, - "y": { - "a", - "b", - }, - }, }, }, // A response that contains a dense map of sets. @@ -482,31 +271,6 @@ func TestClient_JsonMaps_awsRestjson1Deserialize(t *testing.T) { }, }, }, - // A response that contains a sparse map of sets. - "RestJsonDeserializesSparseSetMapAndRetainsNull": { - StatusCode: 200, - Header: http.Header{ - "Content-Type": []string{"application/json"}, - }, - BodyMediaType: "application/json", - Body: []byte(`{ - "sparseSetMap": { - "x": [], - "y": ["a", "b"], - "z": null - } - }`), - ExpectResult: &JsonMapsOutput{ - SparseSetMap: map[string][]string{ - "x": {}, - "y": { - "a", - "b", - }, - "z": nil, - }, - }, - }, // Clients SHOULD tolerate seeing a null value in a dense map, and they SHOULD // drop the null key-value pair. "RestJsonDeserializesDenseSetMapAndSkipsNull": { diff --git a/internal/protocoltest/awsrestjson/api_op_SparseJsonLists.go b/internal/protocoltest/awsrestjson/api_op_SparseJsonLists.go new file mode 100644 index 00000000000..41a12d5bd9f --- /dev/null +++ b/internal/protocoltest/awsrestjson/api_op_SparseJsonLists.go @@ -0,0 +1,125 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package awsrestjson + +import ( + "context" + "fmt" + awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + "github.com/aws/smithy-go/middleware" + smithyhttp "github.com/aws/smithy-go/transport/http" +) + +func (c *Client) SparseJsonLists(ctx context.Context, params *SparseJsonListsInput, optFns ...func(*Options)) (*SparseJsonListsOutput, error) { + if params == nil { + params = &SparseJsonListsInput{} + } + + result, metadata, err := c.invokeOperation(ctx, "SparseJsonLists", params, optFns, c.addOperationSparseJsonListsMiddlewares) + if err != nil { + return nil, err + } + + out := result.(*SparseJsonListsOutput) + out.ResultMetadata = metadata + return out, nil +} + +type SparseJsonListsInput struct { + SparseStringList []*string + + noSmithyDocumentSerde +} + +type SparseJsonListsOutput struct { + SparseStringList []*string + + // Metadata pertaining to the operation's result. + ResultMetadata middleware.Metadata + + noSmithyDocumentSerde +} + +func (c *Client) addOperationSparseJsonListsMiddlewares(stack *middleware.Stack, options Options) (err error) { + if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil { + return err + } + err = stack.Serialize.Add(&awsRestjson1_serializeOpSparseJsonLists{}, middleware.After) + if err != nil { + return err + } + err = stack.Deserialize.Add(&awsRestjson1_deserializeOpSparseJsonLists{}, middleware.After) + if err != nil { + return err + } + if err := addProtocolFinalizerMiddlewares(stack, options, "SparseJsonLists"); err != nil { + return fmt.Errorf("add protocol finalizers: %v", err) + } + + if err = addlegacyEndpointContextSetter(stack, options); err != nil { + return err + } + if err = addSetLoggerMiddleware(stack, options); err != nil { + return err + } + if err = addClientRequestID(stack); err != nil { + return err + } + if err = addComputeContentLength(stack); err != nil { + return err + } + if err = addResolveEndpointMiddleware(stack, options); err != nil { + return err + } + if err = addComputePayloadSHA256(stack); err != nil { + return err + } + if err = addRetry(stack, options); err != nil { + return err + } + if err = addRawResponseToMetadata(stack); err != nil { + return err + } + if err = addRecordResponseTiming(stack); err != nil { + return err + } + if err = addClientUserAgent(stack, options); err != nil { + return err + } + if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { + return err + } + if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { + return err + } + if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil { + return err + } + if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSparseJsonLists(options.Region), middleware.Before); err != nil { + return err + } + if err = addRecursionDetection(stack); err != nil { + return err + } + if err = addRequestIDRetrieverMiddleware(stack); err != nil { + return err + } + if err = addResponseErrorMiddleware(stack); err != nil { + return err + } + if err = addRequestResponseLogging(stack, options); err != nil { + return err + } + if err = addDisableHTTPSMiddleware(stack, options); err != nil { + return err + } + return nil +} + +func newServiceMetadataMiddleware_opSparseJsonLists(region string) *awsmiddleware.RegisterServiceMetadata { + return &awsmiddleware.RegisterServiceMetadata{ + Region: region, + ServiceID: ServiceID, + OperationName: "SparseJsonLists", + } +} diff --git a/internal/protocoltest/awsrestjson/api_op_SparseJsonLists_test.go b/internal/protocoltest/awsrestjson/api_op_SparseJsonLists_test.go new file mode 100644 index 00000000000..83a7747ef44 --- /dev/null +++ b/internal/protocoltest/awsrestjson/api_op_SparseJsonLists_test.go @@ -0,0 +1,212 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package awsrestjson + +import ( + "bytes" + "context" + "github.com/aws/aws-sdk-go-v2/aws" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" + "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" + "github.com/aws/smithy-go/ptr" + smithyrand "github.com/aws/smithy-go/rand" + smithytesting "github.com/aws/smithy-go/testing" + smithyhttp "github.com/aws/smithy-go/transport/http" + "io" + "io/ioutil" + "net/http" + "net/url" + "testing" +) + +func TestClient_SparseJsonLists_awsRestjson1Serialize(t *testing.T) { + cases := map[string]struct { + Params *SparseJsonListsInput + ExpectMethod string + ExpectURIPath string + ExpectQuery []smithytesting.QueryItem + RequireQuery []string + ForbidQuery []string + ExpectHeader http.Header + RequireHeader []string + ForbidHeader []string + Host *url.URL + BodyMediaType string + BodyAssert func(io.Reader) error + }{ + // Serializes null values in sparse lists + "RestJsonSparseListsSerializeNull": { + Params: &SparseJsonListsInput{ + SparseStringList: []*string{ + nil, + ptr.String("hi"), + }, + }, + ExpectMethod: "PUT", + ExpectURIPath: "/SparseJsonLists", + ExpectQuery: []smithytesting.QueryItem{}, + ExpectHeader: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + BodyAssert: func(actual io.Reader) error { + return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ + "sparseStringList": [ + null, + "hi" + ] + }`)) + }, + }, + } + for name, c := range cases { + t.Run(name, func(t *testing.T) { + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" + if c.Host != nil { + u, err := url.Parse(serverURL) + if err != nil { + t.Fatalf("expect no error, got %v", err) + } + u.Path = c.Host.Path + u.RawPath = c.Host.RawPath + u.RawQuery = c.Host.RawQuery + serverURL = u.String() + } + client := New(Options{ + APIOptions: []func(*middleware.Stack) error{ + func(s *middleware.Stack) error { + s.Finalize.Clear() + s.Initialize.Remove(`OperationInputValidation`) + return nil + }, + }, + EndpointResolver: EndpointResolverFunc(func(region string, options EndpointResolverOptions) (e aws.Endpoint, err error) { + e.URL = serverURL + e.SigningRegion = "us-west-2" + return e, err + }), + HTTPClient: protocoltesthttp.NewClient(), + IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), + Region: "us-west-2", + }) + result, err := client.SparseJsonLists(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) + if err != nil { + t.Fatalf("expect nil err, got %v", err) + } + if result == nil { + t.Fatalf("expect not nil result") + } + if e, a := c.ExpectMethod, actualReq.Method; e != a { + t.Errorf("expect %v method, got %v", e, a) + } + if e, a := c.ExpectURIPath, actualReq.URL.RawPath; e != a { + t.Errorf("expect %v path, got %v", e, a) + } + queryItems := smithytesting.ParseRawQuery(actualReq.URL.RawQuery) + smithytesting.AssertHasQuery(t, c.ExpectQuery, queryItems) + smithytesting.AssertHasQueryKeys(t, c.RequireQuery, queryItems) + smithytesting.AssertNotHaveQueryKeys(t, c.ForbidQuery, queryItems) + smithytesting.AssertHasHeader(t, c.ExpectHeader, actualReq.Header) + smithytesting.AssertHasHeaderKeys(t, c.RequireHeader, actualReq.Header) + smithytesting.AssertNotHaveHeaderKeys(t, c.ForbidHeader, actualReq.Header) + if c.BodyAssert != nil { + if err := c.BodyAssert(actualReq.Body); err != nil { + t.Errorf("expect body equal, got %v", err) + } + } + }) + } +} + +func TestClient_SparseJsonLists_awsRestjson1Deserialize(t *testing.T) { + cases := map[string]struct { + StatusCode int + Header http.Header + BodyMediaType string + Body []byte + ExpectResult *SparseJsonListsOutput + }{ + // Serializes null values in sparse lists + "RestJsonSparseListsSerializeNull": { + StatusCode: 200, + Header: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "sparseStringList": [ + null, + "hi" + ] + }`), + ExpectResult: &SparseJsonListsOutput{ + SparseStringList: []*string{ + nil, + ptr.String("hi"), + }, + }, + }, + } + for name, c := range cases { + t.Run(name, func(t *testing.T) { + serverURL := "http://localhost:8888/" + client := New(Options{ + HTTPClient: smithyhttp.ClientDoFunc(func(r *http.Request) (*http.Response, error) { + headers := http.Header{} + for k, vs := range c.Header { + for _, v := range vs { + headers.Add(k, v) + } + } + if len(c.BodyMediaType) != 0 && len(headers.Values("Content-Type")) == 0 { + headers.Set("Content-Type", c.BodyMediaType) + } + response := &http.Response{ + StatusCode: c.StatusCode, + Header: headers, + Request: r, + } + if len(c.Body) != 0 { + response.ContentLength = int64(len(c.Body)) + response.Body = ioutil.NopCloser(bytes.NewReader(c.Body)) + } else { + + response.Body = http.NoBody + } + return response, nil + }), + APIOptions: []func(*middleware.Stack) error{ + func(s *middleware.Stack) error { + s.Finalize.Clear() + s.Initialize.Remove(`OperationInputValidation`) + return nil + }, + }, + EndpointResolver: EndpointResolverFunc(func(region string, options EndpointResolverOptions) (e aws.Endpoint, err error) { + e.URL = serverURL + e.SigningRegion = "us-west-2" + return e, err + }), + IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), + Region: "us-west-2", + }) + var params SparseJsonListsInput + result, err := client.SparseJsonLists(context.Background(), ¶ms) + if err != nil { + t.Fatalf("expect nil err, got %v", err) + } + if result == nil { + t.Fatalf("expect not nil result") + } + if err := smithytesting.CompareValues(c.ExpectResult, result); err != nil { + t.Errorf("expect c.ExpectResult value match:\n%v", err) + } + }) + } +} diff --git a/internal/protocoltest/awsrestjson/api_op_SparseJsonMaps.go b/internal/protocoltest/awsrestjson/api_op_SparseJsonMaps.go new file mode 100644 index 00000000000..0c5b4dfedca --- /dev/null +++ b/internal/protocoltest/awsrestjson/api_op_SparseJsonMaps.go @@ -0,0 +1,143 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package awsrestjson + +import ( + "context" + "fmt" + awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" + "github.com/aws/smithy-go/middleware" + smithyhttp "github.com/aws/smithy-go/transport/http" +) + +// This example tests sparse map serialization. +func (c *Client) SparseJsonMaps(ctx context.Context, params *SparseJsonMapsInput, optFns ...func(*Options)) (*SparseJsonMapsOutput, error) { + if params == nil { + params = &SparseJsonMapsInput{} + } + + result, metadata, err := c.invokeOperation(ctx, "SparseJsonMaps", params, optFns, c.addOperationSparseJsonMapsMiddlewares) + if err != nil { + return nil, err + } + + out := result.(*SparseJsonMapsOutput) + out.ResultMetadata = metadata + return out, nil +} + +type SparseJsonMapsInput struct { + SparseBooleanMap map[string]*bool + + SparseNumberMap map[string]*int32 + + SparseSetMap map[string][]string + + SparseStringMap map[string]*string + + SparseStructMap map[string]*types.GreetingStruct + + noSmithyDocumentSerde +} + +type SparseJsonMapsOutput struct { + SparseBooleanMap map[string]*bool + + SparseNumberMap map[string]*int32 + + SparseSetMap map[string][]string + + SparseStringMap map[string]*string + + SparseStructMap map[string]*types.GreetingStruct + + // Metadata pertaining to the operation's result. + ResultMetadata middleware.Metadata + + noSmithyDocumentSerde +} + +func (c *Client) addOperationSparseJsonMapsMiddlewares(stack *middleware.Stack, options Options) (err error) { + if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil { + return err + } + err = stack.Serialize.Add(&awsRestjson1_serializeOpSparseJsonMaps{}, middleware.After) + if err != nil { + return err + } + err = stack.Deserialize.Add(&awsRestjson1_deserializeOpSparseJsonMaps{}, middleware.After) + if err != nil { + return err + } + if err := addProtocolFinalizerMiddlewares(stack, options, "SparseJsonMaps"); err != nil { + return fmt.Errorf("add protocol finalizers: %v", err) + } + + if err = addlegacyEndpointContextSetter(stack, options); err != nil { + return err + } + if err = addSetLoggerMiddleware(stack, options); err != nil { + return err + } + if err = addClientRequestID(stack); err != nil { + return err + } + if err = addComputeContentLength(stack); err != nil { + return err + } + if err = addResolveEndpointMiddleware(stack, options); err != nil { + return err + } + if err = addComputePayloadSHA256(stack); err != nil { + return err + } + if err = addRetry(stack, options); err != nil { + return err + } + if err = addRawResponseToMetadata(stack); err != nil { + return err + } + if err = addRecordResponseTiming(stack); err != nil { + return err + } + if err = addClientUserAgent(stack, options); err != nil { + return err + } + if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { + return err + } + if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { + return err + } + if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil { + return err + } + if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSparseJsonMaps(options.Region), middleware.Before); err != nil { + return err + } + if err = addRecursionDetection(stack); err != nil { + return err + } + if err = addRequestIDRetrieverMiddleware(stack); err != nil { + return err + } + if err = addResponseErrorMiddleware(stack); err != nil { + return err + } + if err = addRequestResponseLogging(stack, options); err != nil { + return err + } + if err = addDisableHTTPSMiddleware(stack, options); err != nil { + return err + } + return nil +} + +func newServiceMetadataMiddleware_opSparseJsonMaps(region string) *awsmiddleware.RegisterServiceMetadata { + return &awsmiddleware.RegisterServiceMetadata{ + Region: region, + ServiceID: ServiceID, + OperationName: "SparseJsonMaps", + } +} diff --git a/internal/protocoltest/awsrestjson/api_op_SparseJsonMaps_test.go b/internal/protocoltest/awsrestjson/api_op_SparseJsonMaps_test.go new file mode 100644 index 00000000000..fdd8ba246ae --- /dev/null +++ b/internal/protocoltest/awsrestjson/api_op_SparseJsonMaps_test.go @@ -0,0 +1,461 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package awsrestjson + +import ( + "bytes" + "context" + "github.com/aws/aws-sdk-go-v2/aws" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" + "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types" + "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" + "github.com/aws/smithy-go/ptr" + smithyrand "github.com/aws/smithy-go/rand" + smithytesting "github.com/aws/smithy-go/testing" + smithyhttp "github.com/aws/smithy-go/transport/http" + "io" + "io/ioutil" + "net/http" + "net/url" + "testing" +) + +func TestClient_SparseJsonMaps_awsRestjson1Serialize(t *testing.T) { + cases := map[string]struct { + Params *SparseJsonMapsInput + ExpectMethod string + ExpectURIPath string + ExpectQuery []smithytesting.QueryItem + RequireQuery []string + ForbidQuery []string + ExpectHeader http.Header + RequireHeader []string + ForbidHeader []string + Host *url.URL + BodyMediaType string + BodyAssert func(io.Reader) error + }{ + // Serializes JSON maps + "RestJsonSparseJsonMaps": { + Params: &SparseJsonMapsInput{ + SparseStructMap: map[string]*types.GreetingStruct{ + "foo": { + Hi: ptr.String("there"), + }, + "baz": { + Hi: ptr.String("bye"), + }, + }, + }, + ExpectMethod: "POST", + ExpectURIPath: "/SparseJsonMaps", + ExpectQuery: []smithytesting.QueryItem{}, + ExpectHeader: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + BodyAssert: func(actual io.Reader) error { + return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ + "sparseStructMap": { + "foo": { + "hi": "there" + }, + "baz": { + "hi": "bye" + } + } + }`)) + }, + }, + // Serializes JSON map values in sparse maps + "RestJsonSerializesSparseNullMapValues": { + Params: &SparseJsonMapsInput{ + SparseBooleanMap: map[string]*bool{ + "x": nil, + }, + SparseNumberMap: map[string]*int32{ + "x": nil, + }, + SparseStringMap: map[string]*string{ + "x": nil, + }, + SparseStructMap: map[string]*types.GreetingStruct{ + "x": nil, + }, + }, + ExpectMethod: "POST", + ExpectURIPath: "/SparseJsonMaps", + ExpectQuery: []smithytesting.QueryItem{}, + ExpectHeader: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + BodyAssert: func(actual io.Reader) error { + return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ + "sparseBooleanMap": { + "x": null + }, + "sparseNumberMap": { + "x": null + }, + "sparseStringMap": { + "x": null + }, + "sparseStructMap": { + "x": null + } + }`)) + }, + }, + // Ensure that 0 and false are sent over the wire in all maps and lists + "RestJsonSerializesZeroValuesInSparseMaps": { + Params: &SparseJsonMapsInput{ + SparseNumberMap: map[string]*int32{ + "x": ptr.Int32(0), + }, + SparseBooleanMap: map[string]*bool{ + "x": ptr.Bool(false), + }, + }, + ExpectMethod: "POST", + ExpectURIPath: "/SparseJsonMaps", + ExpectQuery: []smithytesting.QueryItem{}, + ExpectHeader: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + BodyAssert: func(actual io.Reader) error { + return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ + "sparseNumberMap": { + "x": 0 + }, + "sparseBooleanMap": { + "x": false + } + }`)) + }, + }, + // A request that contains a sparse map of sets + "RestJsonSerializesSparseSetMap": { + Params: &SparseJsonMapsInput{ + SparseSetMap: map[string][]string{ + "x": {}, + "y": { + "a", + "b", + }, + }, + }, + ExpectMethod: "POST", + ExpectURIPath: "/SparseJsonMaps", + ExpectQuery: []smithytesting.QueryItem{}, + ExpectHeader: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + BodyAssert: func(actual io.Reader) error { + return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ + "sparseSetMap": { + "x": [], + "y": ["a", "b"] + } + }`)) + }, + }, + // A request that contains a sparse map of sets. + "RestJsonSerializesSparseSetMapAndRetainsNull": { + Params: &SparseJsonMapsInput{ + SparseSetMap: map[string][]string{ + "x": {}, + "y": { + "a", + "b", + }, + "z": nil, + }, + }, + ExpectMethod: "POST", + ExpectURIPath: "/SparseJsonMaps", + ExpectQuery: []smithytesting.QueryItem{}, + ExpectHeader: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + BodyAssert: func(actual io.Reader) error { + return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ + "sparseSetMap": { + "x": [], + "y": ["a", "b"], + "z": null + } + }`)) + }, + }, + } + for name, c := range cases { + t.Run(name, func(t *testing.T) { + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" + if c.Host != nil { + u, err := url.Parse(serverURL) + if err != nil { + t.Fatalf("expect no error, got %v", err) + } + u.Path = c.Host.Path + u.RawPath = c.Host.RawPath + u.RawQuery = c.Host.RawQuery + serverURL = u.String() + } + client := New(Options{ + APIOptions: []func(*middleware.Stack) error{ + func(s *middleware.Stack) error { + s.Finalize.Clear() + s.Initialize.Remove(`OperationInputValidation`) + return nil + }, + }, + EndpointResolver: EndpointResolverFunc(func(region string, options EndpointResolverOptions) (e aws.Endpoint, err error) { + e.URL = serverURL + e.SigningRegion = "us-west-2" + return e, err + }), + HTTPClient: protocoltesthttp.NewClient(), + IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), + Region: "us-west-2", + }) + result, err := client.SparseJsonMaps(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) + if err != nil { + t.Fatalf("expect nil err, got %v", err) + } + if result == nil { + t.Fatalf("expect not nil result") + } + if e, a := c.ExpectMethod, actualReq.Method; e != a { + t.Errorf("expect %v method, got %v", e, a) + } + if e, a := c.ExpectURIPath, actualReq.URL.RawPath; e != a { + t.Errorf("expect %v path, got %v", e, a) + } + queryItems := smithytesting.ParseRawQuery(actualReq.URL.RawQuery) + smithytesting.AssertHasQuery(t, c.ExpectQuery, queryItems) + smithytesting.AssertHasQueryKeys(t, c.RequireQuery, queryItems) + smithytesting.AssertNotHaveQueryKeys(t, c.ForbidQuery, queryItems) + smithytesting.AssertHasHeader(t, c.ExpectHeader, actualReq.Header) + smithytesting.AssertHasHeaderKeys(t, c.RequireHeader, actualReq.Header) + smithytesting.AssertNotHaveHeaderKeys(t, c.ForbidHeader, actualReq.Header) + if c.BodyAssert != nil { + if err := c.BodyAssert(actualReq.Body); err != nil { + t.Errorf("expect body equal, got %v", err) + } + } + }) + } +} + +func TestClient_SparseJsonMaps_awsRestjson1Deserialize(t *testing.T) { + cases := map[string]struct { + StatusCode int + Header http.Header + BodyMediaType string + Body []byte + ExpectResult *SparseJsonMapsOutput + }{ + // Deserializes JSON maps + "RestJsonSparseJsonMaps": { + StatusCode: 200, + Header: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "sparseStructMap": { + "foo": { + "hi": "there" + }, + "baz": { + "hi": "bye" + } + } + }`), + ExpectResult: &SparseJsonMapsOutput{ + SparseStructMap: map[string]*types.GreetingStruct{ + "foo": { + Hi: ptr.String("there"), + }, + "baz": { + Hi: ptr.String("bye"), + }, + }, + }, + }, + // Deserializes null JSON map values + "RestJsonDeserializesSparseNullMapValues": { + StatusCode: 200, + Header: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "sparseBooleanMap": { + "x": null + }, + "sparseNumberMap": { + "x": null + }, + "sparseStringMap": { + "x": null + }, + "sparseStructMap": { + "x": null + } + }`), + ExpectResult: &SparseJsonMapsOutput{ + SparseBooleanMap: map[string]*bool{ + "x": nil, + }, + SparseNumberMap: map[string]*int32{ + "x": nil, + }, + SparseStringMap: map[string]*string{ + "x": nil, + }, + SparseStructMap: map[string]*types.GreetingStruct{ + "x": nil, + }, + }, + }, + // Ensure that 0 and false are sent over the wire in all maps and lists + "RestJsonDeserializesZeroValuesInSparseMaps": { + StatusCode: 200, + Header: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "sparseNumberMap": { + "x": 0 + }, + "sparseBooleanMap": { + "x": false + } + }`), + ExpectResult: &SparseJsonMapsOutput{ + SparseNumberMap: map[string]*int32{ + "x": ptr.Int32(0), + }, + SparseBooleanMap: map[string]*bool{ + "x": ptr.Bool(false), + }, + }, + }, + // A response that contains a sparse map of sets + "RestJsonDeserializesSparseSetMap": { + StatusCode: 200, + Header: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "sparseSetMap": { + "x": [], + "y": ["a", "b"] + } + }`), + ExpectResult: &SparseJsonMapsOutput{ + SparseSetMap: map[string][]string{ + "x": {}, + "y": { + "a", + "b", + }, + }, + }, + }, + // A response that contains a sparse map of sets. + "RestJsonDeserializesSparseSetMapAndRetainsNull": { + StatusCode: 200, + Header: http.Header{ + "Content-Type": []string{"application/json"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "sparseSetMap": { + "x": [], + "y": ["a", "b"], + "z": null + } + }`), + ExpectResult: &SparseJsonMapsOutput{ + SparseSetMap: map[string][]string{ + "x": {}, + "y": { + "a", + "b", + }, + "z": nil, + }, + }, + }, + } + for name, c := range cases { + t.Run(name, func(t *testing.T) { + serverURL := "http://localhost:8888/" + client := New(Options{ + HTTPClient: smithyhttp.ClientDoFunc(func(r *http.Request) (*http.Response, error) { + headers := http.Header{} + for k, vs := range c.Header { + for _, v := range vs { + headers.Add(k, v) + } + } + if len(c.BodyMediaType) != 0 && len(headers.Values("Content-Type")) == 0 { + headers.Set("Content-Type", c.BodyMediaType) + } + response := &http.Response{ + StatusCode: c.StatusCode, + Header: headers, + Request: r, + } + if len(c.Body) != 0 { + response.ContentLength = int64(len(c.Body)) + response.Body = ioutil.NopCloser(bytes.NewReader(c.Body)) + } else { + + response.Body = http.NoBody + } + return response, nil + }), + APIOptions: []func(*middleware.Stack) error{ + func(s *middleware.Stack) error { + s.Finalize.Clear() + s.Initialize.Remove(`OperationInputValidation`) + return nil + }, + }, + EndpointResolver: EndpointResolverFunc(func(region string, options EndpointResolverOptions) (e aws.Endpoint, err error) { + e.URL = serverURL + e.SigningRegion = "us-west-2" + return e, err + }), + IdempotencyTokenProvider: smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}), + Region: "us-west-2", + }) + var params SparseJsonMapsInput + result, err := client.SparseJsonMaps(context.Background(), ¶ms) + if err != nil { + t.Fatalf("expect nil err, got %v", err) + } + if result == nil { + t.Fatalf("expect not nil result") + } + if err := smithytesting.CompareValues(c.ExpectResult, result); err != nil { + t.Errorf("expect c.ExpectResult value match:\n%v", err) + } + }) + } +} diff --git a/internal/protocoltest/awsrestjson/deserializers.go b/internal/protocoltest/awsrestjson/deserializers.go index 2355c35bae0..774962ac4d2 100644 --- a/internal/protocoltest/awsrestjson/deserializers.go +++ b/internal/protocoltest/awsrestjson/deserializers.go @@ -4249,11 +4249,6 @@ func awsRestjson1_deserializeOpDocumentJsonListsOutput(v **JsonListsOutput, valu return err } - case "sparseStringList": - if err := awsRestjson1_deserializeDocumentSparseStringList(&sv.SparseStringList, value); err != nil { - return err - } - case "stringList": if err := awsRestjson1_deserializeDocumentStringList(&sv.StringList, value); err != nil { return err @@ -4438,31 +4433,6 @@ func awsRestjson1_deserializeOpDocumentJsonMapsOutput(v **JsonMapsOutput, value return err } - case "sparseBooleanMap": - if err := awsRestjson1_deserializeDocumentSparseBooleanMap(&sv.SparseBooleanMap, value); err != nil { - return err - } - - case "sparseNumberMap": - if err := awsRestjson1_deserializeDocumentSparseNumberMap(&sv.SparseNumberMap, value); err != nil { - return err - } - - case "sparseSetMap": - if err := awsRestjson1_deserializeDocumentSparseSetMap(&sv.SparseSetMap, value); err != nil { - return err - } - - case "sparseStringMap": - if err := awsRestjson1_deserializeDocumentSparseStringMap(&sv.SparseStringMap, value); err != nil { - return err - } - - case "sparseStructMap": - if err := awsRestjson1_deserializeDocumentSparseStructMap(&sv.SparseStructMap, value); err != nil { - return err - } - default: _, _ = key, value @@ -9468,6 +9438,314 @@ func awsRestjson1_deserializeOpDocumentSimpleScalarPropertiesOutput(v **SimpleSc return nil } +type awsRestjson1_deserializeOpSparseJsonLists struct { +} + +func (*awsRestjson1_deserializeOpSparseJsonLists) ID() string { + return "OperationDeserializer" +} + +func (m *awsRestjson1_deserializeOpSparseJsonLists) HandleDeserialize(ctx context.Context, in middleware.DeserializeInput, next middleware.DeserializeHandler) ( + out middleware.DeserializeOutput, metadata middleware.Metadata, err error, +) { + out, metadata, err = next.HandleDeserialize(ctx, in) + if err != nil { + return out, metadata, err + } + + response, ok := out.RawResponse.(*smithyhttp.Response) + if !ok { + return out, metadata, &smithy.DeserializationError{Err: fmt.Errorf("unknown transport type %T", out.RawResponse)} + } + + if response.StatusCode < 200 || response.StatusCode >= 300 { + return out, metadata, awsRestjson1_deserializeOpErrorSparseJsonLists(response, &metadata) + } + output := &SparseJsonListsOutput{} + out.Result = output + + var buff [1024]byte + ringBuffer := smithyio.NewRingBuffer(buff[:]) + + body := io.TeeReader(response.Body, ringBuffer) + + decoder := json.NewDecoder(body) + decoder.UseNumber() + var shape interface{} + if err := decoder.Decode(&shape); err != nil && err != io.EOF { + var snapshot bytes.Buffer + io.Copy(&snapshot, ringBuffer) + err = &smithy.DeserializationError{ + Err: fmt.Errorf("failed to decode response body, %w", err), + Snapshot: snapshot.Bytes(), + } + return out, metadata, err + } + + err = awsRestjson1_deserializeOpDocumentSparseJsonListsOutput(&output, shape) + if err != nil { + var snapshot bytes.Buffer + io.Copy(&snapshot, ringBuffer) + return out, metadata, &smithy.DeserializationError{ + Err: fmt.Errorf("failed to decode response body with invalid JSON, %w", err), + Snapshot: snapshot.Bytes(), + } + } + + return out, metadata, err +} + +func awsRestjson1_deserializeOpErrorSparseJsonLists(response *smithyhttp.Response, metadata *middleware.Metadata) error { + var errorBuffer bytes.Buffer + if _, err := io.Copy(&errorBuffer, response.Body); err != nil { + return &smithy.DeserializationError{Err: fmt.Errorf("failed to copy error response body, %w", err)} + } + errorBody := bytes.NewReader(errorBuffer.Bytes()) + + errorCode := "UnknownError" + errorMessage := errorCode + + headerCode := response.Header.Get("X-Amzn-ErrorType") + if len(headerCode) != 0 { + errorCode = restjson.SanitizeErrorCode(headerCode) + } + + var buff [1024]byte + ringBuffer := smithyio.NewRingBuffer(buff[:]) + + body := io.TeeReader(errorBody, ringBuffer) + decoder := json.NewDecoder(body) + decoder.UseNumber() + jsonCode, message, err := restjson.GetErrorInfo(decoder) + if err != nil { + var snapshot bytes.Buffer + io.Copy(&snapshot, ringBuffer) + err = &smithy.DeserializationError{ + Err: fmt.Errorf("failed to decode response body, %w", err), + Snapshot: snapshot.Bytes(), + } + return err + } + + errorBody.Seek(0, io.SeekStart) + if len(headerCode) == 0 && len(jsonCode) != 0 { + errorCode = restjson.SanitizeErrorCode(jsonCode) + } + if len(message) != 0 { + errorMessage = message + } + + switch { + default: + genericError := &smithy.GenericAPIError{ + Code: errorCode, + Message: errorMessage, + } + return genericError + + } +} + +func awsRestjson1_deserializeOpDocumentSparseJsonListsOutput(v **SparseJsonListsOutput, value interface{}) error { + if v == nil { + return fmt.Errorf("unexpected nil of type %T", v) + } + if value == nil { + return nil + } + + shape, ok := value.(map[string]interface{}) + if !ok { + return fmt.Errorf("unexpected JSON type %v", value) + } + + var sv *SparseJsonListsOutput + if *v == nil { + sv = &SparseJsonListsOutput{} + } else { + sv = *v + } + + for key, value := range shape { + switch key { + case "sparseStringList": + if err := awsRestjson1_deserializeDocumentSparseStringList(&sv.SparseStringList, value); err != nil { + return err + } + + default: + _, _ = key, value + + } + } + *v = sv + return nil +} + +type awsRestjson1_deserializeOpSparseJsonMaps struct { +} + +func (*awsRestjson1_deserializeOpSparseJsonMaps) ID() string { + return "OperationDeserializer" +} + +func (m *awsRestjson1_deserializeOpSparseJsonMaps) HandleDeserialize(ctx context.Context, in middleware.DeserializeInput, next middleware.DeserializeHandler) ( + out middleware.DeserializeOutput, metadata middleware.Metadata, err error, +) { + out, metadata, err = next.HandleDeserialize(ctx, in) + if err != nil { + return out, metadata, err + } + + response, ok := out.RawResponse.(*smithyhttp.Response) + if !ok { + return out, metadata, &smithy.DeserializationError{Err: fmt.Errorf("unknown transport type %T", out.RawResponse)} + } + + if response.StatusCode < 200 || response.StatusCode >= 300 { + return out, metadata, awsRestjson1_deserializeOpErrorSparseJsonMaps(response, &metadata) + } + output := &SparseJsonMapsOutput{} + out.Result = output + + var buff [1024]byte + ringBuffer := smithyio.NewRingBuffer(buff[:]) + + body := io.TeeReader(response.Body, ringBuffer) + + decoder := json.NewDecoder(body) + decoder.UseNumber() + var shape interface{} + if err := decoder.Decode(&shape); err != nil && err != io.EOF { + var snapshot bytes.Buffer + io.Copy(&snapshot, ringBuffer) + err = &smithy.DeserializationError{ + Err: fmt.Errorf("failed to decode response body, %w", err), + Snapshot: snapshot.Bytes(), + } + return out, metadata, err + } + + err = awsRestjson1_deserializeOpDocumentSparseJsonMapsOutput(&output, shape) + if err != nil { + var snapshot bytes.Buffer + io.Copy(&snapshot, ringBuffer) + return out, metadata, &smithy.DeserializationError{ + Err: fmt.Errorf("failed to decode response body with invalid JSON, %w", err), + Snapshot: snapshot.Bytes(), + } + } + + return out, metadata, err +} + +func awsRestjson1_deserializeOpErrorSparseJsonMaps(response *smithyhttp.Response, metadata *middleware.Metadata) error { + var errorBuffer bytes.Buffer + if _, err := io.Copy(&errorBuffer, response.Body); err != nil { + return &smithy.DeserializationError{Err: fmt.Errorf("failed to copy error response body, %w", err)} + } + errorBody := bytes.NewReader(errorBuffer.Bytes()) + + errorCode := "UnknownError" + errorMessage := errorCode + + headerCode := response.Header.Get("X-Amzn-ErrorType") + if len(headerCode) != 0 { + errorCode = restjson.SanitizeErrorCode(headerCode) + } + + var buff [1024]byte + ringBuffer := smithyio.NewRingBuffer(buff[:]) + + body := io.TeeReader(errorBody, ringBuffer) + decoder := json.NewDecoder(body) + decoder.UseNumber() + jsonCode, message, err := restjson.GetErrorInfo(decoder) + if err != nil { + var snapshot bytes.Buffer + io.Copy(&snapshot, ringBuffer) + err = &smithy.DeserializationError{ + Err: fmt.Errorf("failed to decode response body, %w", err), + Snapshot: snapshot.Bytes(), + } + return err + } + + errorBody.Seek(0, io.SeekStart) + if len(headerCode) == 0 && len(jsonCode) != 0 { + errorCode = restjson.SanitizeErrorCode(jsonCode) + } + if len(message) != 0 { + errorMessage = message + } + + switch { + default: + genericError := &smithy.GenericAPIError{ + Code: errorCode, + Message: errorMessage, + } + return genericError + + } +} + +func awsRestjson1_deserializeOpDocumentSparseJsonMapsOutput(v **SparseJsonMapsOutput, value interface{}) error { + if v == nil { + return fmt.Errorf("unexpected nil of type %T", v) + } + if value == nil { + return nil + } + + shape, ok := value.(map[string]interface{}) + if !ok { + return fmt.Errorf("unexpected JSON type %v", value) + } + + var sv *SparseJsonMapsOutput + if *v == nil { + sv = &SparseJsonMapsOutput{} + } else { + sv = *v + } + + for key, value := range shape { + switch key { + case "sparseBooleanMap": + if err := awsRestjson1_deserializeDocumentSparseBooleanMap(&sv.SparseBooleanMap, value); err != nil { + return err + } + + case "sparseNumberMap": + if err := awsRestjson1_deserializeDocumentSparseNumberMap(&sv.SparseNumberMap, value); err != nil { + return err + } + + case "sparseSetMap": + if err := awsRestjson1_deserializeDocumentSparseSetMap(&sv.SparseSetMap, value); err != nil { + return err + } + + case "sparseStringMap": + if err := awsRestjson1_deserializeDocumentSparseStringMap(&sv.SparseStringMap, value); err != nil { + return err + } + + case "sparseStructMap": + if err := awsRestjson1_deserializeDocumentSparseStructMap(&sv.SparseStructMap, value); err != nil { + return err + } + + default: + _, _ = key, value + + } + } + *v = sv + return nil +} + type awsRestjson1_deserializeOpStreamingTraits struct { } diff --git a/internal/protocoltest/awsrestjson/generated.json b/internal/protocoltest/awsrestjson/generated.json index 8eb5f8a875e..95430845249 100644 --- a/internal/protocoltest/awsrestjson/generated.json +++ b/internal/protocoltest/awsrestjson/generated.json @@ -143,6 +143,10 @@ "api_op_RecursiveShapes_test.go", "api_op_SimpleScalarProperties.go", "api_op_SimpleScalarProperties_test.go", + "api_op_SparseJsonLists.go", + "api_op_SparseJsonLists_test.go", + "api_op_SparseJsonMaps.go", + "api_op_SparseJsonMaps_test.go", "api_op_StreamingTraits.go", "api_op_StreamingTraitsRequireLength.go", "api_op_StreamingTraitsRequireLength_test.go", diff --git a/internal/protocoltest/awsrestjson/serializers.go b/internal/protocoltest/awsrestjson/serializers.go index a153254644c..5365846ab97 100644 --- a/internal/protocoltest/awsrestjson/serializers.go +++ b/internal/protocoltest/awsrestjson/serializers.go @@ -2689,13 +2689,6 @@ func awsRestjson1_serializeOpDocumentJsonListsInput(v *JsonListsInput, value smi } } - if v.SparseStringList != nil { - ok := object.Key("sparseStringList") - if err := awsRestjson1_serializeDocumentSparseStringList(v.SparseStringList, ok); err != nil { - return err - } - } - if v.StringList != nil { ok := object.Key("stringList") if err := awsRestjson1_serializeDocumentStringList(v.StringList, ok); err != nil { @@ -2829,41 +2822,6 @@ func awsRestjson1_serializeOpDocumentJsonMapsInput(v *JsonMapsInput, value smith } } - if v.SparseBooleanMap != nil { - ok := object.Key("sparseBooleanMap") - if err := awsRestjson1_serializeDocumentSparseBooleanMap(v.SparseBooleanMap, ok); err != nil { - return err - } - } - - if v.SparseNumberMap != nil { - ok := object.Key("sparseNumberMap") - if err := awsRestjson1_serializeDocumentSparseNumberMap(v.SparseNumberMap, ok); err != nil { - return err - } - } - - if v.SparseSetMap != nil { - ok := object.Key("sparseSetMap") - if err := awsRestjson1_serializeDocumentSparseSetMap(v.SparseSetMap, ok); err != nil { - return err - } - } - - if v.SparseStringMap != nil { - ok := object.Key("sparseStringMap") - if err := awsRestjson1_serializeDocumentSparseStringMap(v.SparseStringMap, ok); err != nil { - return err - } - } - - if v.SparseStructMap != nil { - ok := object.Key("sparseStructMap") - if err := awsRestjson1_serializeDocumentSparseStructMap(v.SparseStructMap, ok); err != nil { - return err - } - } - return nil } @@ -6564,6 +6522,188 @@ func awsRestjson1_serializeOpDocumentSimpleScalarPropertiesInput(v *SimpleScalar return nil } +type awsRestjson1_serializeOpSparseJsonLists struct { +} + +func (*awsRestjson1_serializeOpSparseJsonLists) ID() string { + return "OperationSerializer" +} + +func (m *awsRestjson1_serializeOpSparseJsonLists) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) ( + out middleware.SerializeOutput, metadata middleware.Metadata, err error, +) { + request, ok := in.Request.(*smithyhttp.Request) + if !ok { + return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown transport type %T", in.Request)} + } + + input, ok := in.Parameters.(*SparseJsonListsInput) + _ = input + if !ok { + return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown input parameters type %T", in.Parameters)} + } + + opPath, opQuery := httpbinding.SplitURI("/SparseJsonLists") + request.URL.Path = smithyhttp.JoinPath(request.URL.Path, opPath) + request.URL.RawQuery = smithyhttp.JoinRawQuery(request.URL.RawQuery, opQuery) + request.Method = "PUT" + var restEncoder *httpbinding.Encoder + if request.URL.RawPath == "" { + restEncoder, err = httpbinding.NewEncoder(request.URL.Path, request.URL.RawQuery, request.Header) + } else { + request.URL.RawPath = smithyhttp.JoinPath(request.URL.RawPath, opPath) + restEncoder, err = httpbinding.NewEncoderWithRawPath(request.URL.Path, request.URL.RawPath, request.URL.RawQuery, request.Header) + } + + if err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + + restEncoder.SetHeader("Content-Type").String("application/json") + + jsonEncoder := smithyjson.NewEncoder() + if err := awsRestjson1_serializeOpDocumentSparseJsonListsInput(input, jsonEncoder.Value); err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + + if request, err = request.SetStream(bytes.NewReader(jsonEncoder.Bytes())); err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + + if request.Request, err = restEncoder.Encode(request.Request); err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + in.Request = request + + return next.HandleSerialize(ctx, in) +} +func awsRestjson1_serializeOpHttpBindingsSparseJsonListsInput(v *SparseJsonListsInput, encoder *httpbinding.Encoder) error { + if v == nil { + return fmt.Errorf("unsupported serialization of nil %T", v) + } + + return nil +} + +func awsRestjson1_serializeOpDocumentSparseJsonListsInput(v *SparseJsonListsInput, value smithyjson.Value) error { + object := value.Object() + defer object.Close() + + if v.SparseStringList != nil { + ok := object.Key("sparseStringList") + if err := awsRestjson1_serializeDocumentSparseStringList(v.SparseStringList, ok); err != nil { + return err + } + } + + return nil +} + +type awsRestjson1_serializeOpSparseJsonMaps struct { +} + +func (*awsRestjson1_serializeOpSparseJsonMaps) ID() string { + return "OperationSerializer" +} + +func (m *awsRestjson1_serializeOpSparseJsonMaps) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) ( + out middleware.SerializeOutput, metadata middleware.Metadata, err error, +) { + request, ok := in.Request.(*smithyhttp.Request) + if !ok { + return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown transport type %T", in.Request)} + } + + input, ok := in.Parameters.(*SparseJsonMapsInput) + _ = input + if !ok { + return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown input parameters type %T", in.Parameters)} + } + + opPath, opQuery := httpbinding.SplitURI("/SparseJsonMaps") + request.URL.Path = smithyhttp.JoinPath(request.URL.Path, opPath) + request.URL.RawQuery = smithyhttp.JoinRawQuery(request.URL.RawQuery, opQuery) + request.Method = "POST" + var restEncoder *httpbinding.Encoder + if request.URL.RawPath == "" { + restEncoder, err = httpbinding.NewEncoder(request.URL.Path, request.URL.RawQuery, request.Header) + } else { + request.URL.RawPath = smithyhttp.JoinPath(request.URL.RawPath, opPath) + restEncoder, err = httpbinding.NewEncoderWithRawPath(request.URL.Path, request.URL.RawPath, request.URL.RawQuery, request.Header) + } + + if err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + + restEncoder.SetHeader("Content-Type").String("application/json") + + jsonEncoder := smithyjson.NewEncoder() + if err := awsRestjson1_serializeOpDocumentSparseJsonMapsInput(input, jsonEncoder.Value); err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + + if request, err = request.SetStream(bytes.NewReader(jsonEncoder.Bytes())); err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + + if request.Request, err = restEncoder.Encode(request.Request); err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + in.Request = request + + return next.HandleSerialize(ctx, in) +} +func awsRestjson1_serializeOpHttpBindingsSparseJsonMapsInput(v *SparseJsonMapsInput, encoder *httpbinding.Encoder) error { + if v == nil { + return fmt.Errorf("unsupported serialization of nil %T", v) + } + + return nil +} + +func awsRestjson1_serializeOpDocumentSparseJsonMapsInput(v *SparseJsonMapsInput, value smithyjson.Value) error { + object := value.Object() + defer object.Close() + + if v.SparseBooleanMap != nil { + ok := object.Key("sparseBooleanMap") + if err := awsRestjson1_serializeDocumentSparseBooleanMap(v.SparseBooleanMap, ok); err != nil { + return err + } + } + + if v.SparseNumberMap != nil { + ok := object.Key("sparseNumberMap") + if err := awsRestjson1_serializeDocumentSparseNumberMap(v.SparseNumberMap, ok); err != nil { + return err + } + } + + if v.SparseSetMap != nil { + ok := object.Key("sparseSetMap") + if err := awsRestjson1_serializeDocumentSparseSetMap(v.SparseSetMap, ok); err != nil { + return err + } + } + + if v.SparseStringMap != nil { + ok := object.Key("sparseStringMap") + if err := awsRestjson1_serializeDocumentSparseStringMap(v.SparseStringMap, ok); err != nil { + return err + } + } + + if v.SparseStructMap != nil { + ok := object.Key("sparseStructMap") + if err := awsRestjson1_serializeDocumentSparseStructMap(v.SparseStructMap, ok); err != nil { + return err + } + } + + return nil +} + type awsRestjson1_serializeOpStreamingTraits struct { } diff --git a/internal/protocoltest/awsrestjson/snapshot_test.go b/internal/protocoltest/awsrestjson/snapshot_test.go index d21435eff9b..a0433cd7de5 100644 --- a/internal/protocoltest/awsrestjson/snapshot_test.go +++ b/internal/protocoltest/awsrestjson/snapshot_test.go @@ -1070,6 +1070,30 @@ func TestCheckSnapshot_SimpleScalarProperties(t *testing.T) { } } +func TestCheckSnapshot_SparseJsonLists(t *testing.T) { + svc := New(Options{}) + _, err := svc.SparseJsonLists(context.Background(), nil, func(o *Options) { + o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error { + return testSnapshot(stack, "SparseJsonLists") + }) + }) + if _, ok := err.(snapshotOK); !ok && err != nil { + t.Fatal(err) + } +} + +func TestCheckSnapshot_SparseJsonMaps(t *testing.T) { + svc := New(Options{}) + _, err := svc.SparseJsonMaps(context.Background(), nil, func(o *Options) { + o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error { + return testSnapshot(stack, "SparseJsonMaps") + }) + }) + if _, ok := err.(snapshotOK); !ok && err != nil { + t.Fatal(err) + } +} + func TestCheckSnapshot_StreamingTraits(t *testing.T) { svc := New(Options{}) _, err := svc.StreamingTraits(context.Background(), nil, func(o *Options) { @@ -2185,6 +2209,30 @@ func TestUpdateSnapshot_SimpleScalarProperties(t *testing.T) { } } +func TestUpdateSnapshot_SparseJsonLists(t *testing.T) { + svc := New(Options{}) + _, err := svc.SparseJsonLists(context.Background(), nil, func(o *Options) { + o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error { + return updateSnapshot(stack, "SparseJsonLists") + }) + }) + if _, ok := err.(snapshotOK); !ok && err != nil { + t.Fatal(err) + } +} + +func TestUpdateSnapshot_SparseJsonMaps(t *testing.T) { + svc := New(Options{}) + _, err := svc.SparseJsonMaps(context.Background(), nil, func(o *Options) { + o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error { + return updateSnapshot(stack, "SparseJsonMaps") + }) + }) + if _, ok := err.(snapshotOK); !ok && err != nil { + t.Fatal(err) + } +} + func TestUpdateSnapshot_StreamingTraits(t *testing.T) { svc := New(Options{}) _, err := svc.StreamingTraits(context.Background(), nil, func(o *Options) { diff --git a/internal/protocoltest/ec2query/api_op_SimpleInputParams_test.go b/internal/protocoltest/ec2query/api_op_SimpleInputParams_test.go index 8fe2707d1f1..3cd8fd95920 100644 --- a/internal/protocoltest/ec2query/api_op_SimpleInputParams_test.go +++ b/internal/protocoltest/ec2query/api_op_SimpleInputParams_test.go @@ -185,7 +185,7 @@ func TestClient_SimpleInputParams_awsEc2querySerialize(t *testing.T) { }, BodyMediaType: "application/x-www-form-urlencoded", BodyAssert: func(actual io.Reader) error { - return smithytesting.CompareURLFormReaderBytes(actual, []byte(`Action=SimpleInputParams&Version=2020-01-08&A=Hi`)) + return smithytesting.CompareURLFormReaderBytes(actual, []byte(`Action=SimpleInputParams&Version=2020-01-08&HasQueryName=Hi`)) }, }, // ec2QueryName trait is preferred over xmlName. @@ -204,7 +204,7 @@ func TestClient_SimpleInputParams_awsEc2querySerialize(t *testing.T) { }, BodyMediaType: "application/x-www-form-urlencoded", BodyAssert: func(actual io.Reader) error { - return smithytesting.CompareURLFormReaderBytes(actual, []byte(`Action=SimpleInputParams&Version=2020-01-08&B=Hi`)) + return smithytesting.CompareURLFormReaderBytes(actual, []byte(`Action=SimpleInputParams&Version=2020-01-08&HasQueryAndXmlName=Hi`)) }, }, // xmlName is used with the ec2 protocol, but the first character is uppercased @@ -223,7 +223,7 @@ func TestClient_SimpleInputParams_awsEc2querySerialize(t *testing.T) { }, BodyMediaType: "application/x-www-form-urlencoded", BodyAssert: func(actual io.Reader) error { - return smithytesting.CompareURLFormReaderBytes(actual, []byte(`Action=SimpleInputParams&Version=2020-01-08&C=Hi`)) + return smithytesting.CompareURLFormReaderBytes(actual, []byte(`Action=SimpleInputParams&Version=2020-01-08&UsesXmlName=Hi`)) }, }, // Supports handling NaN float values. diff --git a/internal/protocoltest/ec2query/serializers.go b/internal/protocoltest/ec2query/serializers.go index efdc72e96ad..ff21c863bd0 100644 --- a/internal/protocoltest/ec2query/serializers.go +++ b/internal/protocoltest/ec2query/serializers.go @@ -1818,12 +1818,12 @@ func awsEc2query_serializeOpDocumentSimpleInputParamsInput(v *SimpleInputParamsI } if v.HasQueryAndXmlName != nil { - objectKey := object.Key("B") + objectKey := object.Key("HasQueryAndXmlName") objectKey.String(*v.HasQueryAndXmlName) } if v.HasQueryName != nil { - objectKey := object.Key("A") + objectKey := object.Key("HasQueryName") objectKey.String(*v.HasQueryName) } @@ -1833,7 +1833,7 @@ func awsEc2query_serializeOpDocumentSimpleInputParamsInput(v *SimpleInputParamsI } if v.UsesXmlName != nil { - objectKey := object.Key("C") + objectKey := object.Key("UsesXmlName") objectKey.String(*v.UsesXmlName) } diff --git a/internal/protocoltest/jsonrpc/api_op_NullOperation.go b/internal/protocoltest/jsonrpc/api_op_NullOperation.go index e9ce10035fd..394c5d387f5 100644 --- a/internal/protocoltest/jsonrpc/api_op_NullOperation.go +++ b/internal/protocoltest/jsonrpc/api_op_NullOperation.go @@ -26,20 +26,12 @@ func (c *Client) NullOperation(ctx context.Context, params *NullOperationInput, } type NullOperationInput struct { - SparseStringList []*string - - SparseStringMap map[string]*string - String_ *string noSmithyDocumentSerde } type NullOperationOutput struct { - SparseStringList []*string - - SparseStringMap map[string]*string - String_ *string // Metadata pertaining to the operation's result. diff --git a/internal/protocoltest/jsonrpc/api_op_NullOperation_test.go b/internal/protocoltest/jsonrpc/api_op_NullOperation_test.go index 4957b234fb3..320d8835ac4 100644 --- a/internal/protocoltest/jsonrpc/api_op_NullOperation_test.go +++ b/internal/protocoltest/jsonrpc/api_op_NullOperation_test.go @@ -50,52 +50,6 @@ func TestClient_NullOperation_awsAwsjson11Serialize(t *testing.T) { return smithytesting.CompareJSONReaderBytes(actual, []byte(`{}`)) }, }, - // Serializes null values in maps - "AwsJson11MapsSerializeNullValues": { - Params: &NullOperationInput{ - SparseStringMap: map[string]*string{ - "foo": nil, - }, - }, - ExpectMethod: "POST", - ExpectURIPath: "/", - ExpectQuery: []smithytesting.QueryItem{}, - ExpectHeader: http.Header{ - "Content-Type": []string{"application/x-amz-json-1.1"}, - "X-Amz-Target": []string{"JsonProtocol.NullOperation"}, - }, - BodyMediaType: "application/json", - BodyAssert: func(actual io.Reader) error { - return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ - "sparseStringMap": { - "foo": null - } - }`)) - }, - }, - // Serializes null values in lists - "AwsJson11ListsSerializeNull": { - Params: &NullOperationInput{ - SparseStringList: []*string{ - nil, - }, - }, - ExpectMethod: "POST", - ExpectURIPath: "/", - ExpectQuery: []smithytesting.QueryItem{}, - ExpectHeader: http.Header{ - "Content-Type": []string{"application/x-amz-json-1.1"}, - "X-Amz-Target": []string{"JsonProtocol.NullOperation"}, - }, - BodyMediaType: "application/json", - BodyAssert: func(actual io.Reader) error { - return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ - "sparseStringList": [ - null - ] - }`)) - }, - }, } for name, c := range cases { t.Run(name, func(t *testing.T) { @@ -180,42 +134,6 @@ func TestClient_NullOperation_awsAwsjson11Deserialize(t *testing.T) { }`), ExpectResult: &NullOperationOutput{}, }, - // Deserializes null values in maps - "AwsJson11MapsDeserializeNullValues": { - StatusCode: 200, - Header: http.Header{ - "Content-Type": []string{"application/x-amz-json-1.1"}, - }, - BodyMediaType: "application/json", - Body: []byte(`{ - "sparseStringMap": { - "foo": null - } - }`), - ExpectResult: &NullOperationOutput{ - SparseStringMap: map[string]*string{ - "foo": nil, - }, - }, - }, - // Deserializes null values in lists - "AwsJson11ListsDeserializeNull": { - StatusCode: 200, - Header: http.Header{ - "Content-Type": []string{"application/x-amz-json-1.1"}, - }, - BodyMediaType: "application/json", - Body: []byte(`{ - "sparseStringList": [ - null - ] - }`), - ExpectResult: &NullOperationOutput{ - SparseStringList: []*string{ - nil, - }, - }, - }, } for name, c := range cases { t.Run(name, func(t *testing.T) { diff --git a/internal/protocoltest/jsonrpc/api_op_SparseNullsOperation.go b/internal/protocoltest/jsonrpc/api_op_SparseNullsOperation.go new file mode 100644 index 00000000000..4188c25ab83 --- /dev/null +++ b/internal/protocoltest/jsonrpc/api_op_SparseNullsOperation.go @@ -0,0 +1,129 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package jsonrpc + +import ( + "context" + "fmt" + awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + "github.com/aws/smithy-go/middleware" + smithyhttp "github.com/aws/smithy-go/transport/http" +) + +func (c *Client) SparseNullsOperation(ctx context.Context, params *SparseNullsOperationInput, optFns ...func(*Options)) (*SparseNullsOperationOutput, error) { + if params == nil { + params = &SparseNullsOperationInput{} + } + + result, metadata, err := c.invokeOperation(ctx, "SparseNullsOperation", params, optFns, c.addOperationSparseNullsOperationMiddlewares) + if err != nil { + return nil, err + } + + out := result.(*SparseNullsOperationOutput) + out.ResultMetadata = metadata + return out, nil +} + +type SparseNullsOperationInput struct { + SparseStringList []*string + + SparseStringMap map[string]*string + + noSmithyDocumentSerde +} + +type SparseNullsOperationOutput struct { + SparseStringList []*string + + SparseStringMap map[string]*string + + // Metadata pertaining to the operation's result. + ResultMetadata middleware.Metadata + + noSmithyDocumentSerde +} + +func (c *Client) addOperationSparseNullsOperationMiddlewares(stack *middleware.Stack, options Options) (err error) { + if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil { + return err + } + err = stack.Serialize.Add(&awsAwsjson11_serializeOpSparseNullsOperation{}, middleware.After) + if err != nil { + return err + } + err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpSparseNullsOperation{}, middleware.After) + if err != nil { + return err + } + if err := addProtocolFinalizerMiddlewares(stack, options, "SparseNullsOperation"); err != nil { + return fmt.Errorf("add protocol finalizers: %v", err) + } + + if err = addlegacyEndpointContextSetter(stack, options); err != nil { + return err + } + if err = addSetLoggerMiddleware(stack, options); err != nil { + return err + } + if err = addClientRequestID(stack); err != nil { + return err + } + if err = addComputeContentLength(stack); err != nil { + return err + } + if err = addResolveEndpointMiddleware(stack, options); err != nil { + return err + } + if err = addComputePayloadSHA256(stack); err != nil { + return err + } + if err = addRetry(stack, options); err != nil { + return err + } + if err = addRawResponseToMetadata(stack); err != nil { + return err + } + if err = addRecordResponseTiming(stack); err != nil { + return err + } + if err = addClientUserAgent(stack, options); err != nil { + return err + } + if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { + return err + } + if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { + return err + } + if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil { + return err + } + if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSparseNullsOperation(options.Region), middleware.Before); err != nil { + return err + } + if err = addRecursionDetection(stack); err != nil { + return err + } + if err = addRequestIDRetrieverMiddleware(stack); err != nil { + return err + } + if err = addResponseErrorMiddleware(stack); err != nil { + return err + } + if err = addRequestResponseLogging(stack, options); err != nil { + return err + } + if err = addDisableHTTPSMiddleware(stack, options); err != nil { + return err + } + return nil +} + +func newServiceMetadataMiddleware_opSparseNullsOperation(region string) *awsmiddleware.RegisterServiceMetadata { + return &awsmiddleware.RegisterServiceMetadata{ + Region: region, + ServiceID: ServiceID, + OperationName: "SparseNullsOperation", + } +} diff --git a/internal/protocoltest/jsonrpc/api_op_SparseNullsOperation_test.go b/internal/protocoltest/jsonrpc/api_op_SparseNullsOperation_test.go new file mode 100644 index 00000000000..b8bb39a4e3e --- /dev/null +++ b/internal/protocoltest/jsonrpc/api_op_SparseNullsOperation_test.go @@ -0,0 +1,246 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package jsonrpc + +import ( + "bytes" + "context" + "github.com/aws/aws-sdk-go-v2/aws" + protocoltesthttp "github.com/aws/aws-sdk-go-v2/internal/protocoltest" + "github.com/aws/smithy-go/middleware" + smithyprivateprotocol "github.com/aws/smithy-go/private/protocol" + smithytesting "github.com/aws/smithy-go/testing" + smithyhttp "github.com/aws/smithy-go/transport/http" + "io" + "io/ioutil" + "net/http" + "net/url" + "testing" +) + +func TestClient_SparseNullsOperation_awsAwsjson11Serialize(t *testing.T) { + cases := map[string]struct { + Params *SparseNullsOperationInput + ExpectMethod string + ExpectURIPath string + ExpectQuery []smithytesting.QueryItem + RequireQuery []string + ForbidQuery []string + ExpectHeader http.Header + RequireHeader []string + ForbidHeader []string + Host *url.URL + BodyMediaType string + BodyAssert func(io.Reader) error + }{ + // Serializes null values in maps + "AwsJson11SparseMapsSerializeNullValues": { + Params: &SparseNullsOperationInput{ + SparseStringMap: map[string]*string{ + "foo": nil, + }, + }, + ExpectMethod: "POST", + ExpectURIPath: "/", + ExpectQuery: []smithytesting.QueryItem{}, + ExpectHeader: http.Header{ + "Content-Type": []string{"application/x-amz-json-1.1"}, + "X-Amz-Target": []string{"JsonProtocol.SparseNullsOperation"}, + }, + BodyMediaType: "application/json", + BodyAssert: func(actual io.Reader) error { + return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ + "sparseStringMap": { + "foo": null + } + }`)) + }, + }, + // Serializes null values in lists + "AwsJson11SparseListsSerializeNull": { + Params: &SparseNullsOperationInput{ + SparseStringList: []*string{ + nil, + }, + }, + ExpectMethod: "POST", + ExpectURIPath: "/", + ExpectQuery: []smithytesting.QueryItem{}, + ExpectHeader: http.Header{ + "Content-Type": []string{"application/x-amz-json-1.1"}, + "X-Amz-Target": []string{"JsonProtocol.SparseNullsOperation"}, + }, + BodyMediaType: "application/json", + BodyAssert: func(actual io.Reader) error { + return smithytesting.CompareJSONReaderBytes(actual, []byte(`{ + "sparseStringList": [ + null + ] + }`)) + }, + }, + } + for name, c := range cases { + t.Run(name, func(t *testing.T) { + actualReq := &http.Request{} + serverURL := "http://localhost:8888/" + if c.Host != nil { + u, err := url.Parse(serverURL) + if err != nil { + t.Fatalf("expect no error, got %v", err) + } + u.Path = c.Host.Path + u.RawPath = c.Host.RawPath + u.RawQuery = c.Host.RawQuery + serverURL = u.String() + } + client := New(Options{ + APIOptions: []func(*middleware.Stack) error{ + func(s *middleware.Stack) error { + s.Finalize.Clear() + s.Initialize.Remove(`OperationInputValidation`) + return nil + }, + }, + EndpointResolver: EndpointResolverFunc(func(region string, options EndpointResolverOptions) (e aws.Endpoint, err error) { + e.URL = serverURL + e.SigningRegion = "us-west-2" + return e, err + }), + HTTPClient: protocoltesthttp.NewClient(), + Region: "us-west-2", + }) + result, err := client.SparseNullsOperation(context.Background(), c.Params, func(options *Options) { + options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error { + return smithyprivateprotocol.AddCaptureRequestMiddleware(stack, actualReq) + }) + }) + if err != nil { + t.Fatalf("expect nil err, got %v", err) + } + if result == nil { + t.Fatalf("expect not nil result") + } + if e, a := c.ExpectMethod, actualReq.Method; e != a { + t.Errorf("expect %v method, got %v", e, a) + } + if e, a := c.ExpectURIPath, actualReq.URL.RawPath; e != a { + t.Errorf("expect %v path, got %v", e, a) + } + queryItems := smithytesting.ParseRawQuery(actualReq.URL.RawQuery) + smithytesting.AssertHasQuery(t, c.ExpectQuery, queryItems) + smithytesting.AssertHasQueryKeys(t, c.RequireQuery, queryItems) + smithytesting.AssertNotHaveQueryKeys(t, c.ForbidQuery, queryItems) + smithytesting.AssertHasHeader(t, c.ExpectHeader, actualReq.Header) + smithytesting.AssertHasHeaderKeys(t, c.RequireHeader, actualReq.Header) + smithytesting.AssertNotHaveHeaderKeys(t, c.ForbidHeader, actualReq.Header) + if c.BodyAssert != nil { + if err := c.BodyAssert(actualReq.Body); err != nil { + t.Errorf("expect body equal, got %v", err) + } + } + }) + } +} + +func TestClient_SparseNullsOperation_awsAwsjson11Deserialize(t *testing.T) { + cases := map[string]struct { + StatusCode int + Header http.Header + BodyMediaType string + Body []byte + ExpectResult *SparseNullsOperationOutput + }{ + // Deserializes null values in maps + "AwsJson11SparseMapsDeserializeNullValues": { + StatusCode: 200, + Header: http.Header{ + "Content-Type": []string{"application/x-amz-json-1.1"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "sparseStringMap": { + "foo": null + } + }`), + ExpectResult: &SparseNullsOperationOutput{ + SparseStringMap: map[string]*string{ + "foo": nil, + }, + }, + }, + // Deserializes null values in lists + "AwsJson11SparseListsDeserializeNull": { + StatusCode: 200, + Header: http.Header{ + "Content-Type": []string{"application/x-amz-json-1.1"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "sparseStringList": [ + null + ] + }`), + ExpectResult: &SparseNullsOperationOutput{ + SparseStringList: []*string{ + nil, + }, + }, + }, + } + for name, c := range cases { + t.Run(name, func(t *testing.T) { + serverURL := "http://localhost:8888/" + client := New(Options{ + HTTPClient: smithyhttp.ClientDoFunc(func(r *http.Request) (*http.Response, error) { + headers := http.Header{} + for k, vs := range c.Header { + for _, v := range vs { + headers.Add(k, v) + } + } + if len(c.BodyMediaType) != 0 && len(headers.Values("Content-Type")) == 0 { + headers.Set("Content-Type", c.BodyMediaType) + } + response := &http.Response{ + StatusCode: c.StatusCode, + Header: headers, + Request: r, + } + if len(c.Body) != 0 { + response.ContentLength = int64(len(c.Body)) + response.Body = ioutil.NopCloser(bytes.NewReader(c.Body)) + } else { + + response.Body = http.NoBody + } + return response, nil + }), + APIOptions: []func(*middleware.Stack) error{ + func(s *middleware.Stack) error { + s.Finalize.Clear() + s.Initialize.Remove(`OperationInputValidation`) + return nil + }, + }, + EndpointResolver: EndpointResolverFunc(func(region string, options EndpointResolverOptions) (e aws.Endpoint, err error) { + e.URL = serverURL + e.SigningRegion = "us-west-2" + return e, err + }), + Region: "us-west-2", + }) + var params SparseNullsOperationInput + result, err := client.SparseNullsOperation(context.Background(), ¶ms) + if err != nil { + t.Fatalf("expect nil err, got %v", err) + } + if result == nil { + t.Fatalf("expect not nil result") + } + if err := smithytesting.CompareValues(c.ExpectResult, result); err != nil { + t.Errorf("expect c.ExpectResult value match:\n%v", err) + } + }) + } +} diff --git a/internal/protocoltest/jsonrpc/deserializers.go b/internal/protocoltest/jsonrpc/deserializers.go index a134a926e1d..5c2facf352b 100644 --- a/internal/protocoltest/jsonrpc/deserializers.go +++ b/internal/protocoltest/jsonrpc/deserializers.go @@ -1490,6 +1490,110 @@ func awsAwsjson11_deserializeOpErrorSimpleScalarProperties(response *smithyhttp. } } +type awsAwsjson11_deserializeOpSparseNullsOperation struct { +} + +func (*awsAwsjson11_deserializeOpSparseNullsOperation) ID() string { + return "OperationDeserializer" +} + +func (m *awsAwsjson11_deserializeOpSparseNullsOperation) HandleDeserialize(ctx context.Context, in middleware.DeserializeInput, next middleware.DeserializeHandler) ( + out middleware.DeserializeOutput, metadata middleware.Metadata, err error, +) { + out, metadata, err = next.HandleDeserialize(ctx, in) + if err != nil { + return out, metadata, err + } + + response, ok := out.RawResponse.(*smithyhttp.Response) + if !ok { + return out, metadata, &smithy.DeserializationError{Err: fmt.Errorf("unknown transport type %T", out.RawResponse)} + } + + if response.StatusCode < 200 || response.StatusCode >= 300 { + return out, metadata, awsAwsjson11_deserializeOpErrorSparseNullsOperation(response, &metadata) + } + output := &SparseNullsOperationOutput{} + out.Result = output + + var buff [1024]byte + ringBuffer := smithyio.NewRingBuffer(buff[:]) + + body := io.TeeReader(response.Body, ringBuffer) + decoder := json.NewDecoder(body) + decoder.UseNumber() + var shape interface{} + if err := decoder.Decode(&shape); err != nil && err != io.EOF { + var snapshot bytes.Buffer + io.Copy(&snapshot, ringBuffer) + err = &smithy.DeserializationError{ + Err: fmt.Errorf("failed to decode response body, %w", err), + Snapshot: snapshot.Bytes(), + } + return out, metadata, err + } + + err = awsAwsjson11_deserializeOpDocumentSparseNullsOperationOutput(&output, shape) + if err != nil { + var snapshot bytes.Buffer + io.Copy(&snapshot, ringBuffer) + err = &smithy.DeserializationError{ + Err: fmt.Errorf("failed to decode response body, %w", err), + Snapshot: snapshot.Bytes(), + } + return out, metadata, err + } + + return out, metadata, err +} + +func awsAwsjson11_deserializeOpErrorSparseNullsOperation(response *smithyhttp.Response, metadata *middleware.Metadata) error { + var errorBuffer bytes.Buffer + if _, err := io.Copy(&errorBuffer, response.Body); err != nil { + return &smithy.DeserializationError{Err: fmt.Errorf("failed to copy error response body, %w", err)} + } + errorBody := bytes.NewReader(errorBuffer.Bytes()) + + errorCode := "UnknownError" + errorMessage := errorCode + + headerCode := response.Header.Get("X-Amzn-ErrorType") + + var buff [1024]byte + ringBuffer := smithyio.NewRingBuffer(buff[:]) + + body := io.TeeReader(errorBody, ringBuffer) + decoder := json.NewDecoder(body) + decoder.UseNumber() + bodyInfo, err := getProtocolErrorInfo(decoder) + if err != nil { + var snapshot bytes.Buffer + io.Copy(&snapshot, ringBuffer) + err = &smithy.DeserializationError{ + Err: fmt.Errorf("failed to decode response body, %w", err), + Snapshot: snapshot.Bytes(), + } + return err + } + + errorBody.Seek(0, io.SeekStart) + if typ, ok := resolveProtocolErrorType(headerCode, bodyInfo); ok { + errorCode = restjson.SanitizeErrorCode(typ) + } + if len(bodyInfo.Message) != 0 { + errorMessage = bodyInfo.Message + } + switch { + default: + genericError := &smithy.GenericAPIError{ + Code: errorCode, + Message: errorMessage, + } + return genericError + + } +} + func awsAwsjson11_deserializeErrorComplexError(response *smithyhttp.Response, errorBody *bytes.Reader) error { var buff [1024]byte ringBuffer := smithyio.NewRingBuffer(buff[:]) @@ -3679,16 +3783,6 @@ func awsAwsjson11_deserializeOpDocumentNullOperationOutput(v **NullOperationOutp for key, value := range shape { switch key { - case "sparseStringList": - if err := awsAwsjson11_deserializeDocumentSparseStringList(&sv.SparseStringList, value); err != nil { - return err - } - - case "sparseStringMap": - if err := awsAwsjson11_deserializeDocumentSparseStringMap(&sv.SparseStringMap, value); err != nil { - return err - } - case "string": if value != nil { jtv, ok := value.(string) @@ -3882,6 +3976,47 @@ func awsAwsjson11_deserializeOpDocumentSimpleScalarPropertiesOutput(v **SimpleSc return nil } +func awsAwsjson11_deserializeOpDocumentSparseNullsOperationOutput(v **SparseNullsOperationOutput, value interface{}) error { + if v == nil { + return fmt.Errorf("unexpected nil of type %T", v) + } + if value == nil { + return nil + } + + shape, ok := value.(map[string]interface{}) + if !ok { + return fmt.Errorf("unexpected JSON type %v", value) + } + + var sv *SparseNullsOperationOutput + if *v == nil { + sv = &SparseNullsOperationOutput{} + } else { + sv = *v + } + + for key, value := range shape { + switch key { + case "sparseStringList": + if err := awsAwsjson11_deserializeDocumentSparseStringList(&sv.SparseStringList, value); err != nil { + return err + } + + case "sparseStringMap": + if err := awsAwsjson11_deserializeDocumentSparseStringMap(&sv.SparseStringMap, value); err != nil { + return err + } + + default: + _, _ = key, value + + } + } + *v = sv + return nil +} + type protocolErrorInfo struct { Type string `json:"__type"` Message string diff --git a/internal/protocoltest/jsonrpc/generated.json b/internal/protocoltest/jsonrpc/generated.json index 55aa15f9c5e..0a51a461560 100644 --- a/internal/protocoltest/jsonrpc/generated.json +++ b/internal/protocoltest/jsonrpc/generated.json @@ -38,6 +38,8 @@ "api_op_PutWithContentEncoding_test.go", "api_op_SimpleScalarProperties.go", "api_op_SimpleScalarProperties_test.go", + "api_op_SparseNullsOperation.go", + "api_op_SparseNullsOperation_test.go", "auth.go", "deserializers.go", "doc.go", diff --git a/internal/protocoltest/jsonrpc/serializers.go b/internal/protocoltest/jsonrpc/serializers.go index f18b86c6df9..fe91e562acf 100644 --- a/internal/protocoltest/jsonrpc/serializers.go +++ b/internal/protocoltest/jsonrpc/serializers.go @@ -814,6 +814,61 @@ func (m *awsAwsjson11_serializeOpSimpleScalarProperties) HandleSerialize(ctx con return next.HandleSerialize(ctx, in) } + +type awsAwsjson11_serializeOpSparseNullsOperation struct { +} + +func (*awsAwsjson11_serializeOpSparseNullsOperation) ID() string { + return "OperationSerializer" +} + +func (m *awsAwsjson11_serializeOpSparseNullsOperation) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) ( + out middleware.SerializeOutput, metadata middleware.Metadata, err error, +) { + request, ok := in.Request.(*smithyhttp.Request) + if !ok { + return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown transport type %T", in.Request)} + } + + input, ok := in.Parameters.(*SparseNullsOperationInput) + _ = input + if !ok { + return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown input parameters type %T", in.Parameters)} + } + + operationPath := "/" + if len(request.Request.URL.Path) == 0 { + request.Request.URL.Path = operationPath + } else { + request.Request.URL.Path = path.Join(request.Request.URL.Path, operationPath) + if request.Request.URL.Path != "/" && operationPath[len(operationPath)-1] == '/' { + request.Request.URL.Path += "/" + } + } + request.Request.Method = "POST" + httpBindingEncoder, err := httpbinding.NewEncoder(request.URL.Path, request.URL.RawQuery, request.Header) + if err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + httpBindingEncoder.SetHeader("Content-Type").String("application/x-amz-json-1.1") + httpBindingEncoder.SetHeader("X-Amz-Target").String("JsonProtocol.SparseNullsOperation") + + jsonEncoder := smithyjson.NewEncoder() + if err := awsAwsjson11_serializeOpDocumentSparseNullsOperationInput(input, jsonEncoder.Value); err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + + if request, err = request.SetStream(bytes.NewReader(jsonEncoder.Bytes())); err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + + if request.Request, err = httpBindingEncoder.Encode(request.Request); err != nil { + return out, metadata, &smithy.SerializationError{Err: err} + } + in.Request = request + + return next.HandleSerialize(ctx, in) +} func awsAwsjson11_serializeDocumentDocument(v document.Interface, value smithyjson.Value) error { if v == nil { return nil @@ -1606,20 +1661,6 @@ func awsAwsjson11_serializeOpDocumentNullOperationInput(v *NullOperationInput, v object := value.Object() defer object.Close() - if v.SparseStringList != nil { - ok := object.Key("sparseStringList") - if err := awsAwsjson11_serializeDocumentSparseStringList(v.SparseStringList, ok); err != nil { - return err - } - } - - if v.SparseStringMap != nil { - ok := object.Key("sparseStringMap") - if err := awsAwsjson11_serializeDocumentSparseStringMap(v.SparseStringMap, ok); err != nil { - return err - } - } - if v.String_ != nil { ok := object.Key("string") ok.String(*v.String_) @@ -1713,3 +1754,24 @@ func awsAwsjson11_serializeOpDocumentSimpleScalarPropertiesInput(v *SimpleScalar return nil } + +func awsAwsjson11_serializeOpDocumentSparseNullsOperationInput(v *SparseNullsOperationInput, value smithyjson.Value) error { + object := value.Object() + defer object.Close() + + if v.SparseStringList != nil { + ok := object.Key("sparseStringList") + if err := awsAwsjson11_serializeDocumentSparseStringList(v.SparseStringList, ok); err != nil { + return err + } + } + + if v.SparseStringMap != nil { + ok := object.Key("sparseStringMap") + if err := awsAwsjson11_serializeDocumentSparseStringMap(v.SparseStringMap, ok); err != nil { + return err + } + } + + return nil +} diff --git a/internal/protocoltest/jsonrpc/snapshot_test.go b/internal/protocoltest/jsonrpc/snapshot_test.go index 77fd3068fc8..8bc0da0c081 100644 --- a/internal/protocoltest/jsonrpc/snapshot_test.go +++ b/internal/protocoltest/jsonrpc/snapshot_test.go @@ -241,6 +241,18 @@ func TestCheckSnapshot_SimpleScalarProperties(t *testing.T) { t.Fatal(err) } } + +func TestCheckSnapshot_SparseNullsOperation(t *testing.T) { + svc := New(Options{}) + _, err := svc.SparseNullsOperation(context.Background(), nil, func(o *Options) { + o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error { + return testSnapshot(stack, "SparseNullsOperation") + }) + }) + if _, ok := err.(snapshotOK); !ok && err != nil { + t.Fatal(err) + } +} func TestUpdateSnapshot_DatetimeOffsets(t *testing.T) { svc := New(Options{}) _, err := svc.DatetimeOffsets(context.Background(), nil, func(o *Options) { @@ -420,3 +432,15 @@ func TestUpdateSnapshot_SimpleScalarProperties(t *testing.T) { t.Fatal(err) } } + +func TestUpdateSnapshot_SparseNullsOperation(t *testing.T) { + svc := New(Options{}) + _, err := svc.SparseNullsOperation(context.Background(), nil, func(o *Options) { + o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error { + return updateSnapshot(stack, "SparseNullsOperation") + }) + }) + if _, ok := err.(snapshotOK); !ok && err != nil { + t.Fatal(err) + } +} diff --git a/internal/protocoltest/jsonrpc10/api_op_JsonUnions_test.go b/internal/protocoltest/jsonrpc10/api_op_JsonUnions_test.go index cc2609a8fe9..f3117b9b246 100644 --- a/internal/protocoltest/jsonrpc10/api_op_JsonUnions_test.go +++ b/internal/protocoltest/jsonrpc10/api_op_JsonUnions_test.go @@ -525,6 +525,35 @@ func TestClient_JsonUnions_awsAwsjson10Deserialize(t *testing.T) { }}, }, }, + // Allows for : null to be set for all unset fields + "AwsJson10DeserializeAllowNulls": { + StatusCode: 200, + Header: http.Header{ + "Content-Type": []string{"application/x-amz-json-1.0"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "contents": { + "stringValue": null, + "booleanValue": null, + "numberValue": null, + "blobValue": null, + "timestampValue": null, + "enumValue": null, + "intEnumValue": null, + "listValue": null, + "mapValue": null, + "structureValue": { + "hi": "hello" + } + } + }`), + ExpectResult: &JsonUnionsOutput{ + Contents: &types.MyUnionMemberStructureValue{Value: types.GreetingStruct{ + Hi: ptr.String("hello"), + }}, + }, + }, } for name, c := range cases { t.Run(name, func(t *testing.T) { diff --git a/internal/protocoltest/restxml/api_op_HttpPayloadWithUnion_test.go b/internal/protocoltest/restxml/api_op_HttpPayloadWithUnion_test.go index eac31d0d219..77d3422ab71 100644 --- a/internal/protocoltest/restxml/api_op_HttpPayloadWithUnion_test.go +++ b/internal/protocoltest/restxml/api_op_HttpPayloadWithUnion_test.go @@ -62,9 +62,6 @@ func TestClient_HttpPayloadWithUnion_awsRestxmlSerialize(t *testing.T) { ExpectMethod: "PUT", ExpectURIPath: "/HttpPayloadWithUnion", ExpectQuery: []smithytesting.QueryItem{}, - ExpectHeader: http.Header{ - "Content-Type": []string{"application/xml"}, - }, BodyAssert: func(actual io.Reader) error { return smithytesting.CompareReaderEmpty(actual) },