python-jsonschema/jsonschema

error object properties "schema" and "relative_schema_path" seem to be inconsistent

Open

#191 ouverte le 6 janv. 2015

Voir sur GitHub
 (5 commentaires) (0 réactions) (0 assignés)Python (576 forks)batch import
BugError ReportingHelp Wanted

Métriques du dépôt

Stars
 (4 349 stars)
Métriques de merge PR
 (Merge moyen 2j 23h) (6 PRs mergées en 30 j)

Description

I need to parse a jsonschema.exceptions.ValidationError object to help produce a more useful error message to my customers, but I am not sure that the fields of the ValidationError object are correct.

Test case: https://gist.github.com/jason-s/6d2b3418f4edb7fc8064

Raw object (in yaml format, but jsonschema is representation-agnostic -- thank you, it means I can use it for yaml files):

debug:
  foo:
    bar:
      jiminy: cricket
      mickey: mouse
      44hoho: twinkie

The validator correctly find that 44hoho is not a legal property name; it doesn't match patternProperties and in my schema I have additionalProperties = false.

The problem is that the error object's relative_schema_path and schema seem inconsistent.

My test case prints:

parent         : None
relative_path  : deque(['debug', 'foo', 'bar'])
relative_schema_path: deque(['properties', 'debug', 'properties', 'foo', 'properties', 'bar', 'additionalProperties'])
instance       : {'jiminy': 'cricket', 'mickey': 'mouse', '44hoho': 'twinkie'}
schema_path    : deque(['properties', 'debug', 'properties', 'foo', 'properties', 'bar', 'additionalProperties'])
validator      : additionalProperties
context        : []
path           : deque(['debug', 'foo', 'bar'])
message        : Additional properties are not allowed ('44hoho' was unexpected)
schema         : {'additionalProperties': False, 'type': 'object', 'patternProperties': {'^[^\\d\\W]\\w*$': {'type': 'string'}}}
cause          : None
validator_value: False

Note that the schema attribute is a sub-portion of the schema object, but the relative schema path is from the root schema.

Guide contributeur