diff --git a/src/cfnlint/rules/resources/properties/Properties.py b/src/cfnlint/rules/resources/properties/Properties.py index 6ca95c6c45..94c91bcd09 100644 --- a/src/cfnlint/rules/resources/properties/Properties.py +++ b/src/cfnlint/rules/resources/properties/Properties.py @@ -8,7 +8,7 @@ from typing import Any from cfnlint.helpers import FUNCTIONS, is_function -from cfnlint.jsonschema import ValidationResult, Validator +from cfnlint.jsonschema import ValidationError, ValidationResult, Validator from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema from cfnlint.schema.manager import PROVIDER_SCHEMA_MANAGER @@ -87,7 +87,14 @@ def validate( properties = instance.get("Properties", {}) fn_k, fn_v = is_function(properties) if fn_k == "Ref" and fn_v == "AWS::NoValue": - properties = {} + yield ValidationError( + # Expected an object, received {"Ref":"AWS::NoValue"} + message=f"{properties!r} is not of type object", + path=deque(["Properties", fn_k]), + rule=self.child_rules.get(self.rule_set.get("type")), # type: ignore + validator="type", + ) + return for regions, schema in PROVIDER_SCHEMA_MANAGER.get_resource_schemas_by_regions( t, validator.context.regions diff --git a/test/unit/rules/resources/properties/test_properties.py b/test/unit/rules/resources/properties/test_properties.py index c25fd33ec9..bffae12066 100644 --- a/test/unit/rules/resources/properties/test_properties.py +++ b/test/unit/rules/resources/properties/test_properties.py @@ -54,15 +54,15 @@ def rule(): ], ), ( - "Valid type but no required fields", + "Invalid with Ref AWS::NoValue", {"Type": "MyType", "Properties": {"Ref": "AWS::NoValue"}}, - [(["us-east-1"], Schema({"typeName": "MyType", "required": ["Name"]}))], + [], [ ValidationError( - "'Name' is a required property", - validator="required", - path=deque(["Properties"]), - schema_path=deque(["required"]), + "{'Ref': 'AWS::NoValue'} is not of type object", + validator="type", + path=deque(["Properties", "Ref"]), + rule=None, ) ], ),