diff --git a/service/smithyprototype/lexruntimeservice/api_client.go b/service/smithyprototype/lexruntimeservice/api_client.go index 0ce8ec94417..3d47eca7a18 100644 --- a/service/smithyprototype/lexruntimeservice/api_client.go +++ b/service/smithyprototype/lexruntimeservice/api_client.go @@ -3,82 +3,106 @@ package lexruntimeservice import ( + "context" + "net/http" + "time" + "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/retry" - "github.com/aws/aws-sdk-go-v2/aws/signer/v4" - "github.com/aws/aws-sdk-go-v2/private/protocol/restjson" + v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" + awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" + "github.com/awslabs/smithy-go/middleware" ) -// Client provides the API operation methods for making requests to -// Amazon Lex Runtime Service. See this package's package overview docs -// for details on the service. -// -// The client's methods are safe to use concurrently. It is not safe to -// modify mutate any of the struct's properties though. +// Client provides the client for interacting with the Amazon Lex Runtime Service. type Client struct { - *aws.Client + serviceName string + serviceID string + endpointID string + options ClientOptions } -// Used for custom client initialization logic -var initClient func(*Client) +// ClientOptions provides the set of configurations that can be applied to the +// Client. Use functional options to modify this set when creating the client, +// or when invoking API operations. +type ClientOptions struct { + RegionID string -// Used for custom request initialization logic -var initRequest func(*Client, *aws.Request) + EndpointResolver aws.EndpointResolver + HTTPClient HTTPClient -const ( - ServiceName = "Amazon Lex Runtime Service" // Service's name - ServiceID = "LexRuntimeService" // Service's identifier - EndpointsID = "runtime.lex" // Service's Endpoint identifier -) + // Signer is the signer for the client. + SigningName string + Signer HTTPSigner -// New creates a new instance of the client from the provided Config. -// -// Example: -// // Create a client from just a config. -// svc := lexruntimeservice.New(myConfig) -func New(config aws.Config) *Client { - svc := &Client{ - Client: aws.NewClient( - config, - aws.Metadata{ - ServiceName: ServiceName, - ServiceID: ServiceID, - EndpointsID: EndpointsID, - SigningName: "lex", - SigningRegion: config.Region, - APIVersion: "2016-11-28", - }, - ), - } + APIOptions []APIOptionFunc - if config.Retryer == nil { - svc.Retryer = retry.NewStandard() - } + Retryer aws.Retryer + LogLevel aws.LogLevel + Logger aws.Logger +} + +// HTTPSigner provides the interface for implementations to sign HTTP AWS +// requests. +type HTTPSigner interface { + SignHTTP(ctx context.Context, r *http.Request, payloadHash string, service string, region string, signingTime time.Time) error +} - // Handlers - svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler) - svc.Handlers.Build.PushBackNamed(restjson.BuildHandler) - svc.Handlers.Unmarshal.PushBackNamed(restjson.UnmarshalHandler) - svc.Handlers.UnmarshalMeta.PushBackNamed(restjson.UnmarshalMetaHandler) - svc.Handlers.UnmarshalError.PushBackNamed(restjson.UnmarshalErrorHandler) +// HTTPClient provides the interface for an implementation to round trip HTTP +// requests to a service, returning a response or error. +type HTTPClient interface { + Do(*http.Request) (*http.Response, error) +} - // Run custom client initialization if present - if initClient != nil { - initClient(svc) +// NewClient returns an initialized client with the client options used to +// specify the behavior of the client. +func NewClient(cfg aws.Config, opts ...func(*ClientOptions)) *Client { + client := &Client{ + serviceName: "Amazon Lex Runtime Service", + serviceID: "LexRuntimeService", + endpointID: "runtime.lex", + + options: ClientOptions{ + RegionID: cfg.Region, + EndpointResolver: cfg.EndpointResolver, + Signer: v4.NewSigner(cfg.Credentials), + HTTPClient: cfg.HTTPClient, + }, + } + + for _, fn := range opts { + fn(&client.options) } - return svc + return client } -// newRequest creates a new request for a client operation and runs any -// custom request initialization. -func (c *Client) newRequest(op *aws.Operation, params, data interface{}) *aws.Request { - req := c.NewRequest(op, params, data) +// ServiceID returns the name of the identifier for the service API. +func (c *Client) ServiceID() string { return c.serviceID } + +// ServiceName returns the full service name. +func (c *Client) ServiceName() string { return c.serviceName } + +// APIOptionFunc provides the type for overriding options for API operation +// calls. Allows modifying the middleware stack, and client options per API +// operation call. +type APIOptionFunc func(*ClientOptions, *middleware.Stack) error + +func (c *Client) invoke(ctx context.Context, stack *middleware.Stack, input interface{}, opts ...APIOptionFunc) ( + result interface{}, metadata middleware.Metadata, err error, +) { + clientOptions := c.options + for _, fn := range c.options.APIOptions { + if err := fn(&clientOptions, stack); err != nil { + return nil, metadata, err + } + } - // Run custom request initialization if present - if initRequest != nil { - initRequest(c, req) + for _, fn := range opts { + if err := fn(&clientOptions, stack); err != nil { + return nil, metadata, err + } } - return req + h := middleware.DecorateHandler(awshttp.ClientHandler{Client: clientOptions.HTTPClient}, stack) + return h.Handle(ctx, input) } diff --git a/service/smithyprototype/lexruntimeservice/api_client_example_test.go b/service/smithyprototype/lexruntimeservice/api_client_example_test.go new file mode 100644 index 00000000000..a2d7fa57ac8 --- /dev/null +++ b/service/smithyprototype/lexruntimeservice/api_client_example_test.go @@ -0,0 +1,59 @@ +package lexruntimeservice_test + +import ( + "context" + "fmt" + "log" + + "github.com/aws/aws-sdk-go-v2/aws" + lexruntime "github.com/aws/aws-sdk-go-v2/service/smithyprototype/lexruntimeservice" +) + +func ExampleNewClient() { + cfg, err := external.LoadDefaultAWSConfig() + if err != nil { + log.Fatalf("failed to load config, %v", err) + } + + client := lexruntime.NewClient(cfg) + res, err := client.GetSession(context.TODO(), &lexruntime.GetSessionInput{ + BotAlias: aws.String("botAlias"), + BotName: aws.String("botName"), + UserId: aws.String("userID"), + }) + if err != nil { + log.Fatalf("failed to get session, %v", err) + } + + fmt.Println("session:", res.SessionId) +} + +func ExampleNewClient_customOptions() { + cfg, err := external.LoadDefaultAWSConfig() + if err != nil { + log.Fatalf("failed to load config, %v", err) + } + + client := lexruntime.NewClient(cfg, func(o *lexruntime.ClientOptions) { + o.RegionID = "us-west-2" + }) + res, err := client.GetSession(context.TODO(), &lexruntime.GetSessionInput{ + BotAlias: aws.String("botAlias"), + BotName: aws.String("botName"), + UserId: aws.String("userID"), + }) + if err != nil { + log.Fatalf("failed to get session, %v", err) + } + + fmt.Println("session:", res.SessionId) +} + +var external = mockExternal{} + +type mockExternal struct { +} + +func (mockExternal) LoadDefaultAWSConfig() (aws.Config, error) { + return aws.Config{}, nil +} diff --git a/service/smithyprototype/lexruntimeservice/api_op_DeleteSession.go b/service/smithyprototype/lexruntimeservice/api_op_DeleteSession.go index 6adbe986c63..9bd2b55eb75 100644 --- a/service/smithyprototype/lexruntimeservice/api_op_DeleteSession.go +++ b/service/smithyprototype/lexruntimeservice/api_op_DeleteSession.go @@ -7,7 +7,9 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/internal/awsutil" - "github.com/aws/aws-sdk-go-v2/private/protocol" + "github.com/awslabs/smithy-go" + "github.com/awslabs/smithy-go/middleware" + smithyhttp "github.com/awslabs/smithy-go/transport/http" ) type DeleteSessionInput struct { @@ -35,7 +37,7 @@ func (s DeleteSessionInput) String() string { } // Validate inspects the fields of the type to determine if they are valid. -func (s *DeleteSessionInput) Validate() error { +func validateDeleteSessionInput(s *DeleteSessionInput) error { invalidParams := aws.ErrInvalidParams{Context: "DeleteSessionInput"} if s.BotAlias == nil { @@ -59,31 +61,6 @@ func (s *DeleteSessionInput) Validate() error { return nil } -// MarshalFields encodes the AWS API shape using the passed in protocol encoder. -func (s DeleteSessionInput) MarshalFields(e protocol.FieldEncoder) error { - e.SetValue(protocol.HeaderTarget, "Content-Type", protocol.StringValue("application/json"), protocol.Metadata{}) - - if s.BotAlias != nil { - v := *s.BotAlias - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "botAlias", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.BotName != nil { - v := *s.BotName - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "botName", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.UserId != nil { - v := *s.UserId - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "userId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - return nil -} - type DeleteSessionOutput struct { _ struct{} `type:"structure"` @@ -98,6 +75,9 @@ type DeleteSessionOutput struct { // The ID of the client application user. UserId *string `locationName:"userId" min:"2" type:"string"` + + // Operation result metadata + ResultMetadata middleware.Metadata } // String returns the string representation @@ -105,99 +85,31 @@ func (s DeleteSessionOutput) String() string { return awsutil.Prettify(s) } -// MarshalFields encodes the AWS API shape using the passed in protocol encoder. -func (s DeleteSessionOutput) MarshalFields(e protocol.FieldEncoder) error { - if s.BotAlias != nil { - v := *s.BotAlias - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "botAlias", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.BotName != nil { - v := *s.BotName - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "botName", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.SessionId != nil { - v := *s.SessionId - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "sessionId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.UserId != nil { - v := *s.UserId - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "userId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - return nil -} - -const opDeleteSession = "DeleteSession" - -// DeleteSessionRequest returns a request value for making API operation for -// Amazon Lex Runtime Service. +// DeleteSession invokes the API Amazon Lex Runtime Service, returning the +// result or error. // // Removes session information for a specified bot, alias, and user ID. // -// // Example sending a request using DeleteSessionRequest. -// req := client.DeleteSessionRequest(params) -// resp, err := req.Send(context.TODO()) -// if err == nil { -// fmt.Println(resp) -// } -// // Please also see https://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/DeleteSession -func (c *Client) DeleteSessionRequest(input *DeleteSessionInput) DeleteSessionRequest { - op := &aws.Operation{ - Name: opDeleteSession, - HTTPMethod: "DELETE", - HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/session", - } - - if input == nil { - input = &DeleteSessionInput{} - } - - req := c.newRequest(op, input, &DeleteSessionOutput{}) - return DeleteSessionRequest{Request: req, Input: input, Copy: c.DeleteSessionRequest} -} +func (c *Client) DeleteSession(ctx context.Context, input *DeleteSessionInput, opts ...APIOptionFunc) ( + *DeleteSessionOutput, error, +) { + stack := middleware.NewStack("lex runtime delete session", smithyhttp.NewStackRequest) -// DeleteSessionRequest is the request type for the -// DeleteSession API operation. -type DeleteSessionRequest struct { - *aws.Request - Input *DeleteSessionInput - Copy func(*DeleteSessionInput) DeleteSessionRequest -} + // TODO add stack (de)serializers, retry, and signer + // Items like HTTP method and path are added via operation's serializer + // + // HTTPMethod: "DELETE", + // HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/session", -// Send marshals and sends the DeleteSession API request. -func (r DeleteSessionRequest) Send(ctx context.Context) (*DeleteSessionResponse, error) { - r.Request.SetContext(ctx) - err := r.Request.Send() + res, _, err := c.invoke(ctx, stack, input, opts...) if err != nil { - return nil, err + return nil, &smithy.OperationError{ + ServiceName: "LexRuntimeService", + OperationName: "DeleteSession", + Err: err, + } } - resp := &DeleteSessionResponse{ - DeleteSessionOutput: r.Request.Data.(*DeleteSessionOutput), - response: &aws.Response{Request: r.Request}, - } - - return resp, nil -} - -// DeleteSessionResponse is the response type for the -// DeleteSession API operation. -type DeleteSessionResponse struct { - *DeleteSessionOutput - - response *aws.Response -} - -// SDKResponseMetdata returns the response metadata for the -// DeleteSession request. -func (r *DeleteSessionResponse) SDKResponseMetdata() *aws.Response { - return r.response + return res.(*DeleteSessionOutput), nil } diff --git a/service/smithyprototype/lexruntimeservice/api_op_GetSession.go b/service/smithyprototype/lexruntimeservice/api_op_GetSession.go index 05380b772a6..97bb0ca41fe 100644 --- a/service/smithyprototype/lexruntimeservice/api_op_GetSession.go +++ b/service/smithyprototype/lexruntimeservice/api_op_GetSession.go @@ -7,8 +7,10 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/internal/awsutil" - "github.com/aws/aws-sdk-go-v2/private/protocol" "github.com/aws/aws-sdk-go-v2/service/smithyprototype/lexruntimeservice/types" + "github.com/awslabs/smithy-go" + "github.com/awslabs/smithy-go/middleware" + smithyhttp "github.com/awslabs/smithy-go/transport/http" ) type GetSessionInput struct { @@ -44,7 +46,7 @@ func (s GetSessionInput) String() string { } // Validate inspects the fields of the type to determine if they are valid. -func (s *GetSessionInput) Validate() error { +func validateGetSessionInput(s *GetSessionInput) error { invalidParams := aws.ErrInvalidParams{Context: "GetSessionInput"} if s.BotAlias == nil { @@ -71,37 +73,6 @@ func (s *GetSessionInput) Validate() error { return nil } -// MarshalFields encodes the AWS API shape using the passed in protocol encoder. -func (s GetSessionInput) MarshalFields(e protocol.FieldEncoder) error { - e.SetValue(protocol.HeaderTarget, "Content-Type", protocol.StringValue("application/json"), protocol.Metadata{}) - - if s.BotAlias != nil { - v := *s.BotAlias - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "botAlias", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.BotName != nil { - v := *s.BotName - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "botName", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.UserId != nil { - v := *s.UserId - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "userId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.CheckpointLabelFilter != nil { - v := *s.CheckpointLabelFilter - - metadata := protocol.Metadata{} - e.SetValue(protocol.QueryTarget, "checkpointLabelFilter", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - return nil -} - type GetSessionOutput struct { _ struct{} `type:"structure"` @@ -124,6 +95,9 @@ type GetSessionOutput struct { // A unique identifier for the session. SessionId *string `locationName:"sessionId" type:"string"` + + // Operation result metadata + ResultMetadata middleware.Metadata } // String returns the string representation @@ -131,111 +105,31 @@ func (s GetSessionOutput) String() string { return awsutil.Prettify(s) } -// MarshalFields encodes the AWS API shape using the passed in protocol encoder. -func (s GetSessionOutput) MarshalFields(e protocol.FieldEncoder) error { - if s.DialogAction != nil { - v := s.DialogAction - - metadata := protocol.Metadata{} - e.SetFields(protocol.BodyTarget, "dialogAction", v, metadata) - } - if s.RecentIntentSummaryView != nil { - v := s.RecentIntentSummaryView - - metadata := protocol.Metadata{} - ls0 := e.List(protocol.BodyTarget, "recentIntentSummaryView", metadata) - ls0.Start() - for _, v1 := range v { - ls0.ListAddFields(v1) - } - ls0.End() - - } - if s.SessionAttributes != nil { - v := s.SessionAttributes - - metadata := protocol.Metadata{} - ms0 := e.Map(protocol.BodyTarget, "sessionAttributes", metadata) - ms0.Start() - for k1, v1 := range v { - ms0.MapSetValue(k1, protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v1)}) - } - ms0.End() - - } - if s.SessionId != nil { - v := *s.SessionId - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "sessionId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - return nil -} - -const opGetSession = "GetSession" - -// GetSessionRequest returns a request value for making API operation for -// Amazon Lex Runtime Service. +// GetSession invokes the API Amazon Lex Runtime Service, returning the +// result or error. // // Returns session information for a specified bot, alias, and user ID. // -// // Example sending a request using GetSessionRequest. -// req := client.GetSessionRequest(params) -// resp, err := req.Send(context.TODO()) -// if err == nil { -// fmt.Println(resp) -// } -// // Please also see https://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/GetSession -func (c *Client) GetSessionRequest(input *GetSessionInput) GetSessionRequest { - op := &aws.Operation{ - Name: opGetSession, - HTTPMethod: "GET", - HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/session/", - } - - if input == nil { - input = &GetSessionInput{} - } - - req := c.newRequest(op, input, &GetSessionOutput{}) - return GetSessionRequest{Request: req, Input: input, Copy: c.GetSessionRequest} -} +func (c *Client) GetSession(ctx context.Context, input *GetSessionInput, opts ...APIOptionFunc) ( + *GetSessionOutput, error, +) { + stack := middleware.NewStack("lex runtime get session", smithyhttp.NewStackRequest) -// GetSessionRequest is the request type for the -// GetSession API operation. -type GetSessionRequest struct { - *aws.Request - Input *GetSessionInput - Copy func(*GetSessionInput) GetSessionRequest -} + // TODO add stack (de)serializers, retry, and signer + // Items like HTTP method and path are added via operation's serializer + // + // HTTPMethod: "GET", + // HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/session", -// Send marshals and sends the GetSession API request. -func (r GetSessionRequest) Send(ctx context.Context) (*GetSessionResponse, error) { - r.Request.SetContext(ctx) - err := r.Request.Send() + res, _, err := c.invoke(ctx, stack, input, opts...) if err != nil { - return nil, err - } - - resp := &GetSessionResponse{ - GetSessionOutput: r.Request.Data.(*GetSessionOutput), - response: &aws.Response{Request: r.Request}, + return nil, &smithy.OperationError{ + ServiceName: "LexRuntimeService", + OperationName: "GetSession", + Err: err, + } } - return resp, nil -} - -// GetSessionResponse is the response type for the -// GetSession API operation. -type GetSessionResponse struct { - *GetSessionOutput - - response *aws.Response -} - -// SDKResponseMetdata returns the response metadata for the -// GetSession request. -func (r *GetSessionResponse) SDKResponseMetdata() *aws.Response { - return r.response + return res.(*GetSessionOutput), nil } diff --git a/service/smithyprototype/lexruntimeservice/api_op_ListSessions.go b/service/smithyprototype/lexruntimeservice/api_op_ListSessions.go new file mode 100644 index 00000000000..0b87c29ddb3 --- /dev/null +++ b/service/smithyprototype/lexruntimeservice/api_op_ListSessions.go @@ -0,0 +1,182 @@ +// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. + +package lexruntimeservice + +import ( + "context" + "errors" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/internal/awsutil" + "github.com/aws/aws-sdk-go-v2/service/smithyprototype/lexruntimeservice/types" + "github.com/awslabs/smithy-go" + "github.com/awslabs/smithy-go/middleware" + smithyhttp "github.com/awslabs/smithy-go/transport/http" +) + +/* +***Mock operation for pagination*** + */ + +type ListSessionsInput struct { + _ struct{} `type:"structure"` + + // The alias in use for the bot that contains the session data. + // + // BotAlias is a required field + BotAlias *string `location:"uri" locationName:"botAlias" type:"string" required:"true"` + + // The name of the bot that contains the session data. + // + // BotName is a required field + BotName *string `location:"uri" locationName:"botName" type:"string" required:"true"` + + // A string used to filter the intents returned in the recentIntentSummaryView + // structure. + // + // When you specify a filter, only intents with their checkpointLabel field + // set to that string are returned. + CheckpointLabelFilter *string `location:"querystring" locationName:"checkpointLabelFilter" min:"1" type:"string"` + + // The ID of the client application user. Amazon Lex uses this to identify a + // user's conversation with your bot. + // + // UserId is a required field + UserId *string `location:"uri" locationName:"userId" min:"2" type:"string" required:"true"` + + NextToken *string +} + +// String returns the string representation +func (s ListSessionsInput) String() string { + return awsutil.Prettify(s) +} + +// Validate inspects the fields of the type to determine if they are valid. +func validateListSessionsInput(s *ListSessionsInput) error { + invalidParams := aws.ErrInvalidParams{Context: "ListSessionsInput"} + + if s.BotAlias == nil { + invalidParams.Add(aws.NewErrParamRequired("BotAlias")) + } + + if s.BotName == nil { + invalidParams.Add(aws.NewErrParamRequired("BotName")) + } + if s.CheckpointLabelFilter != nil && len(*s.CheckpointLabelFilter) < 1 { + invalidParams.Add(aws.NewErrParamMinLen("CheckpointLabelFilter", 1)) + } + + if s.UserId == nil { + invalidParams.Add(aws.NewErrParamRequired("UserId")) + } + if s.UserId != nil && len(*s.UserId) < 2 { + invalidParams.Add(aws.NewErrParamMinLen("UserId", 2)) + } + + if invalidParams.Len() > 0 { + return invalidParams + } + return nil +} + +type ListSessionsOutput struct { + _ struct{} `type:"structure"` + + // Describes the current state of the bot. + DialogAction *types.DialogAction `locationName:"dialogAction" type:"structure"` + + // An array of information about the intents used in the session. The array + // can contain a maximum of three summaries. If more than three intents are + // used in the session, the recentIntentSummaryView operation contains information + // about the last three intents used. + // + // If you set the checkpointLabelFilter parameter in the request, the array + // contains only the intents with the specified label. + RecentIntentSummaryView []types.IntentSummary `locationName:"recentIntentSummaryView" type:"list"` + + // Map of key/value pairs representing the session-specific context information. + // It contains application information passed between Amazon Lex and a client + // application. + SessionAttributes map[string]string `locationName:"sessionAttributes" type:"map" sensitive:"true"` + + // A unique identifier for the session. + SessionId *string `locationName:"sessionId" type:"string"` + + // Operation result metadata + ResultMetadata middleware.Metadata + + NextToken *string +} + +// String returns the string representation +func (s ListSessionsOutput) String() string { + return awsutil.Prettify(s) +} + +// ListSessions invokes the API Amazon Lex Runtime Service, returning the +// result or error. +// +// Returns session information for a specified bot, alias, and user ID. +// +// Please also see https://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/ListSessions +func (c *Client) ListSessions(ctx context.Context, input *ListSessionsInput, opts ...APIOptionFunc) ( + *ListSessionsOutput, error, +) { + stack := middleware.NewStack("lex runtime get session", smithyhttp.NewStackRequest) + + // TODO add stack (de)serializers, retry, and signer + // Items like HTTP method and path are added via operation's serializer + // + // HTTPMethod: "GET", + // HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/session", + + res, _, err := c.invoke(ctx, stack, input, opts...) + if err != nil { + return nil, &smithy.OperationError{ + ServiceName: "LexRuntimeService", + OperationName: "ListSessions", + Err: err, + } + } + + return res.(*ListSessionsOutput), nil +} + +// Client interface generated for an operation as needed. This includes +// paginators, waiters, etc. + +// ListSessionsClient provides the interface for a client that implements the +// ListSessions API operation. Implemented by the package's Client type. +type ListSessionsClient interface { + ListSessions(ctx context.Context, input *ListSessionsInput, opts ...APIOptionFunc) ( + *ListSessionsOutput, error, + ) +} + +// ListSessionsPaginator provides the paginator for the ListSessions API operation. +type ListSessionsPaginator struct { + client ListSessionsClient + input *ListSessionsInput +} + +// NewListSessionsPaginator returns a ListSessionsPaginator configured for the +// API operation client, and input parameters. +func NewListSessionsPaginator(client ListSessionsClient, input *ListSessionsInput, opts ...APIOptionFunc) *ListSessionsPaginator { + // TODO implementation + return nil +} + +// HasMorePages returns if there may be more pages to retrieve. +func (p *ListSessionsPaginator) HasMorePages() bool { + // TODO implementation + return false +} + +// NextPage returns the next page from the API, or error. +func (p *ListSessionsPaginator) NextPage(ctx context.Context, opts ...APIOptionFunc) ( + *ListSessionsOutput, error, +) { + // TODO implementation + return nil, errors.New("not implemented") +} diff --git a/service/smithyprototype/lexruntimeservice/api_op_ListSessions_example_test.go b/service/smithyprototype/lexruntimeservice/api_op_ListSessions_example_test.go new file mode 100644 index 00000000000..be845ffd5a2 --- /dev/null +++ b/service/smithyprototype/lexruntimeservice/api_op_ListSessions_example_test.go @@ -0,0 +1,35 @@ +package lexruntimeservice_test + +import ( + "context" + "fmt" + "log" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/smithyprototype/lexruntimeservice" + lexruntime "github.com/aws/aws-sdk-go-v2/service/smithyprototype/lexruntimeservice" +) + +func ExampleClient_ListSessions_pagination() { + cfg, err := external.LoadDefaultAWSConfig() + if err != nil { + log.Fatalf("unable to load configuration, %v", err) + } + + client := lexruntimeservice.NewClient(cfg) + + // Create a paginator with the client and input parameters. + p := lexruntime.NewListSessionsPaginator(client, &lexruntime.ListSessionsInput{ + BotAlias: aws.String("botAlias"), + BotName: aws.String("botName"), + UserId: aws.String("userID"), + }) + + for p.HasMorePages() { + o, err := p.NextPage(context.TODO()) + if err != nil { + log.Fatalf("failed to get next page, %v", err) + } + fmt.Println("Page:", o) + } +} diff --git a/service/smithyprototype/lexruntimeservice/api_op_PostContent.go b/service/smithyprototype/lexruntimeservice/api_op_PostContent.go index 55b22bde1b6..3414a016d96 100644 --- a/service/smithyprototype/lexruntimeservice/api_op_PostContent.go +++ b/service/smithyprototype/lexruntimeservice/api_op_PostContent.go @@ -7,10 +7,11 @@ import ( "io" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/signer/v4" "github.com/aws/aws-sdk-go-v2/internal/awsutil" - "github.com/aws/aws-sdk-go-v2/private/protocol" - types "github.com/aws/aws-sdk-go-v2/service/smithyprototype/lexruntimeservice/types" + "github.com/aws/aws-sdk-go-v2/service/smithyprototype/lexruntimeservice/types" + "github.com/awslabs/smithy-go" + "github.com/awslabs/smithy-go/middleware" + smithyhttp "github.com/awslabs/smithy-go/transport/http" ) type PostContentInput struct { @@ -70,13 +71,8 @@ type PostContentInput struct { // that captures all of the audio data before sending. In general, you get better // performance if you stream audio data rather than buffering the data locally. // - // To use an non-seekable io.Reader for this request wrap the io.Reader with - // "aws.ReadSeekCloser". The SDK will not retry request errors for non-seekable - // readers. This will allow the SDK to send the reader's payload as chunked - // transfer encoding. - // // InputStream is a required field - InputStream io.ReadSeeker `locationName:"inputStream" type:"blob" required:"true"` + InputStream io.Reader `locationName:"inputStream" type:"blob" required:"true"` // You pass this value as the x-amz-lex-request-attributes HTTP header. // @@ -135,7 +131,7 @@ func (s PostContentInput) String() string { } // Validate inspects the fields of the type to determine if they are valid. -func (s *PostContentInput) Validate() error { +func validatePostContentInput(s *PostContentInput) error { invalidParams := aws.ErrInvalidParams{Context: "PostContentInput"} if s.BotAlias == nil { @@ -167,60 +163,6 @@ func (s *PostContentInput) Validate() error { return nil } -// MarshalFields encodes the AWS API shape using the passed in protocol encoder. -func (s PostContentInput) MarshalFields(e protocol.FieldEncoder) error { - - if s.Accept != nil { - v := *s.Accept - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "Accept", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.ContentType != nil { - v := *s.ContentType - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "Content-Type", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.RequestAttributes != nil { - v := s.RequestAttributes - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-request-attributes", protocol.JSONValue{V: v, EscapeMode: protocol.Base64Escape}, metadata) - } - if s.SessionAttributes != nil { - v := s.SessionAttributes - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-session-attributes", protocol.JSONValue{V: v, EscapeMode: protocol.Base64Escape}, metadata) - } - if s.BotAlias != nil { - v := *s.BotAlias - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "botAlias", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.BotName != nil { - v := *s.BotName - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "botName", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.UserId != nil { - v := *s.UserId - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "userId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.InputStream != nil { - v := s.InputStream - - metadata := protocol.Metadata{} - e.SetStream(protocol.PayloadTarget, "inputStream", protocol.ReadSeekerStream{V: v}, metadata) - } - return nil -} - type PostContentOutput struct { _ struct{} `type:"structure" payload:"AudioStream"` @@ -344,6 +286,9 @@ type PostContentOutput struct { // or, if there is no resolution list, null. If you don't specify a valueSelectionStrategy, // the default is ORIGINAL_VALUE. Slots aws.JSONValue `location:"header" locationName:"x-amz-lex-slots" type:"jsonvalue"` + + // Operation result metadata + ResultMetadata middleware.Metadata } // String returns the string representation @@ -351,82 +296,9 @@ func (s PostContentOutput) String() string { return awsutil.Prettify(s) } -// MarshalFields encodes the AWS API shape using the passed in protocol encoder. -func (s PostContentOutput) MarshalFields(e protocol.FieldEncoder) error { - if s.ContentType != nil { - v := *s.ContentType - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "Content-Type", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if len(s.DialogState) > 0 { - v := s.DialogState - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-dialog-state", protocol.QuotedValue{ValueMarshaler: v}, metadata) - } - if s.InputTranscript != nil { - v := *s.InputTranscript - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-input-transcript", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.IntentName != nil { - v := *s.IntentName - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-intent-name", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.Message != nil { - v := *s.Message - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-message", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if len(s.MessageFormat) > 0 { - v := s.MessageFormat - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-message-format", protocol.QuotedValue{ValueMarshaler: v}, metadata) - } - if s.SentimentResponse != nil { - v := *s.SentimentResponse - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-sentiment", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.SessionAttributes != nil { - v := s.SessionAttributes - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-session-attributes", protocol.JSONValue{V: v, EscapeMode: protocol.Base64Escape}, metadata) - } - if s.SessionId != nil { - v := *s.SessionId - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-session-id", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.SlotToElicit != nil { - v := *s.SlotToElicit - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-slot-to-elicit", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.Slots != nil { - v := s.Slots - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-slots", protocol.JSONValue{V: v, EscapeMode: protocol.Base64Escape}, metadata) - } - // Skipping AudioStream Output type's body not valid. - return nil -} - -const opPostContent = "PostContent" - -// PostContentRequest returns a request value for making API operation for -// Amazon Lex Runtime Service. +// PostContent invokes the API Amazon Lex Runtime Service, returning the +// result or error. +// // // Sends user input (text or speech) to Amazon Lex. Clients use this API to // send text and audio requests to Amazon Lex at runtime. Amazon Lex interprets @@ -476,66 +348,26 @@ const opPostContent = "PostContent" // In addition, Amazon Lex also returns your application-specific sessionAttributes. // For more information, see Managing Conversation Context (https://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html). // -// // Example sending a request using PostContentRequest. -// req := client.PostContentRequest(params) -// resp, err := req.Send(context.TODO()) -// if err == nil { -// fmt.Println(resp) -// } -// // Please also see https://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostContent -func (c *Client) PostContentRequest(input *PostContentInput) PostContentRequest { - op := &aws.Operation{ - Name: opPostContent, - HTTPMethod: "POST", - HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/content", - } - - if input == nil { - input = &PostContentInput{} - } - - req := c.newRequest(op, input, &PostContentOutput{}) - req.Handlers.Sign.Remove(v4.SignRequestHandler) - handler := v4.BuildNamedHandler("v4.CustomSignerHandler", v4.WithUnsignedPayload) - req.Handlers.Sign.PushFrontNamed(handler) - return PostContentRequest{Request: req, Input: input, Copy: c.PostContentRequest} -} +func (c *Client) PostContent(ctx context.Context, input *PostContentInput, opts ...APIOptionFunc) ( + *PostContentOutput, error, +) { + stack := middleware.NewStack("lex runtime post content", smithyhttp.NewStackRequest) -// PostContentRequest is the request type for the -// PostContent API operation. -type PostContentRequest struct { - *aws.Request - Input *PostContentInput - Copy func(*PostContentInput) PostContentRequest -} + // TODO add stack (de)serializers, retry, and signer + // Items like HTTP method and path are added via operation's serializer + // + // HTTPMethod: "POST", + // HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/content", -// Send marshals and sends the PostContent API request. -func (r PostContentRequest) Send(ctx context.Context) (*PostContentResponse, error) { - r.Request.SetContext(ctx) - err := r.Request.Send() + res, _, err := c.invoke(ctx, stack, input, opts...) if err != nil { - return nil, err - } - - resp := &PostContentResponse{ - PostContentOutput: r.Request.Data.(*PostContentOutput), - response: &aws.Response{Request: r.Request}, + return nil, &smithy.OperationError{ + ServiceName: "LexRuntimeService", + OperationName: "PostContent", + Err: err, + } } - return resp, nil -} - -// PostContentResponse is the response type for the -// PostContent API operation. -type PostContentResponse struct { - *PostContentOutput - - response *aws.Response -} - -// SDKResponseMetdata returns the response metadata for the -// PostContent request. -func (r *PostContentResponse) SDKResponseMetdata() *aws.Response { - return r.response + return res.(*PostContentOutput), nil } diff --git a/service/smithyprototype/lexruntimeservice/api_op_PostText.go b/service/smithyprototype/lexruntimeservice/api_op_PostText.go index 1f193cd4c7e..84af26274e8 100644 --- a/service/smithyprototype/lexruntimeservice/api_op_PostText.go +++ b/service/smithyprototype/lexruntimeservice/api_op_PostText.go @@ -7,8 +7,10 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/internal/awsutil" - "github.com/aws/aws-sdk-go-v2/private/protocol" "github.com/aws/aws-sdk-go-v2/service/smithyprototype/lexruntimeservice/types" + "github.com/awslabs/smithy-go" + "github.com/awslabs/smithy-go/middleware" + smithyhttp "github.com/awslabs/smithy-go/transport/http" ) type PostTextInput struct { @@ -76,7 +78,7 @@ func (s PostTextInput) String() string { } // Validate inspects the fields of the type to determine if they are valid. -func (s *PostTextInput) Validate() error { +func validatePostTextInput(s *PostTextInput) error { invalidParams := aws.ErrInvalidParams{Context: "PostTextInput"} if s.BotAlias == nil { @@ -107,61 +109,6 @@ func (s *PostTextInput) Validate() error { return nil } -// MarshalFields encodes the AWS API shape using the passed in protocol encoder. -func (s PostTextInput) MarshalFields(e protocol.FieldEncoder) error { - e.SetValue(protocol.HeaderTarget, "Content-Type", protocol.StringValue("application/json"), protocol.Metadata{}) - - if s.InputText != nil { - v := *s.InputText - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "inputText", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.RequestAttributes != nil { - v := s.RequestAttributes - - metadata := protocol.Metadata{} - ms0 := e.Map(protocol.BodyTarget, "requestAttributes", metadata) - ms0.Start() - for k1, v1 := range v { - ms0.MapSetValue(k1, protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v1)}) - } - ms0.End() - - } - if s.SessionAttributes != nil { - v := s.SessionAttributes - - metadata := protocol.Metadata{} - ms0 := e.Map(protocol.BodyTarget, "sessionAttributes", metadata) - ms0.Start() - for k1, v1 := range v { - ms0.MapSetValue(k1, protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v1)}) - } - ms0.End() - - } - if s.BotAlias != nil { - v := *s.BotAlias - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "botAlias", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.BotName != nil { - v := *s.BotName - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "botName", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.UserId != nil { - v := *s.UserId - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "userId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - return nil -} - type PostTextOutput struct { _ struct{} `type:"structure"` @@ -270,6 +217,9 @@ type PostTextOutput struct { // or, if there is no resolution list, null. If you don't specify a valueSelectionStrategy, // the default is ORIGINAL_VALUE. Slots map[string]string `locationName:"slots" type:"map" sensitive:"true"` + + // Operation result metadata + ResultMetadata middleware.Metadata } // String returns the string representation @@ -277,85 +227,6 @@ func (s PostTextOutput) String() string { return awsutil.Prettify(s) } -// MarshalFields encodes the AWS API shape using the passed in protocol encoder. -func (s PostTextOutput) MarshalFields(e protocol.FieldEncoder) error { - if len(s.DialogState) > 0 { - v := s.DialogState - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "dialogState", protocol.QuotedValue{ValueMarshaler: v}, metadata) - } - if s.IntentName != nil { - v := *s.IntentName - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "intentName", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.Message != nil { - v := *s.Message - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "message", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if len(s.MessageFormat) > 0 { - v := s.MessageFormat - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "messageFormat", protocol.QuotedValue{ValueMarshaler: v}, metadata) - } - if s.ResponseCard != nil { - v := s.ResponseCard - - metadata := protocol.Metadata{} - e.SetFields(protocol.BodyTarget, "responseCard", v, metadata) - } - if s.SentimentResponse != nil { - v := s.SentimentResponse - - metadata := protocol.Metadata{} - e.SetFields(protocol.BodyTarget, "sentimentResponse", v, metadata) - } - if s.SessionAttributes != nil { - v := s.SessionAttributes - - metadata := protocol.Metadata{} - ms0 := e.Map(protocol.BodyTarget, "sessionAttributes", metadata) - ms0.Start() - for k1, v1 := range v { - ms0.MapSetValue(k1, protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v1)}) - } - ms0.End() - - } - if s.SessionId != nil { - v := *s.SessionId - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "sessionId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.SlotToElicit != nil { - v := *s.SlotToElicit - - metadata := protocol.Metadata{} - e.SetValue(protocol.BodyTarget, "slotToElicit", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.Slots != nil { - v := s.Slots - - metadata := protocol.Metadata{} - ms0 := e.Map(protocol.BodyTarget, "slots", metadata) - ms0.Start() - for k1, v1 := range v { - ms0.MapSetValue(k1, protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v1)}) - } - ms0.End() - - } - return nil -} - -const opPostText = "PostText" - // PostTextRequest returns a request value for making API operation for // Amazon Lex Runtime Service. // @@ -402,63 +273,26 @@ const opPostText = "PostText" // In addition, Amazon Lex also returns your application-specific sessionAttributes. // For more information, see Managing Conversation Context (https://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html). // -// // Example sending a request using PostTextRequest. -// req := client.PostTextRequest(params) -// resp, err := req.Send(context.TODO()) -// if err == nil { -// fmt.Println(resp) -// } -// // Please also see https://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostText -func (c *Client) PostTextRequest(input *PostTextInput) PostTextRequest { - op := &aws.Operation{ - Name: opPostText, - HTTPMethod: "POST", - HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/text", - } - - if input == nil { - input = &PostTextInput{} - } - - req := c.newRequest(op, input, &PostTextOutput{}) - return PostTextRequest{Request: req, Input: input, Copy: c.PostTextRequest} -} +func (c *Client) PostText(ctx context.Context, input *PostTextInput, opts ...APIOptionFunc) ( + *PostTextOutput, error, +) { + stack := middleware.NewStack("lex runtime post text", smithyhttp.NewStackRequest) -// PostTextRequest is the request type for the -// PostText API operation. -type PostTextRequest struct { - *aws.Request - Input *PostTextInput - Copy func(*PostTextInput) PostTextRequest -} + // TODO add stack (de)serializers, retry, and signer + // Items like HTTP method and path are added via operation's serializer + // + // HTTPMethod: "POST", + // HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/text", -// Send marshals and sends the PostText API request. -func (r PostTextRequest) Send(ctx context.Context) (*PostTextResponse, error) { - r.Request.SetContext(ctx) - err := r.Request.Send() + res, _, err := c.invoke(ctx, stack, input, opts...) if err != nil { - return nil, err - } - - resp := &PostTextResponse{ - PostTextOutput: r.Request.Data.(*PostTextOutput), - response: &aws.Response{Request: r.Request}, + return nil, &smithy.OperationError{ + ServiceName: "LexRuntimeService", + OperationName: "PostText", + Err: err, + } } - return resp, nil -} - -// PostTextResponse is the response type for the -// PostText API operation. -type PostTextResponse struct { - *PostTextOutput - - response *aws.Response -} - -// SDKResponseMetdata returns the response metadata for the -// PostText request. -func (r *PostTextResponse) SDKResponseMetdata() *aws.Response { - return r.response + return res.(*PostTextOutput), nil } diff --git a/service/smithyprototype/lexruntimeservice/api_op_PutSession.go b/service/smithyprototype/lexruntimeservice/api_op_PutSession.go index 7374eab158f..3f7858e1c79 100644 --- a/service/smithyprototype/lexruntimeservice/api_op_PutSession.go +++ b/service/smithyprototype/lexruntimeservice/api_op_PutSession.go @@ -9,8 +9,10 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/internal/awsutil" - "github.com/aws/aws-sdk-go-v2/private/protocol" "github.com/aws/aws-sdk-go-v2/service/smithyprototype/lexruntimeservice/types" + "github.com/awslabs/smithy-go" + "github.com/awslabs/smithy-go/middleware" + smithyhttp "github.com/awslabs/smithy-go/transport/http" ) type PutSessionInput struct { @@ -86,7 +88,7 @@ func (s PutSessionInput) String() string { } // Validate inspects the fields of the type to determine if they are valid. -func (s *PutSessionInput) Validate() error { +func validatePutSessionInput(s *PutSessionInput) error { invalidParams := aws.ErrInvalidParams{Context: "PutSessionInput"} if s.BotAlias == nil { @@ -122,67 +124,6 @@ func (s *PutSessionInput) Validate() error { return nil } -// MarshalFields encodes the AWS API shape using the passed in protocol encoder. -func (s PutSessionInput) MarshalFields(e protocol.FieldEncoder) error { - e.SetValue(protocol.HeaderTarget, "Content-Type", protocol.StringValue("application/json"), protocol.Metadata{}) - - if s.DialogAction != nil { - v := s.DialogAction - - metadata := protocol.Metadata{} - e.SetFields(protocol.BodyTarget, "dialogAction", v, metadata) - } - if s.RecentIntentSummaryView != nil { - v := s.RecentIntentSummaryView - - metadata := protocol.Metadata{} - ls0 := e.List(protocol.BodyTarget, "recentIntentSummaryView", metadata) - ls0.Start() - for _, v1 := range v { - ls0.ListAddFields(v1) - } - ls0.End() - - } - if s.SessionAttributes != nil { - v := s.SessionAttributes - - metadata := protocol.Metadata{} - ms0 := e.Map(protocol.BodyTarget, "sessionAttributes", metadata) - ms0.Start() - for k1, v1 := range v { - ms0.MapSetValue(k1, protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v1)}) - } - ms0.End() - - } - if s.Accept != nil { - v := *s.Accept - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "Accept", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.BotAlias != nil { - v := *s.BotAlias - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "botAlias", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.BotName != nil { - v := *s.BotName - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "botName", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.UserId != nil { - v := *s.UserId - - metadata := protocol.Metadata{} - e.SetValue(protocol.PathTarget, "userId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - return nil -} - type PutSessionOutput struct { _ struct{} `type:"structure" payload:"AudioStream"` @@ -259,68 +200,6 @@ func (s PutSessionOutput) String() string { return awsutil.Prettify(s) } -// MarshalFields encodes the AWS API shape using the passed in protocol encoder. -func (s PutSessionOutput) MarshalFields(e protocol.FieldEncoder) error { - if s.ContentType != nil { - v := *s.ContentType - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "Content-Type", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if len(s.DialogState) > 0 { - v := s.DialogState - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-dialog-state", protocol.QuotedValue{ValueMarshaler: v}, metadata) - } - if s.IntentName != nil { - v := *s.IntentName - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-intent-name", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.Message != nil { - v := *s.Message - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-message", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if len(s.MessageFormat) > 0 { - v := s.MessageFormat - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-message-format", protocol.QuotedValue{ValueMarshaler: v}, metadata) - } - if s.SessionAttributes != nil { - v := s.SessionAttributes - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-session-attributes", protocol.JSONValue{V: v, EscapeMode: protocol.Base64Escape}, metadata) - } - if s.SessionId != nil { - v := *s.SessionId - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-session-id", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.SlotToElicit != nil { - v := *s.SlotToElicit - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-slot-to-elicit", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata) - } - if s.Slots != nil { - v := s.Slots - - metadata := protocol.Metadata{} - e.SetValue(protocol.HeaderTarget, "x-amz-lex-slots", protocol.JSONValue{V: v, EscapeMode: protocol.Base64Escape}, metadata) - } - // Skipping AudioStream Output type's body not valid. - return nil -} - -const opPutSession = "PutSession" - // PutSessionRequest returns a request value for making API operation for // Amazon Lex Runtime Service. // @@ -330,63 +209,26 @@ const opPutSession = "PutSession" // // For more information, see Managing Sessions (https://docs.aws.amazon.com/lex/latest/dg/how-session-api.html). // -// // Example sending a request using PutSessionRequest. -// req := client.PutSessionRequest(params) -// resp, err := req.Send(context.TODO()) -// if err == nil { -// fmt.Println(resp) -// } -// // Please also see https://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PutSession -func (c *Client) PutSessionRequest(input *PutSessionInput) PutSessionRequest { - op := &aws.Operation{ - Name: opPutSession, - HTTPMethod: "POST", - HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/session", - } - - if input == nil { - input = &PutSessionInput{} - } - - req := c.newRequest(op, input, &PutSessionOutput{}) - return PutSessionRequest{Request: req, Input: input, Copy: c.PutSessionRequest} -} +func (c *Client) PutSession(ctx context.Context, input *PutSessionInput, opts ...APIOptionFunc) ( + *PutSessionOutput, error, +) { + stack := middleware.NewStack("lex runtime put session", smithyhttp.NewStackRequest) -// PutSessionRequest is the request type for the -// PutSession API operation. -type PutSessionRequest struct { - *aws.Request - Input *PutSessionInput - Copy func(*PutSessionInput) PutSessionRequest -} + // TODO add stack (de)serializers, retry, and signer + // Items like HTTP method and path are added via operation's serializer + // + // HTTPMethod: "PUT", + // HTTPPath: "/bot/{botName}/alias/{botAlias}/user/{userId}/session", -// Send marshals and sends the PutSession API request. -func (r PutSessionRequest) Send(ctx context.Context) (*PutSessionResponse, error) { - r.Request.SetContext(ctx) - err := r.Request.Send() + res, _, err := c.invoke(ctx, stack, input, opts...) if err != nil { - return nil, err - } - - resp := &PutSessionResponse{ - PutSessionOutput: r.Request.Data.(*PutSessionOutput), - response: &aws.Response{Request: r.Request}, + return nil, &smithy.OperationError{ + ServiceName: "LexRuntimeService", + OperationName: "PutSession", + Err: err, + } } - return resp, nil -} - -// PutSessionResponse is the response type for the -// PutSession API operation. -type PutSessionResponse struct { - *PutSessionOutput - - response *aws.Response -} - -// SDKResponseMetdata returns the response metadata for the -// PutSession request. -func (r *PutSessionResponse) SDKResponseMetdata() *aws.Response { - return r.response + return res.(*PutSessionOutput), nil } diff --git a/service/smithyprototype/lexruntimeservice/lexruntimeserviceiface/interface.go b/service/smithyprototype/lexruntimeservice/lexruntimeserviceiface/interface.go deleted file mode 100644 index 00bedc6b74a..00000000000 --- a/service/smithyprototype/lexruntimeservice/lexruntimeserviceiface/interface.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. - -// Package lexruntimeserviceiface provides an interface to enable mocking the Amazon Lex Runtime Service service client -// for testing your code. -// -// It is important to note that this interface will have breaking changes -// when the service model is updated and adds new API operations, paginators, -// and waiters. -package lexruntimeserviceiface - -import ( - "github.com/aws/aws-sdk-go-v2/service/lexruntimeservice" -) - -// ClientAPI provides an interface to enable mocking the -// lexruntimeservice.Client methods. This make unit testing your code that -// calls out to the SDK's service client's calls easier. -// -// The best way to use this interface is so the SDK's service client's calls -// can be stubbed out for unit testing your code with the SDK without needing -// to inject custom request handlers into the SDK's request pipeline. -// -// // myFunc uses an SDK service client to make a request to -// // Amazon Lex Runtime Service. -// func myFunc(svc lexruntimeserviceiface.ClientAPI) bool { -// // Make svc.DeleteSession request -// } -// -// func main() { -// cfg, err := external.LoadDefaultAWSConfig() -// if err != nil { -// panic("failed to load config, " + err.Error()) -// } -// -// svc := lexruntimeservice.New(cfg) -// -// myFunc(svc) -// } -// -// In your _test.go file: -// -// // Define a mock struct to be used in your unit tests of myFunc. -// type mockClientClient struct { -// lexruntimeserviceiface.ClientPI -// } -// func (m *mockClientClient) DeleteSession(input *lexruntimeservice.DeleteSessionInput) (*lexruntimeservice.DeleteSessionOutput, error) { -// // mock response/functionality -// } -// -// func TestMyFunc(t *testing.T) { -// // Setup Test -// mockSvc := &mockClientClient{} -// -// myfunc(mockSvc) -// -// // Verify myFunc's functionality -// } -// -// It is important to note that this interface will have breaking changes -// when the service model is updated and adds new API operations, paginators, -// and waiters. Its suggested to use the pattern above for testing, or using -// tooling to generate mocks to satisfy the interfaces. -type ClientAPI interface { - DeleteSessionRequest(*lexruntimeservice.DeleteSessionInput) lexruntimeservice.DeleteSessionRequest - - GetSessionRequest(*lexruntimeservice.GetSessionInput) lexruntimeservice.GetSessionRequest - - PostContentRequest(*lexruntimeservice.PostContentInput) lexruntimeservice.PostContentRequest - - PostTextRequest(*lexruntimeservice.PostTextInput) lexruntimeservice.PostTextRequest - - PutSessionRequest(*lexruntimeservice.PutSessionInput) lexruntimeservice.PutSessionRequest -} - -var _ ClientAPI = (*lexruntimeservice.Client)(nil)