-
Notifications
You must be signed in to change notification settings - Fork 112
fix: handle clientContextParam collisions with builtin config keys #1788
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
base: main
Are you sure you want to change the base?
Conversation
4a0b1ea to
c0cc0c7
Compare
f3ea1fe to
13fd0f0
Compare
9117008 to
1fc37f8
Compare
packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts
Outdated
Show resolved
Hide resolved
packages/middleware-endpoint/src/adaptors/createConfigValueProvider.ts
Outdated
Show resolved
Hide resolved
...est/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2GeneratorTest.java
Outdated
Show resolved
Hide resolved
ef3cda8 to
c5f0d86
Compare
...rc/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java
Outdated
Show resolved
Hide resolved
...rc/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java
Outdated
Show resolved
Hide resolved
...rc/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java
Outdated
Show resolved
Hide resolved
packages/middleware-endpoint/src/adaptors/createConfigValueProvider.ts
Outdated
Show resolved
Hide resolved
| if (isClientContextParam) { | ||
| // For client context parameters, check clientContextParams first | ||
| const clientContextParams = config.clientContextParams as Record<string, unknown> | undefined; | ||
| const nestedValue: unknown = clientContextParams?.[configKey] ?? clientContextParams?.[canonicalEndpointParamKey]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any case where the nested object does not use the canonical parameter key?
If not, there's no reason to check the configKey entry for the nested object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so
packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts
Outdated
Show resolved
Hide resolved
...rc/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java
Outdated
Show resolved
Hide resolved
...rc/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java
Outdated
Show resolved
Hide resolved
...rc/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java
Outdated
Show resolved
Hide resolved
...rc/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java
Outdated
Show resolved
Hide resolved
smithy-typescript-protocol-test-codegen/model/my-local-model/main.smithy
Show resolved
Hide resolved
1ed724d to
182326a
Compare
packages/eventstream-serde-universal/src/eventstream-cbor.integ.spec.ts
Outdated
Show resolved
Hide resolved
packages/middleware-endpoint/src/adaptors/createConfigValueProvider.spec.ts
Outdated
Show resolved
Hide resolved
packages/middleware-endpoint/src/adaptors/createConfigValueProvider.spec.ts
Show resolved
Hide resolved
| type Provider, | ||
| ApiKeyIdentity, | ||
| ApiKeyIdentityProvider, | ||
| HttpApiKeyAuthLocation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these new imports look like types. Change the codegen part to use addTypeImport() instead, or if imported via symbol, ensure the symbol has the typeOnly property.
| */ | ||
| export interface EndpointParameters extends __EndpointParameters { | ||
| endpoint?: string | undefined; | ||
| endpoint: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not saying it's wrong necessarily, but why did endpoint become required in the change?
| @@ -1,5 +1,5 @@ | |||
| // smithy-typescript generated code | |||
| import type { HttpAuthScheme } from "@smithy/types"; | |||
| import { type HttpAuthScheme, ApiKeyIdentity, ApiKeyIdentityProvider } from "@smithy/types"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change these to type imports
| type Provider, | ||
| ApiKeyIdentity, | ||
| ApiKeyIdentityProvider, | ||
| HttpApiKeyAuthLocation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use type imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpApiKeyAuthLocation can't be changed to type only. It's accessing a runtime value HttpApiKeyAuthLocation.HEADER
7016448 to
5401b57
Compare
smithy-typescript-protocol-test-codegen/model/my-local-model/main.smithy
Outdated
Show resolved
Hide resolved
packages/eventstream-serde-universal/src/clientContextParams-precedence.integ.spec.ts
Outdated
Show resolved
Hide resolved
packages/eventstream-serde-universal/src/clientContextParams-precedence.integ.spec.ts
Outdated
Show resolved
Hide resolved
packages/eventstream-serde-universal/src/clientContextParams-precedence.integ.spec.ts
Outdated
Show resolved
Hide resolved
private/my-local-model-schema/src/auth/httpAuthExtensionConfiguration.ts
Outdated
Show resolved
Hide resolved
...rc/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java
Outdated
Show resolved
Hide resolved
.../main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java
Outdated
Show resolved
Hide resolved
.../main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java
Outdated
Show resolved
Hide resolved
.../main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java
Outdated
Show resolved
Hide resolved
| enableFeature: { type: "Boolean", required: true, default: true, documentation: "Feature toggle with default" } | ||
| debugMode: { type: "Boolean", required: true, default: false, documentation: "Debug mode with default" } | ||
| nonConflictingParam: { type: "String", required: true, default: "non-conflict-default", documentation: "Non-conflicting with default" } | ||
| logger: { type: "String", required: true, default: "default-logger", documentation: "Conflicting logger with default" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all endpoint param types need to be lowercase string boolean. Add a stringArray one too, like "additionalFeatures".
5401b57 to
c848d0a
Compare
c848d0a to
fee039f
Compare
packages/eventstream-serde-universal/src/clientContextParams-precedence.integ.spec.ts
Show resolved
Hide resolved
| // For client context parameters, check clientContextParams first | ||
| const clientContextParams = config.clientContextParams as Record<string, unknown> | undefined; | ||
| const nestedValue: unknown = clientContextParams?.[canonicalEndpointParamKey]; | ||
| configValue = nestedValue ?? config[configKey] ?? config[canonicalEndpointParamKey]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could canonicalEndpointParamKey and configKey differ? (ApiKey -- from the ruleset vs apiKey -- from the client config) would that create any problems for the precedence lookup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for example, would this case correctly prefer the nested value?
const client = new XYZService({
apiKey: async () => ({ apiKey: "auth-secret" }),
clientContextParams: {
apiKey: "endpoint-header-key"
}
});if the nested value looks for the canonical name, would it find ApiKey (name in commonParams) and then fall back to the root value when it doesn't find clientContextParams.[ApiKey]?
Issue #, if available:
#1779
codegen v3:aws/aws-sdk-js-v3#7549
Description of changes:
This fixes TypeScript client codegen conflict between known config keys and clientContextParams by adding the nested clientContextParams object to isolate conflicting parameters while maintaining backward compatibility and proper precedence.
--