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

validate fails to identify incorrect uuid strings #1199

Closed peristeri closed 9 months ago

peristeri commented 9 months ago

When using jsonschema==4.19.2, I want to validate uuid string in json instance but returns a valid results for invalid instances

Here's a minimal example:

from jsonschema import validate
schema = {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "string", "format": "uuid"}
validate("", schema)
validate("invalid", schema)

I expect the validation of the invalid json instances to raise ValidationError

Julian commented 9 months ago

See the FAQ, you haven't enabled format validation.

peristeri commented 9 months ago

Sorry for the false alarm, but I just saw at the end of the documentation to include format_checker=Draft202012Validator.FORMAT_CHECKER). I wandering what is the motivation to have the format checker as an opt-in feature to validation?

Julian commented 9 months ago

That's the required behavior by the JSON Schema specification essentially. The FAQ goes into more detail.