假设我有以下 JSON 架构
{
"name":"Product",
"type":"object",
"properties":{
"id":{
"type":"number",
"required":true
},
"name":{
"description":"Name of the product",
"required":true
},
"price":{
"required":true,
"type": "number",
"minimum":0,
"required":true
},
"tags":{
"type":"array",
"items":{
"type":"any"
}
}
}
}
但是,我希望标签不是一个数组,而是根模式的一部分。所以你可以指定任何属性,但我特别注意“id”、“name”和“price” 以下哪个是正确的做法,哪些是完全错误的?
{
"name":"Product",
"type":"object",
"properties":{
"id":{
"type":"number",
"required":true
},
"name":{
"description":"Name of the product",
"required":true
},
"price":{
"required":true,
"type": "number",
"minimum":0,
"required":true
}
},
"additionalProperties": {
"type":"any"
}
}
{
"name":"Product",
"type":"object",
"properties":{
"id":{
"type":"number",
"required":true
},
"name":{
"description":"Name of the product",
"required":true
},
"price":{
"required":true,
"type": "number",
"minimum":0,
"required":true
}
},
"extends": {
"type":"any"
}
}
{
"name":"Product",
"type":["object","any"],
"properties":{
"id":{
"type":"number",
"required":true
},
"name":{
"description":"Name of the product",
"required":true
},
"price":{
"required":true,
"type": "number",
"minimum":0,
"required":true
}
}
}
我可以想出更多(例如“任何”和“对象”的反转角色),但它们都是这三个示例的派生。