diff --git a/src/cfnlint/jsonschema/_keywords.py b/src/cfnlint/jsonschema/_keywords.py index 3d9457225b..c33dde4935 100644 --- a/src/cfnlint/jsonschema/_keywords.py +++ b/src/cfnlint/jsonschema/_keywords.py @@ -104,13 +104,14 @@ def anyOf( ) ) all_errors = [] + other_errors = [] for index, subschema in enumerate(anyOf): errs = [] - # warning and informational errors need to be returned but shouldn't - # be part of if the anyOf is valid + # warning and informational shouldn't count towards if anyOf is + # valid. Save W, I errors and return if errors exist 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 + other_errors.append(err) continue errs.append(err) if not errs: @@ -119,7 +120,7 @@ def anyOf( else: yield ValidationError( f"{instance!r} is not valid under any of the given schemas", - context=all_errors, + context=all_errors + other_errors, ) diff --git a/test/unit/module/jsonschema/test_keywords.py b/test/unit/module/jsonschema/test_keywords.py index 6849d53fe6..00fa2dab17 100644 --- a/test/unit/module/jsonschema/test_keywords.py +++ b/test/unit/module/jsonschema/test_keywords.py @@ -91,30 +91,43 @@ def validator(): ( "Valid anyOf with a warning validation error", "foo", - [{"warning": True}, {"error": True}], + [{"warning": True, "error": True}, {"error": True}], [ ValidationError( - "Warning", - rule=Warning(), + "'foo' is not valid under any of the given schemas", path=deque([]), - validator="warning", - schema_path=deque([0, "warning"]), + schema_path=deque([]), + context=[ + ValidationError( + "Error", + rule=Error(), + path=deque([]), + validator="error", + schema_path=deque([0, "error"]), + ), + ValidationError( + "Error", + rule=Error(), + path=deque([]), + validator="error", + schema_path=deque([1, "error"]), + ), + ValidationError( + "Warning", + rule=Warning(), + path=deque([]), + validator="warning", + schema_path=deque([0, "warning"]), + ), + ], ), ], ), ( - "Valid anyOf with a warning validation error", + "Valid anyOf without a warning validation error", "foo", [{"error": True}, {"warning": True}], - [ - ValidationError( - "Warning", - rule=Warning(), - path=deque([]), - validator="warning", - schema_path=deque([1, "warning"]), - ), - ], + [], ), ], )