Skip to content

Commit

Permalink
get the default region from the spec
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp committed Sep 12, 2022
1 parent 6b615ac commit 644d1a8
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj

Object lambda = objs.get("lambda");
List<CodegenServer> servers = (List<CodegenServer>) objs.get("servers");
boolean hasRegionalHost = servers
.stream()
.anyMatch(server -> server.variables.stream().anyMatch(variable -> variable.name.equals("region")));
CodegenServerVariable regionVariable = null;
outerLoop:for (CodegenServer server : servers) {
for (CodegenServerVariable var : server.variables) {
if (var.name.equals("region")) {
regionVariable = var;
break outerLoop;
}
}
}
boolean hasRegionalHost = regionVariable != null;

Map<String, Object> bundle = objs;
bundle.clear();
Expand All @@ -106,7 +113,9 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
bundle.put("client", Utils.createClientName(importClientName, language) + "Client");
bundle.put("clientPrefix", Utils.createClientName(importClientName, language));
bundle.put("hasRegionalHost", hasRegionalHost);
bundle.put("defaultRegion", client.equals("predict") ? "eu" : "us");
if (hasRegionalHost) {
bundle.put("defaultRegion", regionVariable.defaultValue);
}
bundle.put("lambda", lambda);

ctsManager.addDataToBundle(bundle);
Expand Down

0 comments on commit 644d1a8

Please sign in to comment.