properties inside a oneOf operator is not being validated as I want

I have problems validating/understanding the “oneOf” operator.

JSON SCHEMA:

{
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
            "QuerySpecification": {
                "type": "array",
                "minItems": 1,
                "items": {
                    "type": "object",
                    "properties": {
                        "FieldName": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "FieldName"
                    ],
                    "oneOf": [
                        {
                            "properties": {
                                "SimpleQuery": {
                                    "type": "string"
                                }
                            }
                        },
                        {
                            "properties": {
                                "CompositeQuery": {
                                    "type": "string"
                                }
                            },
                            "additionalProperties": false
                        }
                    ]
                }
            }
        }, "required": ["QuerySpecification"]
    }

I would expect either “SimpleQuery” or “CompositeQuery” would be required in the JSON input, but it is validating OK without specifying neither of them.

JSON INPUT:

{
    "QuerySpecification": [{
        "FieldName": "Andreas"
    }]
}


Source: json

Leave a Reply