Open
Description
Given the following schema:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"some_date": {
"type": ["string", "null"],
"format": "date-time"
}
},
"required": ["some_date"],
"additionalProperties": false
}
And the following json:
{
"some_date": null
}
I would expect validation to pass. However it tells me "None is not a 'date-time'":
❧ check-jsonschema --schemafile nullable.schema.json nullable-null.json
Schema validation errors were encountered.
nullable-null.json::$.some_date: None is not a 'date-time'
I would expect it to pass validation since it does when run through the underlying python library:
from jsonschema import validate
from jsonschema import Draft202012Validator
schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"some_date": {
"type": ["string", "null"],
"format": "date",
},
},
"required": ["some_date"],
}
objs = [
{"some_date": None},
{"some_date": "adiofns"}, # included to show that it will error on a string with the incorrect format
{"some_date": "2023-10-01"},
]
for obj in objs:
try:
validate(obj, schema, format_checker=Draft202012Validator.FORMAT_CHECKER)
except Exception as e:
print(f"---\nValidation failed for {obj}: {e}")
else:
print(f"---\nValidation succeeded for {obj}")
❧ python nullable.py
---
Validation succeeded for {'some_date': None}
---
Validation failed for {'some_date': 'adiofns'}: 'adiofns' is not a 'date'
Failed validating 'format' in schema['properties']['some_date']:
{'type': ['string', 'null'], 'format': 'date'}
On instance['some_date']:
'adiofns'
---
Validation succeeded for {'some_date': '2023-10-01'}