diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java index 417bc1627e6..2dfa663aded 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java @@ -43,14 +43,23 @@ public List validate(Model model) { List events = new LinkedList<>(); TopDownIndex topDownIndex = TopDownIndex.of(model); AwsTagIndex tagIndex = AwsTagIndex.of(model); - for (ServiceShape service : model.getServiceShapesWithTrait(TagEnabledTrait.class)) { + for (ServiceShape service : model.getServiceShapes()) { for (ResourceShape resource : topDownIndex.getContainedResources(service)) { + boolean resourceLikelyTaggable = false; if (resource.hasTrait(TaggableTrait.class)) { events.addAll(validateResource(model, resource, service, tagIndex)); - } else if (resource.hasTrait(ArnTrait.class) && tagIndex.serviceHasTagApis(service.getId())) { + resourceLikelyTaggable = true; + } else if (resource.hasTrait(ArnTrait.class) && tagIndex.serviceHasTagApis(service)) { // If a resource does not have the taggable trait, but has an ARN, and the service has tag // operations, it is most likely a mistake. events.add(warning(resource, "Resource is likely missing `aws.api#taggable` trait.")); + resourceLikelyTaggable = true; + } + + // It's possible the resource was marked as taggable but the service isn't tagEnabled. + if (resourceLikelyTaggable && !service.hasTrait(TagEnabledTrait.class)) { + events.add(warning(service, "Service has resources with `aws.api#taggable` applied but does not " + + "have the `aws.api#tagEnabled` trait.")); } } } diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/tagging/tagging-warnings.errors b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/tagging/tagging-warnings.errors index eb96150771a..494564873da 100644 --- a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/tagging/tagging-warnings.errors +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/tagging/tagging-warnings.errors @@ -3,3 +3,4 @@ [WARNING] example.weather#Weather: Service marked `aws.api#TagEnabled` is missing an operation named 'UntagResource.' | ServiceTagging [WARNING] example.weather#City: Suggested tag property name is '[T|t]ags'. | TagResourcePropertyName [DANGER] example.weather#UpdateCity: Update and put resource lifecycle operations should not support updating tags because it is a privileged operation that modifies access. | TaggableResource +[WARNING] example.weather#Weather2: Service has resources with `aws.api#taggable` applied but does not have the `aws.api#tagEnabled` trait. | TaggableResource diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/tagging/tagging-warnings.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/tagging/tagging-warnings.smithy index b15aeecee53..420f0c5882f 100644 --- a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/tagging/tagging-warnings.smithy +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/tagging/tagging-warnings.smithy @@ -19,6 +19,11 @@ service Weather { operations: [GetCurrentTime] } +service Weather2 { + version: "2006-03-01", + resources: [City] +} + structure Tag { key: String value: String