-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hand written prototype for updated client API design. #530
Conversation
May need to rethink the signer some, as today a signer is constructed with the aws.Credentials, maybe these should be passed to the SignHTTP/PresignHTTP functions instead? |
May want to enumerate the keywords we will strip off when adding the For example |
My thought was that Metadata access helpers would be provided by the packages where middleware that produces said artifacts resides. Thoughts? Or were you thinking that we would have more specific metadata for services specifically? |
Closing this since prototype is no longer needed. Using smithy to generate based on this design |
Generated API client design
Addresses issue #70, #438, #439
Operation generated types
The following are a set of types that must be generated by smithy for an operation, that are not defined in the model. These types are needed by the API client to wrap and encapsulate the modeled operation types. The Smithy generator must ensure that all novel generated type do not conflict with modeled shapes.
Operation input: Smithy must generate a unique input type for each operation, regardless if an input shape is modeled. The naming of the input shape will be Input, where is the exported name of the operation. The input shape is a renamed clone of the modeled operation’s input shape, if any. If the operation does not have a modeled input shape, the a new empty shape will be created and used as the input shape.
Operation output: Smithy must generate a unique output type for each operation, regardless if an output shape is modeled. The name of the output type will be Output, where is the exported name of the operation. The output shape is a renamed clone of the modeled operation’s output shape, if any. If the operation does not have a modeled output shape, the a new empty output shape will be created and used as the input shape.
Operation Paginator: Smithy must generate operation specific paginator helpers for operations with modeled paginators. The paginator is a novel type that provides pagination iterator behavior. The name of the type will be Paginator, where is the exported name of the operation.
API Client: Smithy must generate a type named Client for each API client package. There may only be one API client per package. The client type will have additional configuration option utility types and functions generated as well.
Client
Smithy will generate a
Client
type in the API client package. This type will have methods for each modeled operation. The client's constructor takes functional options for configuring how the client operates. If customers would like to modify the client's behavior for all operation they can use the Client's functional options to do this.Client options
A client options is a type unique to the Client, that defines the set of options that a customer can modify when they create a client via the
New
function.If the SDK were to generate functional option helpers the
New
function'sopts
parameter could be defined as an exported type that all functional options return. This would ensure functional option helpers are grouped with the option type in API reference docs.Operations
The SDK will generate a method on the API Client for each supported operation. The operation will need to take three parameters, context.Context the modeled input shape, and a variadic argument of functional options to modify operation being invoked.
The functional options allow customers to modify how the individual operation is invoked. If the customer wants to modify all operations of a client, they can use the
Options.APIOptions
member.Operation input and output shape
Since Go does not support method overloading, and an operation can be updated to have a modeled input or output shape, all generated operation methods must have a stable input and output type generated. In order to ensure a stable name, this types must be
<Operation>
Input and<Operation>
Output, where<Operation>
is the name of the generated operation method.If a modeled input or output shape in an orphan and is not used by any other operation, or nested within a shape, the original shape should not be generated.
If a modeled input or output shape is reused by another operation, or nested, the original shape should be generated. The generator should also generate copy utilities to copy the cloned input/output shape to and from the original modeled shape. This allows customers to easily convert the input or output shape into its original shape for round tripping.
For example, the Lex Runtime
GetSession
operation is modeled withGetSessionRequest
input shape. Smithy will generated theGetSessionInput
type with all the same parameters as the modeledGetSessionRequest
shape. If theGetSessionRequest
shape is not used by any other shape or operation, it would not be generated. The reason to not generate these unused types is, because it would cause noise, and be confusion.Operation output type result metadata
The operation output generated type will have additional members and methods generated. These member's provide access to result metadata such as retry attempts and access to the raw protocol response message.
The operation output type will also have metadata helper methods generated on it such as
ServiceRequestID()
, andHTTPResponse()
.For example the Lex Runtime GetSession operation has a modeled output shape of
GetSessionResponse
, which becomes the operation output type ofGetSessionOutput
. TheGetSessionOutput
type will have the additional memberResultMetadata
generated. This member will be used to store result metadata of invoking the operation.Mocking API Client operations
The Smithy generator will not generate interfaces for the API client. Customers will need to write these interfaces them selves. Depending on customer demand this decision might be changed, but this is a two-way door decision to not generate the API client interfaces. The exception to this are operation clients that are needed for Waiters and Paginators.
Customers are able to define their own interfaces for operations they use. These interfaces can be composed, adding multiple operation methods to the same interface as they need. This style is the idiomatic style of not defining interfaces for behavior not used by the package.
Paginated operations
Smithy must generate operation specific paginator helpers for operations with modeled paginators. The paginator is a novel type that provides pagination iterator behavior. The name of the type will be
<OperationName>Paginator
.When a paginator or other utility that needs a client operation, an interface in the client package should be generated for that operation. The interface should be named
<OperationName>APIClient.
The generated paginator utility will take the client operation interface, and input parameters as input.
The following is an example of the paginator being used to iterate over pages.
Outstanding Question: Should HasMorePages continue to return true even if NextPage fails"? The reasoning behind this would be so that in the case of temporary server side error. This would give the user the ability to recover mid pagination, without needing to restart from the beginning, or rebuilding the input parameters with the current token.