Description
If a schema specifies a string in the format of date-time
, the CLI tool will allow any string value to pass validation. The tool should instead declare the value as not a date-time and the instance should fail the validation.
The date-time
format is defined as a format in JSONSchema 2020-12 Section 7.3.1.
Validation occurs correctly for the date
format but not date-time
. For example, the following schema and instance files:
schema.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.org/test-date.json",
"title": "Check Date Validation",
"description": "A simple schema designed to check datetime and date validation in the check-jsonschema CLI application",
"type": "object",
"properties": {
"thisShouldBeADate": {
"type": "string",
"format": "date",
"title": "This Should Be A Date",
"description": "This field should contain a date but not a datetime"
},
"thisShouldBeADatetime": {
"type": "string",
"format": "date-time",
"title": "This Should Be A Datetime",
"description": "This field should contain a datetime but dates should not validate."
}
},
"required": [ "thisShouldBeADate","thisShouldBeADatetime" ]
}
instance.json:
{
"thisShouldBeADate": "not a date",
"thisShouldBeADatetime": "not a datetime"
}
with the following command:
check-jsonschema --schemafile schema.json instance.json
returns the following results:
Schema validation errors were encountered.
example.json::$.thisShouldBeADate: 'not a date' is not a 'date'
If I change the value of thisShouldBeADate
to a valid date, but leave the value of thisShouldBeADatetime
as a random string, the entire file passes validation.
System configuration (if it helps debugging):
- OS: Devuan 5 (basically Debian 12)
- Python version: 3.11.2
- Installation method: pipx (v1.1.0)
EDIT: forgot to mention, https://www.jsonschemavalidator.net/ produces the expected behaviour when given the above schema and instance, hence my raising the issue here.
Thank you for your time and work on this otherwise incredible tool.