Repository: smithy-lang/smithy
Pull request #2444 (2024-11-07 17:56:36)

Fix for tagsProperty in CFN schema creation
This value is expected to be a JSON pointer to a property, not just the name of the property.

See: https://github.com/aws-cloudformation/cloudformation-cli/blob/master/src/rpdk/core/data/schema/provider.definition.schema.v1.json#L193-L197

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.



Patch:
diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java
index c6c79e352..bf9988725 100644
--- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java
+++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java
@@ -311,7 +311,7 @@ public final class CfnConverter {
             Tagging.Builder tagBuilder = Tagging.builder()
                     .taggable(true)
                     .tagOnCreate(tagsIndex.isResourceTagOnCreate(resourceShape.getId()))
-                    .tagProperty(getTagsProperty(resourceShape))
+                    .tagProperty("/properties/" + getTagMemberName(resourceShape))
                     .cloudFormationSystemTags(!trait.getDisableSystemTags())
                     // Unless tag-on-create is supported, Smithy tagging means
                     .tagUpdatable(true);
@@ -396,7 +396,7 @@ public final class CfnConverter {
         return builder.build();
     }
 
-    private String getTagsProperty(ResourceShape resource) {
+    private String getTagMemberName(ResourceShape resource) {
         return resource.getTrait(TaggableTrait.class)
                 .flatMap(TaggableTrait::getProperty)
                 .map(property -> {
@@ -414,7 +414,7 @@ public final class CfnConverter {
         ResourceShape resource,
         CfnResource cfnResource
     ) {
-        String tagPropertyName = getTagsProperty(resource);
+        String tagMemberName = getTagMemberName(resource);
         if (resource.hasTrait(TaggableTrait.class)) {
             AwsTagIndex tagIndex = AwsTagIndex.of(model);
             TaggableTrait trait = resource.expectTrait(TaggableTrait.class);
@@ -422,13 +422,13 @@ public final class CfnConverter {
                     .containsKey(trait.getProperty().get())) {
                 if (trait.getProperty().isPresent()) {
                     ShapeId definition = resource.getProperties().get(trait.getProperty().get());
-                    builder.addMember(tagPropertyName, definition);
+                    builder.addMember(tagMemberName, definition);
                 } else {
                     // A valid TagResource operation certainly has a single tags input member.
                     AwsTagIndex awsTagIndex = AwsTagIndex.of(model);
                     Optional<ShapeId> tagOperation = tagIndex.getTagResourceOperation(resource.getId());
                     MemberShape member = awsTagIndex.getTagsMember(tagOperation.get()).get();
-                    member = member.toBuilder().id(builder.getId().withMember(tagPropertyName)).build();
+                    member = member.toBuilder().id(builder.getId().withMember(tagMemberName)).build();
                     builder.addMember(member);
                 }
             }


Test patch:
diff --git a/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/weather-service-wide.cfn.json b/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/weather-service-wide.cfn.json
index 15d71ee79..7a9311de5 100644
--- a/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/weather-service-wide.cfn.json
+++ b/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/weather-service-wide.cfn.json
@@ -80,7 +80,7 @@
     },
     "tagging": {
         "tagOnCreate": false,
-        "tagProperty": "Tags",
+        "tagProperty": "/properties/Tags",
         "tagUpdatable": true,
         "cloudFormationSystemTags": true,
         "taggable": true
diff --git a/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/weather.cfn.json b/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/weather.cfn.json
index f011c04cf..7dd4df090 100644
--- a/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/weather.cfn.json
+++ b/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/weather.cfn.json
@@ -79,7 +79,7 @@
     },
     "tagging": {
         "tagOnCreate": false,
-        "tagProperty": "Tags",
+        "tagProperty": "/properties/Tags",
         "tagUpdatable": true,
         "cloudFormationSystemTags": true,
         "taggable": true