python-jsonschema / jsonschema

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

Validate formats in `check_schema` #1278

Closed alliefitter closed 3 weeks ago

alliefitter commented 3 weeks ago

I'm wondering if there's a way to validate formats when using check_schema. It seems to allow invalid format names. The below example passes validation, even though datetime should be date-time. I noticed the concrete implementation of check_schema has a format_checker argument (even though the FormatChecker protocol does not have this argument). Setting the format checker doesn't validate format names either. Is there anyway to get check_schema to fail for invalid formats?

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "foo": {"type": "string", "minLength": 2},
    "bar": {"type": "number", "minimum": 10},
    "baz": {"type": "string", "format": "datetime"}
  }
}