Skip to content

support for validating entire structure rather than throwing ONLY the first validation error found #515

@radzhome

Description

@radzhome

Would it be possible to add a flag to validate so that all the schema errors are found and included in the error? and in the error object itself, would be excellent to include a list of all the errors so can easily iterate over rather than having to parse the error message.

here for example I have 2 errors in schema

from jsonschema import validate
schema = {
     "type" : "object",
     "properties" : {
         "price" : {"type" : "number"},
         "name" : {"type" : "string"},
     },
 }

try:
    validate({"name" : 3, "price" : '34.99'}, schema)
except Exception as e:
    #import pdb; pdb.set_trace();
    breakpoint();
    raise

but am prompted for only the first one

jsonschema.exceptions.ValidationError: '34.99' is not of type 'number'

Failed validating 'type' in schema['properties']['price']:
    {'type': 'number'}

On instance['price']:
    '34.99'

I do not see this one until the first one is fixed;

Failed validating 'type' in schema['properties']['name']:
    {'type': 'string'}

On instance['name']:
    3```

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvalidNot a bug, PEBKAC, or an unsupported setup

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions