Skip to content

Error reporting in case of multi option type #50

@P-Product

Description

@P-Product

Hi Julian,

this time I would like to ask something. Consider the following setup

my_schema = {
    "type": [
        "string",
        {
            "type": "array",
            "items": { "type": "number" },
            "additionalItems": False
        }
    ]
}

my_json = [1, "test"]


Draft3Validator.check_schema(my_schema)
print 'schema is valid'

v = Draft3Validator(my_schema)

valid = True
for error in sorted(v.iter_errors(my_json), key=str):
    valid = False
    print error

if valid: 
    print 'json is valid'

The output I get for this is

schema is valid
[1, 'test'] is not of type 'string', {'items': {'type': 'number'}, 'additionalItems': False, 'type': 'array'}

However it seems to me that the error should read

'test' is not of type 'number'

Do you think it is possible that in such case of multiple options an error of the deepest match should be presented?
Or, as an alternative, there may be a set of errors like

[1, 'test'] is not of type 'string'
'test' is not of type 'number'

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementSome new desired functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions