Skip to content

Commit 7956245

Browse files
kuhesrchase
authored andcommitted
fix(endpoints): move AWS name map to JSv3, additional fixes for all-service endpoint compilation (smithy-lang#614)
1 parent b9c39ed commit 7956245

File tree

7 files changed

+39
-28
lines changed

7 files changed

+39
-28
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -235,9 +235,6 @@ private void generateCommandMiddlewareResolver(String configType) {
235235
// Add serialization and deserialization plugin.
236236
writer.write("this.middlewareStack.use($T(configuration, this.serialize, this.deserialize));", serde);
237237

238-
// Add customizations.
239-
addCommandSpecificPlugins();
240-
241238
// EndpointsV2
242239
if (service.hasTrait(EndpointRuleSetTrait.class)) {
243240
writer.addImport(
@@ -254,6 +251,9 @@ private void generateCommandMiddlewareResolver(String configType) {
254251
);
255252
}
256253

254+
// Add customizations.
255+
addCommandSpecificPlugins();
256+
257257
// Resolve the middleware stack.
258258
writer.write("\nconst stack = clientStack.concat(this.middlewareStack);\n");
259259
writer.write("const { logger } = configuration;");

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -15,26 +15,28 @@
1515

1616
package software.amazon.smithy.typescript.codegen.endpointsV2;
1717

18+
import java.util.HashMap;
1819
import java.util.Map;
19-
import software.amazon.smithy.utils.MapUtils;
20-
2120

21+
/**
22+
* Map of EndpointsV2 canonical ruleset param name to generated code param names.
23+
* This allows continuity for parameter names that were decided prior to EndpointsV2
24+
* and differ from their EndpointsV2 name.
25+
*/
2226
public final class EndpointsParamNameMap {
23-
/**
24-
* Map of EndpointsV2 ruleset param name to existing JSv3 config param names.
25-
*/
26-
private static final Map<String, String> MAPPING = MapUtils.of(
27-
"Region", "region",
28-
"UseFIPS", "useFipsEndpoint",
29-
"UseDualStack", "useDualstackEndpoint",
30-
"ForcePathStyle", "forcePathStyle",
31-
"Accelerate", "useAccelerateEndpoint",
32-
"DisableMRAP", "disableMultiregionAccessPoints",
33-
"UseArnRegion", "useArnRegion"
34-
);
27+
private static final Map<String, String> MAPPING = new HashMap<>();
3528

3629
private EndpointsParamNameMap() {}
3730

31+
public static void setNameMapping(Map<String, String> parameterNameMap) {
32+
EndpointsParamNameMap.MAPPING.clear();
33+
MAPPING.putAll(parameterNameMap);
34+
}
35+
36+
public static void addNameMapping(Map<String, String> parameterNameMap) {
37+
MAPPING.putAll(parameterNameMap);
38+
}
39+
3840
public static String getLocalName(String endpointsV2ParamName) {
3941
return MAPPING.getOrDefault(endpointsV2ParamName, endpointsV2ParamName);
4042
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -64,6 +64,7 @@ private void generateEndpointParameters() {
6464
TypeScriptWriter writer = new TypeScriptWriter("");
6565

6666
writer.addImport("EndpointParameters", "__EndpointParameters", "@aws-sdk/types");
67+
writer.addImport("Provider", null, "@aws-sdk/types");
6768

6869
writer.openBlock(
6970
"export interface ClientInputEndpointParameters {",
@@ -81,7 +82,9 @@ private void generateEndpointParameters() {
8182
}
8283
);
8384

85+
writer.write("");
8486
writer.write("export type ClientResolvedEndpointParameters = ClientInputEndpointParameters;");
87+
writer.write("");
8588

8689
writer.openBlock(
8790
"export const resolveClientEndpointParameters = "
@@ -99,6 +102,7 @@ private void generateEndpointParameters() {
99102
}
100103
);
101104

105+
writer.write("");
102106
writer.openBlock(
103107
"export interface EndpointParameters extends __EndpointParameters {",
104108
"}",

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -102,14 +102,18 @@ public Map.Entry<String, String> getNameAndType() {
102102
/**
103103
* Used to generate interface line for EndpointParameters.ts.
104104
*/
105-
public String toCodeString() {
105+
public String toCodeString(boolean isClientContextParam) {
106106
String buffer = "";
107107
buffer += parameterName;
108-
if (!required || hasDefault()) {
108+
if (!required || hasDefault() || isClientContextParam) {
109109
buffer += "?";
110110
}
111111
buffer += ": ";
112-
buffer += tsParamType + ";";
112+
if (isClientContextParam) {
113+
buffer += (tsParamType + "|" + "Provider<" + tsParamType + ">") + ";";
114+
} else {
115+
buffer += tsParamType + ";";
116+
}
113117
return buffer;
114118
}
115119
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -69,7 +69,8 @@ public Void objectNode(ObjectNode node) {
6969
writer.write(parameterGenerator.defaultAsCodeString());
7070
}
7171
} else if (clientContextParams.isEmpty() || clientContextParams.containsKey(key)) {
72-
writer.write(parameterGenerator.toCodeString());
72+
boolean isClientContextParams = !clientContextParams.isEmpty();
73+
writer.write(parameterGenerator.toCodeString(isClientContextParams));
7374
}
7475
}
7576
return null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)