1818import software .amazon .smithy .model .shapes .Shape ;
1919import software .amazon .smithy .model .shapes .ShapeId ;
2020import software .amazon .smithy .model .shapes .StructureShape ;
21+ import software .amazon .smithy .utils .StringUtils ;
2122
2223/**
2324 * Logic for validating that a shape looks like a tag.
@@ -30,7 +31,7 @@ final class TaggingShapeUtils {
3031 private static final Pattern TAG_PROPERTY_REGEX = Pattern
3132 .compile ("^[T|t]ag(s|[L|l]ist)$" );
3233 private static final Pattern RESOURCE_ARN_REGEX = Pattern
33- .compile ("^([R|r]esource)?([A|a]rn|ARN)$" );
34+ .compile ("^([R|r]esource)?([A|a]rn|ARN)? $" );
3435 private static final Pattern TAG_KEYS_REGEX = Pattern
3536 .compile ("^[T|t]ag[K|k]eys$" );
3637
@@ -41,32 +42,29 @@ static String getDesiredTagsPropertyName() {
4142 return "[T|t]ags" ;
4243 }
4344
44- // Recommended name is more limited than the accepted regular expression.
45- static String getDesiredArnName () {
46- return "[R|r]esourceArn" ;
47- }
48-
49- // Recommended name is more limited than the accepted regular expression.
50- static String getDesiredTagKeysName () {
51- return "[T|t]agKeys" ;
52- }
53-
5445 // Used to validate tag property name and tag member name.
5546 static boolean isTagDesiredName (String memberName ) {
5647 return TAG_PROPERTY_REGEX .matcher (memberName ).matches ();
5748 }
5849
5950 // Used for checking if member name is good for resource ARN input.
6051 static boolean isArnMemberDesiredName (String memberName ) {
61- return RESOURCE_ARN_REGEX .matcher (memberName ).matches ();
52+ if (StringUtils .isEmpty (memberName )) {
53+ return false ;
54+ }
55+
56+ return memberName
57+ .replaceFirst ("^[R|r]esource" , "" )
58+ .replaceFirst ("[A|a]rn|ARN$" , "" )
59+ .isEmpty ();
6260 }
6361
6462 // Used for checking if member name is good for tag keys input for untag operation.
6563 static boolean isTagKeysDesiredName (String memberName ) {
6664 return TAG_KEYS_REGEX .matcher (memberName ).matches ();
6765 }
6866
69- static boolean hasResourceArnInput (Map <String , MemberShape > inputMembers , Model model ) {
67+ private static boolean hasResourceArnInput (Map <String , MemberShape > inputMembers , Model model ) {
7068 for (Map .Entry <String , MemberShape > memberEntry : inputMembers .entrySet ()) {
7169 if (isArnMemberDesiredName (memberEntry .getKey ())
7270 && model .expectShape (memberEntry .getValue ().getTarget ()).isStringShape ()) {
@@ -89,7 +87,7 @@ static boolean verifyTagsShape(Model model, Shape tagShape) {
8987 return verifyTagListShape (model , tagShape ) || verifyTagMapShape (model , tagShape );
9088 }
9189
92- static boolean verifyTagListShape (Model model , Shape tagShape ) {
90+ private static boolean verifyTagListShape (Model model , Shape tagShape ) {
9391 if (tagShape .isListShape ()) {
9492 ListShape listShape = tagShape .asListShape ().get ();
9593 Shape listTargetShape = model .expectShape (listShape .getMember ().getTarget ());
@@ -108,7 +106,7 @@ static boolean verifyTagListShape(Model model, Shape tagShape) {
108106 return false ;
109107 }
110108
111- static boolean verifyTagMapShape (Model model , Shape tagShape ) {
109+ private static boolean verifyTagMapShape (Model model , Shape tagShape ) {
112110 if (tagShape .isMapShape ()) {
113111 MapShape mapShape = tagShape .asMapShape ().get ();
114112 Shape valueTargetShape = model .expectShape (mapShape .getValue ().getTarget ());
@@ -189,7 +187,7 @@ static boolean isTagPropertyInInput(
189187 return false ;
190188 }
191189
192- static boolean isTagPropertyInShape (
190+ private static boolean isTagPropertyInShape (
193191 String tagPropertyName ,
194192 Shape shape ,
195193 PropertyBindingIndex propertyBindingIndex
0 commit comments