From d598742504a6a6af0e5d882b6876f2f30007b851 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Sat, 6 Jul 2024 10:10:34 -0700 Subject: [PATCH] Don't fail anyOf on warnings (#3469) * Don't fail anyOf on warnings --- src/cfnlint/jsonschema/_keywords.py | 9 ++++- test/unit/module/jsonschema/test_keywords.py | 39 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/cfnlint/jsonschema/_keywords.py b/src/cfnlint/jsonschema/_keywords.py index fc3d2e1af2..3d9457225b 100644 --- a/src/cfnlint/jsonschema/_keywords.py +++ b/src/cfnlint/jsonschema/_keywords.py @@ -105,7 +105,14 @@ def anyOf( ) all_errors = [] for index, subschema in enumerate(anyOf): - errs = list(validator.descend(instance, subschema, schema_path=index)) + errs = [] + # warning and informational errors need to be returned but shouldn't + # be part of if the anyOf is valid + for err in validator.descend(instance, subschema, schema_path=index): + if err.rule is not None and not err.rule.id.startswith("E"): + yield err + continue + errs.append(err) if not errs: break all_errors.extend(errs) diff --git a/test/unit/module/jsonschema/test_keywords.py b/test/unit/module/jsonschema/test_keywords.py index 592ae66673..6849d53fe6 100644 --- a/test/unit/module/jsonschema/test_keywords.py +++ b/test/unit/module/jsonschema/test_keywords.py @@ -23,12 +23,23 @@ def validate(self, validator, s, instance, schema): ) +class Warning(CloudFormationLintRule): + id = "W1111" + + def validate(self, validator, s, instance, schema): + yield ValidationError( + "Warning", + rule=self, + ) + + @pytest.fixture def validator(): validator = CfnTemplateValidator(schema={}) validator = validator.extend( validators={ "error": Error().validate, + "warning": Warning().validate, } ) return validator({}) @@ -77,6 +88,34 @@ def validator(): ), ], ), + ( + "Valid anyOf with a warning validation error", + "foo", + [{"warning": True}, {"error": True}], + [ + ValidationError( + "Warning", + rule=Warning(), + path=deque([]), + validator="warning", + schema_path=deque([0, "warning"]), + ), + ], + ), + ( + "Valid anyOf with a warning validation error", + "foo", + [{"error": True}, {"warning": True}], + [ + ValidationError( + "Warning", + rule=Warning(), + path=deque([]), + validator="warning", + schema_path=deque([1, "warning"]), + ), + ], + ), ], ) def test_anyof(name, instance, schema, validator, expected):