Skip to content

Commit d598742

Browse files
authored
Don't fail anyOf on warnings (#3469)
* Don't fail anyOf on warnings
1 parent 9f6e8f4 commit d598742

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/cfnlint/jsonschema/_keywords.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ def anyOf(
105105
)
106106
all_errors = []
107107
for index, subschema in enumerate(anyOf):
108-
errs = list(validator.descend(instance, subschema, schema_path=index))
108+
errs = []
109+
# warning and informational errors need to be returned but shouldn't
110+
# be part of if the anyOf is valid
111+
for err in validator.descend(instance, subschema, schema_path=index):
112+
if err.rule is not None and not err.rule.id.startswith("E"):
113+
yield err
114+
continue
115+
errs.append(err)
109116
if not errs:
110117
break
111118
all_errors.extend(errs)

test/unit/module/jsonschema/test_keywords.py

+39
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@ def validate(self, validator, s, instance, schema):
2323
)
2424

2525

26+
class Warning(CloudFormationLintRule):
27+
id = "W1111"
28+
29+
def validate(self, validator, s, instance, schema):
30+
yield ValidationError(
31+
"Warning",
32+
rule=self,
33+
)
34+
35+
2636
@pytest.fixture
2737
def validator():
2838
validator = CfnTemplateValidator(schema={})
2939
validator = validator.extend(
3040
validators={
3141
"error": Error().validate,
42+
"warning": Warning().validate,
3243
}
3344
)
3445
return validator({})
@@ -77,6 +88,34 @@ def validator():
7788
),
7889
],
7990
),
91+
(
92+
"Valid anyOf with a warning validation error",
93+
"foo",
94+
[{"warning": True}, {"error": True}],
95+
[
96+
ValidationError(
97+
"Warning",
98+
rule=Warning(),
99+
path=deque([]),
100+
validator="warning",
101+
schema_path=deque([0, "warning"]),
102+
),
103+
],
104+
),
105+
(
106+
"Valid anyOf with a warning validation error",
107+
"foo",
108+
[{"error": True}, {"warning": True}],
109+
[
110+
ValidationError(
111+
"Warning",
112+
rule=Warning(),
113+
path=deque([]),
114+
validator="warning",
115+
schema_path=deque([1, "warning"]),
116+
),
117+
],
118+
),
80119
],
81120
)
82121
def test_anyof(name, instance, schema, validator, expected):

0 commit comments

Comments
 (0)