johnnoone / json-spec

Implements some tools for JSON

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

type error when using oneOf

misja opened this issue · comments

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?

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.