Skip to content

Commit

Permalink
anyOf only returns Ws and Is when there are Es (#3600)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Aug 15, 2024
1 parent 3eef025 commit a77aff2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
9 changes: 5 additions & 4 deletions src/cfnlint/jsonschema/_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
)


Expand Down
43 changes: 28 additions & 15 deletions test/unit/module/jsonschema/test_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
),
],
[],
),
],
)
Expand Down

0 comments on commit a77aff2

Please sign in to comment.