Skip to content

Friendlier unevaluatedProperties errors #1074

@ikonst

Description

@ikonst

It would be helpful to bifurcate the "Unevaluated properties are not allowed" error messages over whether the property was expected — defined but failing validation, e.g.

  • "Unevaluated properties are not allowed ('foo', 'bar' were not valid under the given schema)"
  • "Unevaluated properties are not allowed ('baz' was unexpected)"

A single unevaluatedProperties could yield 0, 1 or 2 errors.

I personally found that aspect of unevaluatedProperties to be confusing when I first stumbled on it ("foo is not a typo, so why is it reported?"). Later I understood it, but my learning path could be shorter and astonishment smaller if we somehow structured the message to suggest this possibility.

--

One way to implement this would be to have find_evaluated_property_keys_by_schema collect tuples of (property_name, is_valid), and then process them within unevaluatedProperties:

-evaluated_keys = find_evaluated_property_keys_by_schema(...)
+res = find_evaluated_property_keys_by_schema(...)
+evaluated_keys = {key for key, is_valid in res if is_valid}
+expected_keys = {key for key, _ in res if key in instance}

Then unevaluated_keys could be split into:

unevaluated_expected_keys = [k for k in unevaluated_keys if k in expected_keys]
unevaluated_unexpected_keys = [k for k in unevaluated_keys if k not in expected_keys]

and each list used to emit the relevant error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementSome new desired functionalityError ReportingIssues related to clearer or more robust validation error reporting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions