Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error when unevaluatedProperties is not satisfied #936

Closed
spagh-eddie opened this issue Apr 21, 2022 · 3 comments
Closed

Misleading error when unevaluatedProperties is not satisfied #936

spagh-eddie opened this issue Apr 21, 2022 · 3 comments

Comments

@spagh-eddie
Copy link

spagh-eddie commented Apr 21, 2022

Hello, I was mislead by some errors relating to the use of unevaluatedProperties. Here is an MRE of my issue.

Is it reasonable to expect 3.14 is not of type 'integer' instead of Unevaluated properties are not allowed ('eggs' was unexpected) on the last line?

contents of eggs.json:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "eggs.json",
    "type": "object",
    "properties": {"eggs": {"type": "integer"}},
    "unevaluatedProperties": false,
    "required": ["eggs"]
}
import json, jsonschema

with open("eggs.json", "rb") as f:
    # eczema?
    eggschema = json.load(f)

jsonschema.validate({"eggs": 1}, eggschema)  # OK

# get Unevaluated properties are not allowed ('eggs' was unexpected),
# but expected 3.14 is not of type 'integer',
# which is the error if remove unevaluatedProperties
jsonschema.validate({"eggs": 3.14}, eggschema)
@robherring
Copy link
Contributor

validate() picks one error to return and it's not always the best one. You could probably change that to prefer other errors. Or use iter_errors() instead.

I think that including properties that fall validation as unevaluated is strange, but that seems to be intended as multiple implementations behave that way.

@Julian
Copy link
Member

Julian commented Apr 21, 2022

Indeed, (thanks @robherring). You may also be interested in #728.

@spagh-eddie
Copy link
Author

Thank you both for your suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants