johnnoone / json-spec

Implements some tools for JSON
BSD 3-Clause "New" or "Revised" License
38 stars 21 forks source link

type error when using oneOf #4

Closed misja closed 9 years ago

misja commented 9 years ago

I have the following schema:

schema = {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "props": {
            "type": "array",
            "items": {
                "oneOf": [
                    {"type": "string"},
                    {"type": "number"}
                ]
            }
        }
    }
}

Validating the following documents raises a ValidationError('Wrong type', 'hello') error:

doc = {
    "props": ["hello"]
}

This is due to validate_type marking the value "hello" as not a type number during the recursion, but am not able to trace why this error is bubbling up since validate_one_of already validated the condition as true. Any ideas?

misja commented 9 years ago

I just noticed the fix, quite obvious, but I missed it! Thanks :) One other thing that's not too obvious for me at the moment is how to construct a validator by using namespaced schemas I have available via a FilesystemProvider (and also to have these globally available via a Registry). Not sure if this is the best place to ask but if you could provide an example that would be great. Edit: last question sorted.