JSON模式;开关";不起作用
我试图使用库使用JSON模式v5的JSON模式;开关";不起作用,json,jsonschema,ajv,Json,Jsonschema,Ajv,我试图使用库使用JSON模式v5的开关属性 我有以下模式,但它不工作 { "type": "array", "id": "http://localhost/drinks.json", "items": { "type": "object", "properties": { "items": { "type": "array", "items": { "switch": [ {
开关属性
我有以下模式,但它不工作
{
"type": "array",
"id": "http://localhost/drinks.json",
"items": {
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"switch": [
{
"if": {
"properties": {
"type": {
"enum": ["coffee", "tea"]
}
}
},
"then": {
"$ref": "http://localhost/caffeinated.json"
}
},
{
"then": {
"$ref": "http://localhost/decaf.json"
}
}
]
}
}
}
}
}
需要说明的是,$ref
s在没有switch语句的情况下工作正常。例如,这将得到正确验证:
{
"type": "array",
"id": "http://localhost/drinks.json",
"items": {
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"oneOf": [
{
"$ref": "http://localhost/caffeinated.json"
},
{
"$ref": "http://localhost/decaf.json"
}
]
}
}
}
}
}
但是第一个模式不起作用,我说的“不起作用”是指它甚至不会触发valid/invalid。我做错什么了吗