Skip to content

required, additionalProperties, propertyNames, dependentRequired and any other validators that reference property *names* need a way to indicate the erroring names in ValidationErrorsΒ #119

Open
@martinpengellyphillips

Description

@martinpengellyphillips

Trying to figure out if there is a way to retrieve the name of a missing required property from an error (without hacking it out of error.message).

For example:

from jsonschema import Draft4Validator as Validator

schema = {
    'type': 'object',
    'properties': {
        'a': {
            'type': 'string'
        },
        'b': {
            'type': 'string',
            'pattern': '^hello$'
        }
    },
    'required': ['a', 'b']
}

errors = Validator(schema).iter_errors({'b': 'world'})
for error in errors:
    print error.path, error.schema_path, error.message

# deque([]) deque(['required']) 'a' is a required property
# deque(['b']) deque(['properties', 'b', 'pattern']) 'world' does not match '^hello$'

In error.path and error.schema_path there is no mention of 'a'. Is there a way to determine that the property missing was 'a' without using 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