diff --git a/internal/protocoltest/jsonrpc/api_op_GreetingWithErrors.go b/internal/protocoltest/jsonrpc/api_op_GreetingWithErrors.go new file mode 100644 index 00000000000..59728386ddc --- /dev/null +++ b/internal/protocoltest/jsonrpc/api_op_GreetingWithErrors.go @@ -0,0 +1,84 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. +package jsonrpc + +import ( + "context" + awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + "github.com/aws/aws-sdk-go-v2/aws/retry" + "github.com/aws/aws-sdk-go-v2/aws/signer/v4" + smithy "github.com/awslabs/smithy-go" + "github.com/awslabs/smithy-go/middleware" + smithyhttp "github.com/awslabs/smithy-go/transport/http" +) + +// This operation has three possible return values: +// +// * A successful response in +// the form of GreetingWithErrorsOutput +// +// * An InvalidGreeting error. +// +// * A +// ComplexError error. +// +// Implementations must be able to successfully take a +// response and properly deserialize successful and error responses. +func (c *Client) GreetingWithErrors(ctx context.Context, params *GreetingWithErrorsInput, optFns ...func(*Options)) (*GreetingWithErrorsOutput, error) { + stack := middleware.NewStack("GreetingWithErrors", smithyhttp.NewStackRequest) + options := c.options.Copy() + for _, fn := range optFns { + fn(&options) + } + awsmiddleware.AddRequestInvocationIDMiddleware(stack) + awsmiddleware.AddResolveServiceEndpointMiddleware(stack, options) + v4.AddComputePayloadSHA256Middleware(stack) + retry.AddRetryMiddlewares(stack, options) + v4.AddHTTPSignerMiddleware(stack, options) + awsmiddleware.AddAttemptClockSkewMiddleware(stack) + stack.Initialize.Add(newServiceMetadataMiddleware_opGreetingWithErrors(options.Region), middleware.Before) + addawsAwsjson11_serdeOpGreetingWithErrorsMiddlewares(stack) + + for _, fn := range options.APIOptions { + if err := fn(stack); err != nil { + return nil, err + } + } + handler := middleware.DecorateHandler(smithyhttp.NewClientHandler(options.HTTPClient), stack) + result, metadata, err := handler.Handle(ctx, params) + if err != nil { + return nil, &smithy.OperationError{ + ServiceID: c.ServiceID(), + OperationName: "GreetingWithErrors", + Err: err, + } + } + out := result.(*GreetingWithErrorsOutput) + out.ResultMetadata = metadata + return out, nil +} + +type GreetingWithErrorsInput struct { +} + +type GreetingWithErrorsOutput struct { + Greeting *string + + // Metadata pertaining to the operation's result. + ResultMetadata middleware.Metadata +} + +func addawsAwsjson11_serdeOpGreetingWithErrorsMiddlewares(stack *middleware.Stack) { + stack.Serialize.Add(&awsAwsjson11_serializeOpGreetingWithErrors{}, middleware.After) + stack.Deserialize.Add(&awsAwsjson11_deserializeOpGreetingWithErrors{}, middleware.After) +} + +func newServiceMetadataMiddleware_opGreetingWithErrors(region string) awsmiddleware.RegisterServiceMetadata { + return awsmiddleware.RegisterServiceMetadata{ + Region: region, + ServiceName: "Json Protocol", + ServiceID: "jsonprotocol", + EndpointPrefix: "jsonprotocol", + SigningName: "foo", + OperationName: "GreetingWithErrors", + } +} diff --git a/internal/protocoltest/jsonrpc/api_op_GreetingWithErrors_test.go b/internal/protocoltest/jsonrpc/api_op_GreetingWithErrors_test.go new file mode 100644 index 00000000000..12ced82f7ad --- /dev/null +++ b/internal/protocoltest/jsonrpc/api_op_GreetingWithErrors_test.go @@ -0,0 +1,216 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. +package jsonrpc + +import ( + "bytes" + "context" + "errors" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc/types" + "github.com/awslabs/smithy-go/middleware" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "io" + "net/http" + "net/http/httptest" + "strconv" + "testing" +) + +func TestClient_GreetingWithErrors_InvalidGreeting_awsAwsjson11Deserialize(t *testing.T) { + cases := map[string]struct { + StatusCode int + Header http.Header + BodyMediaType string + Body []byte + ExpectError *types.InvalidGreeting + }{ + // Parses simple JSON errors + "AwsJson11InvalidGreetingError": { + StatusCode: 400, + Header: http.Header{ + "Content-Type": []string{"application/x-amz-json-1.1"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "__type": "InvalidGreeting", + "Message": "Hi" + }`), + ExpectError: &types.InvalidGreeting{}, + }, + } + for name, c := range cases { + t.Run(name, func(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + for k, vs := range c.Header { + for _, v := range vs { + w.Header().Add(k, v) + } + } + if len(c.BodyMediaType) != 0 && len(w.Header().Values("Content-Type")) == 0 { + w.Header().Set("Content-Type", c.BodyMediaType) + } + if len(c.Body) != 0 { + w.Header().Set("Content-Length", strconv.Itoa(len(c.Body))) + } + w.WriteHeader(c.StatusCode) + if len(c.Body) != 0 { + if _, err := io.Copy(w, bytes.NewReader(c.Body)); err != nil { + t.Errorf("failed to write response body, %v", err) + } + } + })) + defer server.Close() + client := New(Options{ + APIOptions: []APIOptionFunc{ + func(s *middleware.Stack) error { + s.Build.Clear() + s.Finalize.Clear() + return nil + }, + }, + EndpointResolver: aws.EndpointResolverFunc(func(service, region string) (e aws.Endpoint, err error) { + e.URL = server.URL + e.SigningRegion = "us-west-2" + return e, err + }), + HTTPClient: aws.NewBuildableHTTPClient(), + Region: "us-west-2", + }) + var params GreetingWithErrorsInput + result, err := client.GreetingWithErrors(context.Background(), ¶ms) + if err == nil { + t.Fatalf("expect not nil err") + } + if result != nil { + t.Fatalf("expect nil result, got %v", result) + } + var opErr interface { + Service() string + Operation() string + } + if !errors.As(err, &opErr) { + t.Fatalf("expect *types.InvalidGreeting operation error, got %T", err) + } + if e, a := client.ServiceID(), opErr.Service(); e != a { + t.Errorf("expect %v operation service name, got %v", e, a) + } + if e, a := "GreetingWithErrors", opErr.Operation(); e != a { + t.Errorf("expect %v operation service name, got %v", e, a) + } + var actualErr *types.InvalidGreeting + if !errors.As(err, &actualErr) { + t.Fatalf("expect *types.InvalidGreeting result error, got %T", err) + } + if diff := cmp.Diff(c.ExpectError, actualErr, cmpopts.IgnoreUnexported(middleware.Metadata{})); len(diff) != 0 { + t.Errorf("expect c.ExpectError value match:\n%s", diff) + } + }) + } +} + +func TestClient_GreetingWithErrors_ComplexError_awsAwsjson11Deserialize(t *testing.T) { + cases := map[string]struct { + StatusCode int + Header http.Header + BodyMediaType string + Body []byte + ExpectError *types.ComplexError + }{ + // Parses a complex error with no message member + "AwsJson11ComplexError": { + StatusCode: 400, + Header: http.Header{ + "Content-Type": []string{"application/x-amz-json-1.1"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "__type": "ComplexError", + "TopLevel": "Top level", + "Nested": { + "Fooooo": "bar" + } + }`), + ExpectError: &types.ComplexError{}, + }, + "AwsJson11EmptyComplexError": { + StatusCode: 400, + Header: http.Header{ + "Content-Type": []string{"application/x-amz-json-1.1"}, + }, + BodyMediaType: "application/json", + Body: []byte(`{ + "__type": "ComplexError" + }`), + ExpectError: &types.ComplexError{}, + }, + } + for name, c := range cases { + t.Run(name, func(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + for k, vs := range c.Header { + for _, v := range vs { + w.Header().Add(k, v) + } + } + if len(c.BodyMediaType) != 0 && len(w.Header().Values("Content-Type")) == 0 { + w.Header().Set("Content-Type", c.BodyMediaType) + } + if len(c.Body) != 0 { + w.Header().Set("Content-Length", strconv.Itoa(len(c.Body))) + } + w.WriteHeader(c.StatusCode) + if len(c.Body) != 0 { + if _, err := io.Copy(w, bytes.NewReader(c.Body)); err != nil { + t.Errorf("failed to write response body, %v", err) + } + } + })) + defer server.Close() + client := New(Options{ + APIOptions: []APIOptionFunc{ + func(s *middleware.Stack) error { + s.Build.Clear() + s.Finalize.Clear() + return nil + }, + }, + EndpointResolver: aws.EndpointResolverFunc(func(service, region string) (e aws.Endpoint, err error) { + e.URL = server.URL + e.SigningRegion = "us-west-2" + return e, err + }), + HTTPClient: aws.NewBuildableHTTPClient(), + Region: "us-west-2", + }) + var params GreetingWithErrorsInput + result, err := client.GreetingWithErrors(context.Background(), ¶ms) + if err == nil { + t.Fatalf("expect not nil err") + } + if result != nil { + t.Fatalf("expect nil result, got %v", result) + } + var opErr interface { + Service() string + Operation() string + } + if !errors.As(err, &opErr) { + t.Fatalf("expect *types.ComplexError operation error, got %T", err) + } + if e, a := client.ServiceID(), opErr.Service(); e != a { + t.Errorf("expect %v operation service name, got %v", e, a) + } + if e, a := "GreetingWithErrors", opErr.Operation(); e != a { + t.Errorf("expect %v operation service name, got %v", e, a) + } + var actualErr *types.ComplexError + if !errors.As(err, &actualErr) { + t.Fatalf("expect *types.ComplexError result error, got %T", err) + } + if diff := cmp.Diff(c.ExpectError, actualErr, cmpopts.IgnoreUnexported(middleware.Metadata{})); len(diff) != 0 { + t.Errorf("expect c.ExpectError value match:\n%s", diff) + } + }) + } +} diff --git a/internal/protocoltest/jsonrpc/deserializers.go b/internal/protocoltest/jsonrpc/deserializers.go index eb9423d7e18..1f6ab8efef4 100644 --- a/internal/protocoltest/jsonrpc/deserializers.go +++ b/internal/protocoltest/jsonrpc/deserializers.go @@ -62,6 +62,51 @@ func (m *awsAwsjson11_deserializeOpEmptyOperation) HandleDeserialize(ctx context return out, metadata, err } +type awsAwsjson11_deserializeOpGreetingWithErrors struct { +} + +func (*awsAwsjson11_deserializeOpGreetingWithErrors) ID() string { + return "awsAwsjson11_deserializeOpGreetingWithErrors" +} + +func (m *awsAwsjson11_deserializeOpGreetingWithErrors) 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)} + } + + output := &GreetingWithErrorsOutput{} + out.Result = output + + buff := make([]byte, 1024) + ringBuffer := smithyio.NewRingBuffer(buff) + + body := io.TeeReader(response.Body, ringBuffer) + defer response.Body.Close() + + decoder := json.NewDecoder(body) + decoder.UseNumber() + + err = awsAwsjson11_deserializeDocumentGreetingWithErrorsOutput(&output, decoder) + 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 +} + type awsAwsjson11_deserializeOpJsonEnums struct { } @@ -290,6 +335,7 @@ func awsAwsjson11_deserializeDocumentDocument(v *smithy.Document, decoder *json. if v == nil { return fmt.Errorf("unexpected nil of type %T", v) } + // TODO: implement document serialization. return nil } @@ -376,12 +422,10 @@ func awsAwsjson11_deserializeDocumentKitchenSink(v **types.KitchenSink, decoder } switch t { case "Blob": - var bs []byte - err := decoder.Decode(&bs) + err := decoder.Decode(&sv.Blob) if err != nil { return err } - sv.Blob = bs case "Boolean": val, err := decoder.Token() @@ -608,8 +652,7 @@ func awsAwsjson11_deserializeDocumentKitchenSink(v **types.KitchenSink, decoder if err != nil { return err } - t := smithytime.ParseEpochSeconds(f64) - sv.Timestamp = &t + sv.Timestamp = ptr.Time(smithytime.ParseEpochSeconds(f64)) } case "UnixTimestamp": @@ -626,8 +669,7 @@ func awsAwsjson11_deserializeDocumentKitchenSink(v **types.KitchenSink, decoder if err != nil { return err } - t := smithytime.ParseEpochSeconds(f64) - sv.UnixTimestamp = &t + sv.UnixTimestamp = ptr.Time(smithytime.ParseEpochSeconds(f64)) } default: @@ -1630,6 +1672,70 @@ func awsAwsjson11_deserializeDocumentEmptyOperationOutput(v **EmptyOperationOutp return nil } +func awsAwsjson11_deserializeDocumentGreetingWithErrorsOutput(v **GreetingWithErrorsOutput, decoder *json.Decoder) error { + if v == nil { + return fmt.Errorf("unexpected nil of type %T", v) + } + startToken, err := decoder.Token() + if err == io.EOF { + return nil + } + if err != nil { + return err + } + if startToken == nil { + return nil + } + if t, ok := startToken.(json.Delim); !ok || t != '{' { + return fmt.Errorf("expect `{` as start token") + } + + var sv *GreetingWithErrorsOutput + if *v == nil { + sv = &GreetingWithErrorsOutput{} + } else { + sv = *v + } + + for decoder.More() { + t, err := decoder.Token() + if err != nil { + return err + } + switch t { + case "greeting": + val, err := decoder.Token() + if err != nil { + return err + } + if val != nil { + jtv, ok := val.(string) + if !ok { + return fmt.Errorf("expected String to be of type string, got %T instead", val) + } + sv.Greeting = &jtv + } + + default: + err := restjson.DiscardUnknownField(decoder) + if err != nil { + return err + } + + } + } + endToken, err := decoder.Token() + if err != nil { + return err + } + if t, ok := endToken.(json.Delim); !ok || t != '}' { + return fmt.Errorf("expect `}` as end token") + } + + *v = sv + return nil +} + func awsAwsjson11_deserializeDocumentJsonEnumsOutput(v **JsonEnumsOutput, decoder *json.Decoder) error { if v == nil { return fmt.Errorf("unexpected nil of type %T", v) @@ -1767,12 +1873,10 @@ func awsAwsjson11_deserializeDocumentKitchenSinkOperationOutput(v **KitchenSinkO } switch t { case "Blob": - var bs []byte - err := decoder.Decode(&bs) + err := decoder.Decode(&sv.Blob) if err != nil { return err } - sv.Blob = bs case "Boolean": val, err := decoder.Token() @@ -1999,8 +2103,7 @@ func awsAwsjson11_deserializeDocumentKitchenSinkOperationOutput(v **KitchenSinkO if err != nil { return err } - t := smithytime.ParseEpochSeconds(f64) - sv.Timestamp = &t + sv.Timestamp = ptr.Time(smithytime.ParseEpochSeconds(f64)) } case "UnixTimestamp": @@ -2017,8 +2120,7 @@ func awsAwsjson11_deserializeDocumentKitchenSinkOperationOutput(v **KitchenSinkO if err != nil { return err } - t := smithytime.ParseEpochSeconds(f64) - sv.UnixTimestamp = &t + sv.UnixTimestamp = ptr.Time(smithytime.ParseEpochSeconds(f64)) } default: diff --git a/internal/protocoltest/jsonrpc/go.mod b/internal/protocoltest/jsonrpc/go.mod index f79f87783a2..cf5c8fab3ba 100644 --- a/internal/protocoltest/jsonrpc/go.mod +++ b/internal/protocoltest/jsonrpc/go.mod @@ -3,7 +3,7 @@ module github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc go 1.14 require ( - github.com/aws/aws-sdk-go-v2 v0.0.0-20200629185603-8a40db2118b1 - github.com/awslabs/smithy-go v0.0.0-20200626165009-2c11297eadd1 + github.com/aws/aws-sdk-go-v2 v0.21.1-0.20200630225515-ddc322369f03 + github.com/awslabs/smithy-go v0.0.0-20200626165807-d2e64072bf43 github.com/google/go-cmp v0.4.1 ) diff --git a/internal/protocoltest/jsonrpc/go.sum b/internal/protocoltest/jsonrpc/go.sum new file mode 100644 index 00000000000..3eb7154cf0b --- /dev/null +++ b/internal/protocoltest/jsonrpc/go.sum @@ -0,0 +1,21 @@ +github.com/aws/aws-sdk-go-v2 v0.21.1-0.20200630225515-ddc322369f03 h1:BAsBMmgpp5VPGjIlodZbY9rnOXsL60WcN0xw8R8LADY= +github.com/aws/aws-sdk-go-v2 v0.21.1-0.20200630225515-ddc322369f03/go.mod h1:4pVqQk1zf8gdDZt6lzN4pC8UdJFERj5St6QeWx+BK0Q= +github.com/awslabs/smithy-go v0.0.0-20200626165807-d2e64072bf43 h1:UNbzZEa8aoCAIwve5rF5TgQ1Xcgb49TKdjyIn/ki6SY= +github.com/awslabs/smithy-go v0.0.0-20200626165807-d2e64072bf43/go.mod h1:hPOQwnmBLHsUphH13tVSjQhTAFma0/0XoZGbBcOuABI= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/google/go-cmp v0.4.1 h1:/exdXoGamhu5ONeUJH0deniYLWYvQwW66yvlfiiKTu0= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/protocoltest/jsonrpc/serializers.go b/internal/protocoltest/jsonrpc/serializers.go index bbee71084da..8613729198f 100644 --- a/internal/protocoltest/jsonrpc/serializers.go +++ b/internal/protocoltest/jsonrpc/serializers.go @@ -60,6 +60,52 @@ func (m *awsAwsjson11_serializeOpEmptyOperation) HandleSerialize(ctx context.Con return next.HandleSerialize(ctx, in) } +type awsAwsjson11_serializeOpGreetingWithErrors struct { +} + +func (*awsAwsjson11_serializeOpGreetingWithErrors) ID() string { + return "awsAwsjson11_serializeOpGreetingWithErrors" +} + +func (m *awsAwsjson11_serializeOpGreetingWithErrors) 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.(*GreetingWithErrorsInput) + if !ok { + return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown input parameters type %T", in.Parameters)} + } + + 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.GreetingWithErrors") + + jsonEncoder := smithyjson.NewEncoder() + if err := awsAwsjson11_serializeDocumentGreetingWithErrorsInput(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) +} + type awsAwsjson11_serializeOpJsonEnums struct { } @@ -726,6 +772,13 @@ func awsAwsjson11_serializeDocumentEmptyOperationInput(v *EmptyOperationInput, v return nil } +func awsAwsjson11_serializeDocumentGreetingWithErrorsInput(v *GreetingWithErrorsInput, value smithyjson.Value) error { + object := value.Object() + defer object.Close() + + return nil +} + func awsAwsjson11_serializeDocumentJsonEnumsInput(v *JsonEnumsInput, value smithyjson.Value) error { object := value.Object() defer object.Close() diff --git a/internal/protocoltest/jsonrpc/types/errors.go b/internal/protocoltest/jsonrpc/types/errors.go index 97ef20c16e1..a7dec7de6c4 100644 --- a/internal/protocoltest/jsonrpc/types/errors.go +++ b/internal/protocoltest/jsonrpc/types/errors.go @@ -7,6 +7,38 @@ import ( "github.com/awslabs/smithy-go/ptr" ) +// This error is thrown when a request is invalid. +type ComplexError struct { + Message *string + + TopLevel *string + Nested *ComplexNestedErrorData +} + +func (e *ComplexError) Error() string { + return fmt.Sprintf("%s: %s", e.ErrorCode(), e.ErrorMessage()) +} +func (e *ComplexError) ErrorMessage() string { + if e.Message == nil { + return "" + } + return *e.Message +} +func (e *ComplexError) ErrorCode() string { return "ComplexError" } +func (e *ComplexError) ErrorFault() smithy.ErrorFault { return smithy.FaultClient } +func (e *ComplexError) GetTopLevel() string { + return ptr.ToString(e.TopLevel) +} +func (e *ComplexError) HasTopLevel() bool { + return e.TopLevel != nil +} +func (e *ComplexError) GetNested() *ComplexNestedErrorData { + return e.Nested +} +func (e *ComplexError) HasNested() bool { + return e.Nested != nil +} + type ErrorWithMembers struct { Message *string @@ -87,3 +119,26 @@ func (e *ErrorWithoutMembers) ErrorMessage() string { } func (e *ErrorWithoutMembers) ErrorCode() string { return "ErrorWithoutMembers" } func (e *ErrorWithoutMembers) ErrorFault() smithy.ErrorFault { return smithy.FaultServer } + +// This error is thrown when an invalid greeting value is provided. +type InvalidGreeting struct { + Message *string +} + +func (e *InvalidGreeting) Error() string { + return fmt.Sprintf("%s: %s", e.ErrorCode(), e.ErrorMessage()) +} +func (e *InvalidGreeting) ErrorMessage() string { + if e.Message == nil { + return "" + } + return *e.Message +} +func (e *InvalidGreeting) ErrorCode() string { return "InvalidGreeting" } +func (e *InvalidGreeting) ErrorFault() smithy.ErrorFault { return smithy.FaultClient } +func (e *InvalidGreeting) GetMessage() string { + return ptr.ToString(e.Message) +} +func (e *InvalidGreeting) HasMessage() bool { + return e.Message != nil +} diff --git a/internal/protocoltest/jsonrpc/types/types.go b/internal/protocoltest/jsonrpc/types/types.go index 12f82efcec3..b2c7f266e5c 100644 --- a/internal/protocoltest/jsonrpc/types/types.go +++ b/internal/protocoltest/jsonrpc/types/types.go @@ -5,6 +5,10 @@ import ( "time" ) +type ComplexNestedErrorData struct { + Foo *string +} + type EmptyStruct struct { }