From d0465c053a8208de5a718296b8b751e3f1911cb3 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Fri, 5 Jul 2024 15:09:20 -0700 Subject: [PATCH 1/2] Don't fail anyOf on 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..4cc52599be 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( + "Error", + rule=Warning(), + path=deque([]), + validator="warning", + schema_path=deque([0, "warning"]), + ), + ], + ), + ( + "Valid anyOf with a warning validation error", + "foo", + [{"error": True}, {"warning": True}], + [ + ValidationError( + "Error", + rule=Warning(), + path=deque([]), + validator="warning", + schema_path=deque([0, "warning"]), + ), + ], + ), ], ) def test_anyof(name, instance, schema, validator, expected): From aabc863b234daebcaccbaeb54b6920c7d563abc3 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Fri, 5 Jul 2024 15:22:35 -0700 Subject: [PATCH 2/2] Don't fail anyOf on warnings --- test/unit/module/jsonschema/test_keywords.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/module/jsonschema/test_keywords.py b/test/unit/module/jsonschema/test_keywords.py index 4cc52599be..6849d53fe6 100644 --- a/test/unit/module/jsonschema/test_keywords.py +++ b/test/unit/module/jsonschema/test_keywords.py @@ -94,7 +94,7 @@ def validator(): [{"warning": True}, {"error": True}], [ ValidationError( - "Error", + "Warning", rule=Warning(), path=deque([]), validator="warning", @@ -108,11 +108,11 @@ def validator(): [{"error": True}, {"warning": True}], [ ValidationError( - "Error", + "Warning", rule=Warning(), path=deque([]), validator="warning", - schema_path=deque([0, "warning"]), + schema_path=deque([1, "warning"]), ), ], ),