Skip to content

Commit

Permalink
Better type checking for Null types (#3557)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Aug 1, 2024
1 parent 70c71eb commit 8bd553d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cfnlint/jsonschema/_keywords_cfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def validate(
# Type checks
#####
def _raw_type(validator: Validator, tS: Any, instance: Any) -> bool:
if tS in ["object", "array"]:
if tS in ["object", "array", "null"] or validator.is_type(instance, "null"):
return validator.is_type(instance, tS)
if "string" == tS:
if validator.is_type(instance, "object") or validator.is_type(
Expand Down
26 changes: 26 additions & 0 deletions test/unit/module/jsonschema/test_keywords_cfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,32 @@ def test_standard_values(self):
self.build_execute_tests(True, ["string", "boolean"])
self.build_execute_tests("true", ["string", "boolean"])

def test_null_values(self):
self.message_errors(
"Null value with string type",
None,
["None is not of type 'string'"],
{"type": "string"},
)
self.message_errors(
"String value with null type",
"foo",
["'foo' is not of type 'null'"],
{"type": "null"},
)
self.message_errors(
"Object value with null type",
{},
["{} is not of type 'null'"],
{"type": "null"},
)
self.message_errors(
"None value with multiple types",
None,
[],
{"type": ["string", "null"]},
)


class TestMultiCfnTypes(Base):
def build_execute_tests(self, instance, supported_types, unsupported_type) -> None:
Expand Down

0 comments on commit 8bd553d

Please sign in to comment.