-
Notifications
You must be signed in to change notification settings - Fork 111
Description
Hello,
I'm using typescript-client-codegen plugin to generate a typescript client for a model where I use https://smithy.io/2.0/additional-specs/rules-engine/specification.html to add stage and apiKey client context parameters so that my service's client users can have an easy way of selecting the service's endpoint based on stage, and also to set the apiKey I provide for them.
For the generated typescript client, and despite setting the apiKey which should, in the case of the model below, lead to the selection of an endpoint configuration that has the x-api-key header being set to the value of the apiKey provided, the final outgoing request never has that header set.
For context, I'm generating an AWS SDK v2-based client (starting from Smithy -> C2J -> generated Java Client, so I know it's a bit different), and following the same approach I'm able to set the apiKey on the client, and the endpoint header is included in the outgoing request.
I tried debugging the generated typescript client, and I could see that
- Till , the endpoint is resolved correctly, and has the
context.endpointV2 = endpoint; x-api-keyheader - I suspect it's in where the
const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint(); HttpRequestis created, ignoring the headers from the endpoint
Is that an intentional behavior? If not, then this is a feature request to respect the endpoint headers.
$version: "2.0"
namespace software.MyService
use smithy.rules#clientContextParams
use smithy.rules#endpointRuleSet
use smithy.rules#endpointTests
apply MyService @clientContextParams(
Stage: { type: "string", documentation: "Service stage (beta|prod)" }
ApiKey: { type: "string", documentation: "ApiKey" }
)
apply MyService @endpointRuleSet({
version: "1.0"
parameters: {
Stage: { required: false, documentation: "Specify the stage (beta|prod) so the endpoint is automatically set. If unspecified, prod endpoint will be used. Setting an explicit endpoint override is supported.", type: "String" }
ApiKey: { required: false, documentation: "ApiKey", type: "string" }
Endpoint: { builtIn: "SDK::Endpoint", required: false, documentation: "Override the endpoint used to send requests", type: "String" }
}
rules: [
// Rule to allow using endpoint overrides (with api key set)
{
type: "endpoint"
conditions: [
{
fn: "isSet"
argv: [
{
ref: "Endpoint"
}
]
}
{
fn: "isSet"
argv: [
{
ref: "ApiKey"
}
]
}
]
endpoint: {
headers: {
"x-api-key": ["{ApiKey}"]
}
url: { ref: "Endpoint" }
}
}
...