0

I have very basic schema that behaves somehow strange.

{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": 
{
    "$out": 
    {
        "type": "array",
        "minItems": 1,
        "items": {
            "oneOf": [
                { "type": "string" },
                { "$ref": "#/definitions/alias" }
            ]
        }
    }
},
"definitions": 
{
    "alias": 
    {
        "properties": 
        {
            "$source": { "type": "string" },
            "$alias": { "type": "string" }
        },
        "required": [ "$source", "$alias" ],
        "additionalProperties": false
    }
}

}

If I use the following JSON to test:

{
    "$out": [
        "12w",
        { "$source": "WH.Code", "$alias": "WarehouseCode"}
    ] 
}

It fails (sample) saying that string element in array is valid agains more that one schema. If I change reference to 'alias' with say just { "type": "string" } it works as expected. What am I doing wrong?

Thanks in advance.

1 Answer 1

1

All of the keywords you use (properties, required, additionalProperties) only apply if the value is an object. Because there nothing requiring that the value be an object, anything that is not an object will pass. The object keywords are only taken into account if it is an object.

There are a number of ways you can make the schema work, but the most straight forward is to add "type": "object" to your alias schema.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.