我需要根据http://json-schema.org/定义的规范编写JSON。但我正在为所需的/强制的属性验证而奋斗。下面是我编写的JSON模式,其中所有的3个属性都是强制性的,但在我的例子中,应该是强制性的。怎么做呢?
{
    "id": "http://example.com/searchShops-schema#",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "searchShops Service",
    "description": "",
    "type": "object",
    "properties": {     
            "city":{
                "type": "string"                
            },  
            "address":{
                "type": "string"                
            },      
            "zipCode":{
                "type": "integer"
            }                   
    },
    "required": ["city", "address", "zipCode"]
}发布于 2015-06-21 00:22:21
{
  ...
  "anyOf": [
    { "required": ["city"] },
    { "required": ["address"] },
    { "required": ["zipcode"] },
  ]
}如果恰好存在一个属性,则使用"oneOf“
https://stackoverflow.com/questions/28936710
复制相似问题