У меня проблемы с проверками JSON.У меня есть 3 связанных окна выбора на моей странице, и мне нужна проверка, чтобы отразить то, что показывает пользовательский интерфейс.Доступны следующие 3 значения: - Область действия: может быть ScopeNational
, ScopeRegional
или ScopeInternational
- Страна: список стран - Регион: список регионов ("Европа", "Азия" и т. Д.)
В схеме выборки являются объектами с двумя свойствами: «ключ» и «текст», оба являются строками.
Если область действия - «Область действия», то требуются «Страна» и «Регион».Если область действия - «ScopeRegional», то требуется только «Регион».Наконец, если область действия - «ScopeInternational», ни одна из «Страна» или «Регион» не требуется.
Я перепробовал множество настроек с anyOf
, oneOf
и if-then-else
, но я не смог этого добиться. Вотпоследняя схема, которую я попробовал, но безуспешно:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "Linked scope",
"default": null,
"properties": {
"scope": {
"$id": "#/properties/scope",
"title": "Project scope",
"$ref": "#/definitions/Scope"
},
"country": {
"$id": "#/properties/country",
"title": "Country",
"$ref": "#/definitions/Choice"
},
"region": {
"$id": "#/properties/region",
"title": "Region",
"$ref": "#/definitions/Choice"
}
},
"oneOf": [
{
"properties": {
"scope": {
"properties": {
"key": {
"const": "ScopeNational"
}
}
},
"country": {
"required": [
"key",
"text"
]
},
"region": {
"required": [
"key",
"text"
]
}
}
},
{
"properties": {
"scope": {
"properties": {
"key": {
"const": "ScopeRegional"
}
}
},
"region": {
"required": [
"key",
"text"
]
}
}
},
{
"properties": {
"scope": {
"properties": {
"key": {
"const": "ScopeInternational"
}
}
}
}
}
],
"required": [
"scope"
],
"definitions": {
"Choice": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"text": {
"type": "string"
}
},
"required": [
"key",
"text"
]
},
"Scope": {
"type": "object",
"properties": {
"key": {
"type": "string",
"enum": [
"ScopeNational",
"ScopeRegional",
"ScopeInternational"
]
},
"text": {
"type": "string"
}
},
"required": [
"key",
"text"
]
}
}
}
Спасибо!