Skip to content

The input schema draft version should be used in all validators  #66

Closed
@Stranger6667

Description

@Stranger6667

Hi Zac!

During work on the "recursive references" branch I found a problem.

For example, the input schema is Draft 4 and uses exclusiveMaximum as a boolean value and has keywords that involve subschema validation and are not canonicalised.

The problem is that those subschemas will use Draft 7 (the default from jsonschema) and will be rejected as invalid. For example, the following schema is valid Draft 4 schema:

SCHEMA = {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "not": {
        "allOf": [
            {"exclusiveMinimum": True, "minimum": 0},
            {"exclusiveMaximum": True, "maximum": 10},
        ]
    }
}

And canonicalise call fails:

~/code/hypothesis-jsonschema/src/hypothesis_jsonschema/_canonicalise.py in merged(schemas, resolver)
    922             return FALSEY
    923     assert isinstance(out, dict)
--> 924     jsonschema.validators.validator_for(out).check_schema(out)
    925     return out
    926 

~/.virtualenvs/hypothesis-jsonschema/lib/python3.8/site-packages/jsonschema/validators.py in check_schema(cls, schema)
    292         def check_schema(cls, schema):
    293             for error in cls(cls.META_SCHEMA).iter_errors(schema):
--> 294                 raise exceptions.SchemaError.create_from(error)
    295 
    296         def iter_errors(self, instance, _schema=None):

SchemaError: True is not of type 'number'

Failed validating 'type' in metaschema['properties']['exclusiveMaximum']:
    {'type': 'number'}

On schema['exclusiveMaximum']:
    True

The real-life example is the Open API schema, which I found failing for this reason in my "recursive references" branch.

To me, it seems like we need to pass the schema version to places where those validators are created to use proper validators for the schema's draft. I could try to push a PR with that approach.

What do you think?

Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions