Skip to content
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

fix(endpoints): move AWS name map to JSv3, additional fixes for all-service endpoint compilation #614

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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