I have a schema where I have an array (inside the transmit object) which could possibly have one of two options (A or B).
I have attached both the schema and sample data (that is actually getting validated, when it should have thrown an error).
under transmitDataDef->items, I have tried "anyOf", "oneOf", "type" and they all yield no-errors even though the data does not match (data contains optionC that is not defined anywhere)
I am using jsonschema python library. I have also tried this schema + data in https://www.jsonschemavalidator.net/ with same results.
Schema:
{
"definitions": {
"optionADef": {
"type": "object",
"properties": {
"pattern": {
"type": "string",
"enum": [
"random",
"fixed"
]
},
"startbyte": {
"type": "number"
}
},
"required": [
"startbyte"
],
"additionalProperties": false
},
"optionBSubItemDef": {
"type": "object",
"properties": {
"value": {
"type": "number",
"minimum": 0
}
}
},
"optionBSettingsDef": {
"type": "object",
"properties": {
"sequence": {
"type": "number",
"minimum": 0
}
}
},
"optionBDataDef": {
"type": "object",
"properties": {
"subitem": {
"ref": "#/definitions/optionBSubItemDef"
}
}
},
"optionBDef": {
"type": "object",
"properties": {
"_data": {
"ref": "#/definitions/optionBDataDef"
},
"_settings": {
"$ref": "#/definitions/optionBSettingsDef"
}
},
"required": [
"_data"
],
"additionalProperties": false
},
"transmitDataDef": {
"type": "array",
"minItems": 1,
"maxItems": 1,
"items": {
"anyOf": [
{
"type": "object",
"properties": {
"optionA": {
"ref": "#/definitions/optionADef"
}
},
"additionalProperties": false
},
{
"type": "object",
"properties": {
"optionB": {
"ref": "#/definitions/optionBDef"
}
},
"additionalProperties": false
}
]
}
},
"transmitSettingsDef": {
"type": "object",
"properties": {
"length": {
"type": "number",
"minimum": 0,
"maximim": 8
}
}
},
"transmitDef": {
"type": "object",
"properties": {
"_data": {
"ref": "#/definitions/transmitDataDef"
},
"_settings": {
"$ref": "#/definitions/transmitSettingsDef"
}
},
"required": [
"_data"
],
"additionalProperties": false
},
"bundleDef": {
"type": "object",
"properties": {
"transmit": {
"$ref": "#/definitions/transmitDef"
}
},
"oneOf": [
{
"required": [
"transmit"
]
}
],
"additionalProperties": false
}
},
"type": "object",
"properties": {
"name": {
"type": "string"
},
"bundle": {
"$ref": "#/definitions/bundleDef"
}
},
"required": [
"name",
"bundle"
]
}
Sample data:
{
"name": "test1",
"bundle": {
"transmit": {
"_settings": {
"length": 0
},
"_data": [
{
"optionC": {
"_settings": {
"sequence": 150
},
"data1": [
{
"subitem": {
"value": 100
}
}
]
}
}
]
}
}
}
I expect the validation to catch "optionC" and flag it as an error. If I had optionB instead of optionC, i expect it to flag "data1" as an invalid item.