python-jsonschema / jsonschema

An implementation of the JSON Schema specification for Python
https://python-jsonschema.readthedocs.io
MIT License
4.58k stars 578 forks source link

Draft07Valiadator doesn't validate dates #1178

Closed DoubleBoba closed 10 months ago

DoubleBoba commented 10 months ago

Code snippet:

schema = {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "#masterdata/data",
    "type": "object",
    "title": "Data Definition",
    "required": ["d"],
    "properties": {
        "d": {
            "type": "string",
            "format": "date",
            "description": "Occurrence date"
        },
    }
}

data = {'d': ''}
import jsonschema
jsonschema.validate(data, schema)

Expected behavior: Validation should fail because the date isn't in iso8601 format.

Actual behavior: Document successfully validated.

Environment: Python 3.10.13 (main, Aug 24 2023, 22:36:46) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin jsonschema==4.19.1

Julian commented 10 months ago

Hi. This is correct behavior. See https://python-jsonschema.readthedocs.io/en/stable/faq/#my-schema-specifies-format-validation-why-do-invalid-instances-seem-valid