Skip to content

Commit ef3cda8

Browse files
committed
chore: address comments and add diff for build generate-protocol-tests
1 parent 1fc37f8 commit ef3cda8

File tree

8 files changed

+24
-18
lines changed

8 files changed

+24
-18
lines changed

packages/middleware-endpoint/src/adaptors/createConfigValueProvider.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,29 @@ import type { Endpoint, EndpointV2 } from "@smithy/types";
99
* it will most likely not contain the config
1010
* value, but we use it as a fallback.
1111
* @param config - container of the config values.
12+
* @param isClientContextParam - whether this is a client context parameter.
1213
*
1314
* @returns async function that will resolve with the value.
1415
*/
1516
export const createConfigValueProvider = <Config extends Record<string, unknown>>(
1617
configKey: string,
1718
canonicalEndpointParamKey: string,
18-
config: Config
19+
config: Config,
20+
isClientContextParam = false
1921
) => {
2022
const configProvider = async () => {
21-
// Check clientContextParams first for client context parameters
22-
const clientContextParams = config.clientContextParams as Record<string, unknown> | undefined;
23-
const nestedValue: unknown = clientContextParams?.[configKey] ?? clientContextParams?.[canonicalEndpointParamKey];
24-
// Fall back to direct config properties
25-
const configValue: unknown = nestedValue ?? config[configKey] ?? config[canonicalEndpointParamKey];
23+
let configValue: unknown;
24+
25+
if (isClientContextParam) {
26+
// For client context parameters, check clientContextParams first
27+
const clientContextParams = config.clientContextParams as Record<string, unknown> | undefined;
28+
const nestedValue: unknown = clientContextParams?.[configKey] ?? clientContextParams?.[canonicalEndpointParamKey];
29+
configValue = nestedValue ?? config[configKey] ?? config[canonicalEndpointParamKey];
30+
} else {
31+
// For built-in parameters, only check direct config properties
32+
configValue = config[configKey] ?? config[canonicalEndpointParamKey];
33+
}
34+
2635
if (typeof configValue === "function") {
2736
return configValue();
2837
}

packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ export const resolveParams = async <
7878
instructionsSupplier: EndpointParameterInstructionsSupplier,
7979
clientConfig: Partial<EndpointResolvedConfig<T>> & Config
8080
) => {
81-
// Initialize clientContextParams to empty object if undefined
82-
const config = clientConfig as typeof clientConfig & { clientContextParams?: Record<string, unknown> };
83-
if (config.clientContextParams === undefined) {
84-
config.clientContextParams = {};
85-
}
8681
const endpointParams: EndpointParameters = {};
8782
const instructions: EndpointParameterInstructions = instructionsSupplier?.getEndpointParameterInstructions?.() || {};
8883

@@ -95,8 +90,10 @@ export const resolveParams = async <
9590
endpointParams[name] = commandInput[instruction.name] as string | boolean;
9691
break;
9792
case "clientContextParams":
93+
endpointParams[name] = await createConfigValueProvider<Config>(instruction.name, name, clientConfig, true)();
94+
break;
9895
case "builtInParams":
99-
endpointParams[name] = await createConfigValueProvider<Config>(instruction.name, name, clientConfig)();
96+
endpointParams[name] = await createConfigValueProvider<Config>(instruction.name, name, clientConfig, false)();
10097
break;
10198
case "operationContextParams":
10299
endpointParams[name] = instruction.get(commandInput);

private/my-local-model-schema/src/endpoint/EndpointParameters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// smithy-typescript generated code
2-
import type { Endpoint, EndpointParameters as __EndpointParameters, EndpointV2, Provider } from "@smithy/types";
2+
import { type Endpoint, type EndpointV2, EndpointParameters as __EndpointParameters, Provider } from "@smithy/types";
33

44
/**
55
* @public

private/my-local-model/src/endpoint/EndpointParameters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// smithy-typescript generated code
2-
import type { Endpoint, EndpointParameters as __EndpointParameters, EndpointV2, Provider } from "@smithy/types";
2+
import { type Endpoint, type EndpointV2, EndpointParameters as __EndpointParameters, Provider } from "@smithy/types";
33

44
/**
55
* @public

private/smithy-rpcv2-cbor-schema/src/endpoint/EndpointParameters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// smithy-typescript generated code
2-
import type { Endpoint, EndpointParameters as __EndpointParameters, EndpointV2, Provider } from "@smithy/types";
2+
import { type Endpoint, type EndpointV2, EndpointParameters as __EndpointParameters, Provider } from "@smithy/types";
33

44
/**
55
* @public

private/smithy-rpcv2-cbor/src/endpoint/EndpointParameters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// smithy-typescript generated code
2-
import type { Endpoint, EndpointParameters as __EndpointParameters, EndpointV2, Provider } from "@smithy/types";
2+
import { type Endpoint, type EndpointV2, EndpointParameters as __EndpointParameters, Provider } from "@smithy/types";
33

44
/**
55
* @public

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ private void generateEndpointParameters() {
259259
if (hasDefaultsForResolve) {
260260
writer.write(
261261
"clientContextParams: Object.assign(clientContextParamDefaults, "
262-
+ "options.clientContextParams ?? {}),"
262+
+ "options.clientContextParams),"
263263
);
264264
} else {
265265
writer.write(

smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2GeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void containsExtraContextParameter() {
5656
return Object.assign(options, {
5757
stage: options.stage ?? "production",
5858
defaultSigningName: "",
59-
clientContextParams: Object.assign(clientContextParamDefaults, options.clientContextParams ?? {}),
59+
clientContextParams: Object.assign(clientContextParamDefaults, options.clientContextParams),
6060
});
6161
"""));
6262
assertThat(endpointParameters, containsString(

0 commit comments

Comments
 (0)