python-jsonschema/jsonschema

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

Open

#191 创建于 2015年1月6日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)Python (4,349 star) (576 fork)batch import
BugError ReportingHelp Wanted

描述

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.

贡献者指南

error object properties "schema" and "relative_schema_path" seem to be inconsistent · python-jsonschema/jsonschema#191 | Good First Issue