Skip to content

Commit

Permalink
Don't fail anyOf on warnings (#3469)
Browse files Browse the repository at this point in the history
* Don't fail anyOf on warnings
  • Loading branch information
kddejong authored Jul 6, 2024
1 parent 9f6e8f4 commit d598742
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/cfnlint/jsonschema/_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions test/unit/module/jsonschema/test_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit d598742

Please sign in to comment.