Я использую jsonSchema для проверки того, что массив имеет один из двух типов элементов.
При использовании этой схемы
{
"type": "array",
"items": {
"type": "object",
"anyOff": [{
"required": ["image", "link"],
"additionalProperties": false,
"properties": {
"image": {
"type": "string",
"format": "url"
},
"link": {
"type": "string",
"format": "url"
}
}
},
{
"required": ["component", "link"],
"additionalProperties": false,
"properties": {
"component": {
"type": "string",
"pattern": "createYourOwn"
},
"link": {
"type": "string"
}
}
}
]
},
"maxItems": 4
}
и прохождение
{
"image": "something "
}
Я должен получить неудачную проверку, но она проходит,
То же самое с
{
"component": "invalid pattern"
}
По сути, все, что я ввожу, пройдет