Skip to content

Commit

Permalink
fix codegen for path prefix (#2700)
Browse files Browse the repository at this point in the history
* fix codegen for path prefix
  • Loading branch information
DmitriyMusatkin authored Oct 9, 2023
1 parent d323938 commit 88cfe94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.cpp.CppViewHelper;

@Data
public class Endpoint {
private static final Pattern MEMBER_PATTERN = Pattern.compile("\\{[\\w\\d]+\\}");
Expand Down Expand Up @@ -41,11 +43,14 @@ public String constructHostPrefixString(String memberPrefix) {
String ret = "";
List<String> parts = getHostPrefixParts();
List<String> members = getMemberReferences();
// {var1}-{var2}.123.{var3}, with prefix to be "Reqeust"
//-> Request.Getvar1() + "-" + Request.Getvar2() + ".123." + Request.Getvar3()
// {var1}-{var2}.123.{var3}, with prefix to be "Request"
//-> Request.GetVar1() + "-" + Request.GetVar2() + ".123." + Request.GetVar3()
for (int i = 0; i < members.size(); i++)
{
ret += "\"" + parts.get(i) + "\" + " + memberPrefix + ".Get" + members.get(i) + "() + ";
// Capitalize first letter, we always do it for getters regardless
// of casing on the field.
String member = CppViewHelper.capitalizeFirstChar(members.get(i));
ret += "\"" + parts.get(i) + "\" + " + memberPrefix + ".Get" + member + "() + ";
}
ret += "\"" + parts.get(parts.size() - 1) + "\"";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class EndpointTest {
public void testParseHostPrefixParts() {
Endpoint endpoint = new Endpoint();

endpoint.setHostPrefix("abc{var1}-{var2}.{var3}12.3{var4}{var5}");
endpoint.setHostPrefix("abc{Var1}-{var2}.{var3}12.3{var4}{var5}");
List<String> parts = endpoint.getHostPrefixParts();
assertEquals(6, parts.size());
assertEquals("abc", parts.get(0));
Expand All @@ -30,16 +30,16 @@ public void testParseHostPrefixParts() {

List<String> members = endpoint.getMemberReferences();
assertEquals(5, members.size());
assertEquals("var1", members.get(0));
assertEquals("Var1", members.get(0));
assertEquals("var2", members.get(1));
assertEquals("var3", members.get(2));
assertEquals("var4", members.get(3));
assertEquals("var5", members.get(4));

String hostPrefix = "\"abc\" + request.Getvar1() + \"-\" + request.Getvar2() + \".\" + request.Getvar3() + \"12.3\" + request.Getvar4() + \"\" + request.Getvar5() + \"\"";
String hostPrefix = "\"abc\" + request.GetVar1() + \"-\" + request.GetVar2() + \".\" + request.GetVar3() + \"12.3\" + request.GetVar4() + \"\" + request.GetVar5() + \"\"";
assertEquals(hostPrefix, endpoint.constructHostPrefixString("request"));

endpoint.setHostPrefix("{var1}-{var2}.{var3}123{var4}{var5}");
endpoint.setHostPrefix("{Var1}-{var2}.{var3}123{var4}{var5}");
parts = endpoint.getHostPrefixParts();
assertEquals(6, parts.size());
assertEquals("", parts.get(0)); // before {var1}
Expand All @@ -51,16 +51,16 @@ public void testParseHostPrefixParts() {

members = endpoint.getMemberReferences();
assertEquals(5, members.size());
assertEquals("var1", members.get(0));
assertEquals("Var1", members.get(0));
assertEquals("var2", members.get(1));
assertEquals("var3", members.get(2));
assertEquals("var4", members.get(3));
assertEquals("var5", members.get(4));

hostPrefix = "\"\" + request.Getvar1() + \"-\" + request.Getvar2() + \".\" + request.Getvar3() + \"123\" + request.Getvar4() + \"\" + request.Getvar5() + \"\"";
hostPrefix = "\"\" + request.GetVar1() + \"-\" + request.GetVar2() + \".\" + request.GetVar3() + \"123\" + request.GetVar4() + \"\" + request.GetVar5() + \"\"";
assertEquals(hostPrefix, endpoint.constructHostPrefixString("request"));

endpoint.setHostPrefix("{var1}-{var2}.{var3}123{var4}{var5}abc");
endpoint.setHostPrefix("{Var1}-{var2}.{var3}123{var4}{var5}abc");
parts = endpoint.getHostPrefixParts();
assertEquals(6, parts.size());
assertEquals("", parts.get(0));
Expand All @@ -72,13 +72,13 @@ public void testParseHostPrefixParts() {

members = endpoint.getMemberReferences();
assertEquals(5, members.size());
assertEquals("var1", members.get(0));
assertEquals("Var1", members.get(0));
assertEquals("var2", members.get(1));
assertEquals("var3", members.get(2));
assertEquals("var4", members.get(3));
assertEquals("var5", members.get(4));

hostPrefix = "\"\" + request.Getvar1() + \"-\" + request.Getvar2() + \".\" + request.Getvar3() + \"123\" + request.Getvar4() + \"\" + request.Getvar5() + \"abc\"";
hostPrefix = "\"\" + request.GetVar1() + \"-\" + request.GetVar2() + \".\" + request.GetVar3() + \"123\" + request.GetVar4() + \"\" + request.GetVar5() + \"abc\"";
assertEquals(hostPrefix, endpoint.constructHostPrefixString("request"));
}
}

0 comments on commit 88cfe94

Please sign in to comment.