Skip to content

Commit 2d07e90

Browse files
committed
chore(codegen): add Endpoint class for storing endpoint configuration
1 parent 96f93e0 commit 2d07e90

File tree

1 file changed

+27
-16
lines changed
  • codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen

1 file changed

+27
-16
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/EndpointGenerator.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ final class EndpointGenerator implements Runnable {
4949
private final String endpointPrefix;
5050
private final String baseSigningService;
5151
private final Map<String, Partition> partitions = new TreeMap<>();
52-
private final Map<String, ObjectNode> endpoints = new TreeMap<>();
52+
private final Map<String, Endpoint> endpoints = new TreeMap<>();
5353

5454
EndpointGenerator(ServiceShape service, TypeScriptWriter writer) {
5555
this.writer = writer;
@@ -88,19 +88,17 @@ private void loadServiceEndpoints() {
8888
ObjectNode serviceData = partition.getService();
8989
ObjectNode endpointMap = serviceData.getObjectMember("endpoints").orElse(Node.objectNode());
9090

91-
// If partition endpoint is available, data will be populated in PartitionHash.
92-
if (!partition.getPartitionEndpoint().isPresent()) {
93-
for (Map.Entry<String, Node> entry : endpointMap.getStringMap().entrySet()) {
94-
ObjectNode config = entry.getValue().expectObjectNode();
95-
if (config.containsMember("hostname")) {
96-
// Resolve the hostname.
97-
String hostName = config.expectStringMember("hostname").getValue();
98-
hostName = hostName.replace("{dnsSuffix}", dnsSuffix);
99-
hostName = hostName.replace("{service}", endpointPrefix);
100-
hostName = hostName.replace("{region}", entry.getKey());
101-
config = config.withMember("hostname", hostName);
102-
endpoints.put(entry.getKey(), config);
103-
}
91+
for (Map.Entry<String, Node> entry : endpointMap.getStringMap().entrySet()) {
92+
ObjectNode config = entry.getValue().expectObjectNode();
93+
if (config.containsMember("hostname")) {
94+
// Resolve the hostname.
95+
String hostName = config.expectStringMember("hostname").getValue();
96+
hostName = hostName.replace("{dnsSuffix}", dnsSuffix);
97+
hostName = hostName.replace("{service}", endpointPrefix);
98+
hostName = hostName.replace("{region}", entry.getKey());
99+
config = config.withMember("hostname", hostName);
100+
Endpoint endpoint = new Endpoint(config, partition.getPartitionEndpoint().isPresent());
101+
endpoints.put(entry.getKey(), endpoint);
104102
}
105103
}
106104
}
@@ -116,8 +114,11 @@ public void run() {
116114
private void writeRegionHash() {
117115
writer.addImport("RegionHash", "RegionHash", TypeScriptDependency.CONFIG_RESOLVER.packageName);
118116
writer.openBlock("const regionHash: RegionHash = {", "};", () -> {
119-
for (Map.Entry<String, ObjectNode> entry : endpoints.entrySet()) {
120-
writeEndpointSpecificResolver(entry.getKey(), entry.getValue());
117+
for (Map.Entry<String, Endpoint> entry : endpoints.entrySet()) {
118+
Endpoint endpoint = entry.getValue();
119+
if (!endpoint.isPartitionEndpoint) {
120+
writeEndpointSpecificResolver(entry.getKey(), endpoint.config);
121+
}
121122
}
122123
});
123124
writer.write("");
@@ -174,6 +175,16 @@ private void writeEndpointSpecificResolver(String region, ObjectNode resolved) {
174175
}
175176
}
176177

178+
private final class Endpoint {
179+
final ObjectNode config;
180+
final boolean isPartitionEndpoint;
181+
182+
private Endpoint(ObjectNode config, boolean isPartitionEndpoint) {
183+
this.config = config;
184+
this.isPartitionEndpoint = isPartitionEndpoint;
185+
}
186+
}
187+
177188
private final class Partition {
178189
final ObjectNode defaults;
179190
final String hostnameTemplate;

0 commit comments

Comments
 (0)