Skip to content

Commit

Permalink
fix(endpoints): move AWS name map to JSv3, additional fixes for all-s…
Browse files Browse the repository at this point in the history
…ervice endpoint compilation (#614)
  • Loading branch information
kuhe authored Oct 14, 2022
1 parent b9ed0c5 commit 0f27d51
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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;");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<String, String> MAPPING = MapUtils.of(
"Region", "region",
"UseFIPS", "useFipsEndpoint",
"UseDualStack", "useDualstackEndpoint",
"ForcePathStyle", "forcePathStyle",
"Accelerate", "useAccelerateEndpoint",
"DisableMRAP", "disableMultiregionAccessPoints",
"UseArnRegion", "useArnRegion"
);
private static final Map<String, String> MAPPING = new HashMap<>();

private EndpointsParamNameMap() {}

public static void setNameMapping(Map<String, String> parameterNameMap) {
EndpointsParamNameMap.MAPPING.clear();
MAPPING.putAll(parameterNameMap);
}

public static void addNameMapping(Map<String, String> parameterNameMap) {
MAPPING.putAll(parameterNameMap);
}

public static String getLocalName(String endpointsV2ParamName) {
return MAPPING.getOrDefault(endpointsV2ParamName, endpointsV2ParamName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 {",
Expand All @@ -81,7 +82,9 @@ private void generateEndpointParameters() {
}
);

writer.write("");
writer.write("export type ClientResolvedEndpointParameters = ClientInputEndpointParameters;");
writer.write("");

writer.openBlock(
"export const resolveClientEndpointParameters = "
Expand All @@ -99,6 +102,7 @@ private void generateEndpointParameters() {
}
);

writer.write("");
writer.openBlock(
"export interface EndpointParameters extends __EndpointParameters {",
"}",
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -102,14 +102,18 @@ public Map.Entry<String, String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 0f27d51

Please sign in to comment.