diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java index 9749f0de3d3..76820c25a3c 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -235,9 +235,6 @@ private void generateCommandMiddlewareResolver(String configType) { // Add serialization and deserialization plugin. writer.write("this.middlewareStack.use($T(configuration, this.serialize, this.deserialize));", serde); - // Add customizations. - addCommandSpecificPlugins(); - // EndpointsV2 if (service.hasTrait(EndpointRuleSetTrait.class)) { writer.addImport( @@ -254,6 +251,9 @@ private void generateCommandMiddlewareResolver(String configType) { ); } + // Add customizations. + addCommandSpecificPlugins(); + // Resolve the middleware stack. writer.write("\nconst stack = clientStack.concat(this.middlewareStack);\n"); writer.write("const { logger } = configuration;"); diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsParamNameMap.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsParamNameMap.java index f7898911d85..c3d2bd7d46a 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsParamNameMap.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsParamNameMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -15,26 +15,28 @@ package software.amazon.smithy.typescript.codegen.endpointsV2; +import java.util.HashMap; import java.util.Map; -import software.amazon.smithy.utils.MapUtils; - +/** + * Map of EndpointsV2 canonical ruleset param name to generated code param names. + * This allows continuity for parameter names that were decided prior to EndpointsV2 + * and differ from their EndpointsV2 name. + */ public final class EndpointsParamNameMap { - /** - * Map of EndpointsV2 ruleset param name to existing JSv3 config param names. - */ - private static final Map MAPPING = MapUtils.of( - "Region", "region", - "UseFIPS", "useFipsEndpoint", - "UseDualStack", "useDualstackEndpoint", - "ForcePathStyle", "forcePathStyle", - "Accelerate", "useAccelerateEndpoint", - "DisableMRAP", "disableMultiregionAccessPoints", - "UseArnRegion", "useArnRegion" - ); + private static final Map MAPPING = new HashMap<>(); private EndpointsParamNameMap() {} + public static void setNameMapping(Map parameterNameMap) { + EndpointsParamNameMap.MAPPING.clear(); + MAPPING.putAll(parameterNameMap); + } + + public static void addNameMapping(Map parameterNameMap) { + MAPPING.putAll(parameterNameMap); + } + public static String getLocalName(String endpointsV2ParamName) { return MAPPING.getOrDefault(endpointsV2ParamName, endpointsV2ParamName); } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java index 8b83cf35de5..3de2e73c38e 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2Generator.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -64,6 +64,7 @@ private void generateEndpointParameters() { TypeScriptWriter writer = new TypeScriptWriter(""); writer.addImport("EndpointParameters", "__EndpointParameters", "@aws-sdk/types"); + writer.addImport("Provider", null, "@aws-sdk/types"); writer.openBlock( "export interface ClientInputEndpointParameters {", @@ -81,7 +82,9 @@ private void generateEndpointParameters() { } ); + writer.write(""); writer.write("export type ClientResolvedEndpointParameters = ClientInputEndpointParameters;"); + writer.write(""); writer.openBlock( "export const resolveClientEndpointParameters = " @@ -99,6 +102,7 @@ private void generateEndpointParameters() { } ); + writer.write(""); writer.openBlock( "export interface EndpointParameters extends __EndpointParameters {", "}", diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/ParameterGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/ParameterGenerator.java index bcca3149779..bbf59e21dc0 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/ParameterGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/ParameterGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -102,14 +102,18 @@ public Map.Entry getNameAndType() { /** * Used to generate interface line for EndpointParameters.ts. */ - public String toCodeString() { + public String toCodeString(boolean isClientContextParam) { String buffer = ""; buffer += parameterName; - if (!required || hasDefault()) { + if (!required || hasDefault() || isClientContextParam) { buffer += "?"; } buffer += ": "; - buffer += tsParamType + ";"; + if (isClientContextParam) { + buffer += (tsParamType + "|" + "Provider<" + tsParamType + ">") + ";"; + } else { + buffer += tsParamType + ";"; + } return buffer; } } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java index c9878972ff5..3da1217bc5d 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParameterFinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParametersVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParametersVisitor.java index a03bba6f748..6be4352a9d2 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParametersVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetParametersVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -69,7 +69,8 @@ public Void objectNode(ObjectNode node) { writer.write(parameterGenerator.defaultAsCodeString()); } } else if (clientContextParams.isEmpty() || clientContextParams.containsKey(key)) { - writer.write(parameterGenerator.toCodeString()); + boolean isClientContextParams = !clientContextParams.isEmpty(); + writer.write(parameterGenerator.toCodeString(isClientContextParams)); } } return null; diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetSerializer.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetSerializer.java index dfbb8d4ca05..dd3018729a5 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetSerializer.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/RuleSetSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License.