-
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
| options: T & ClientInputEndpointParameters | ||
| ): T & ClientResolvedEndpointParameters => { | ||
| return Object.assign(options, { | ||
| apiKey: options.apiKey ?? "default-api-key", |
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.
This is the main point of the fix, but this shouldn't appear here, since it will conflict with the same key potentially be added by the api key auth scheme.
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.
This is generated because the parameter has a default value set defined in @endpointRuleSet. If a default value is not defined it doesn't generate this.
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.
that does not matter - a conflicting key cannot be generated here
...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
9f47441 to
1ed724d
Compare
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
8965dee to
7016448
Compare
7016448 to
5401b57
Compare
smithy-typescript-protocol-test-codegen/model/my-local-model/main.smithy
Show resolved
Hide resolved
| customParam: "user-custom-value", | ||
| clientContextParams: { | ||
| apiKey: "test-key", | ||
| customParam: "default-custom-value", |
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.
| customParam: "default-custom-value", | |
| customParam: "nested-custom-value", |
this is not the default, it is given by the user at the client instantiation site
|
|
||
| // Verify the resolved config has the user's root-level value | ||
| const resolvedConfig = (clientWithNonConflicting as any).config; | ||
| expect(resolvedConfig.customParam).toBe("user-custom-value"); |
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.
This should be "nested-custom-value". When a value exists in both places the nested value should be used.
| }); | ||
|
|
||
| // Verify that both auth and endpoint contexts can coexist | ||
| const resolvedConfigConflicting = (clientWithConflicting as any).config; |
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.
why as any?
private/my-local-model-schema/src/auth/httpAuthExtensionConfiguration.ts
Show resolved
Hide resolved
...rc/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java
Show resolved
Hide resolved
.../main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java
Show resolved
Hide resolved
.../main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java
Show resolved
Hide resolved
.../main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java
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".
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.
--