JsonSchema验证没有为不同的属性NAME引发错误



这是我的json模式

{
"title":"Sl",
"description":"A user request json",
"type":"object",
"properties":{
"FRETL":{
"id": "#FRETL",
"type": "array",
"items":{
"type": "object",
"properties":{
"instances":{
"description":"ThE Instance(Comma Separated Allowed)",
"type":"string",
"minLength": 1
},
"ID":{
"description":"The ID of the Instance",
"type":"string",
"minLength": 1
},
"Number":{
"description":"Mention The Number associated",
"type":"string"
},
"EndDate":{
"type":"string",
"format": "date",
"pattern": "(((19|20)([2468][048]|[13579][26]|0[48])|2000)[/-]02[/-]29|((19|20)[0-9]{2}[/-](0[469]|11)[/-](0[1-9]|[12][0-9]|30)|(19|20)[0-9]{2}[/-](0[13578]|1[02])[/-](0[1-9]|[12][0-9]|3[01])|(19|20)[0-9]{2}[/-]02[/-](0[1-9]|1[0-9]|2[0-8])))",
"description": "We expect yyyy-MM-dd"
},
"StartDate":{
"type":"string",
"format": "date",
"pattern": "(((19|20)([2468][048]|[13579][26]|0[48])|2000)[/-]02[/-]29|((19|20)[0-9]{2}[/-](0[469]|11)[/-](0[1-9]|[12][0-9]|30)|(19|20)[0-9]{2}[/-](0[13578]|1[02])[/-](0[1-9]|[12][0-9]|3[01])|(19|20)[0-9]{2}[/-]02[/-](0[1-9]|1[0-9]|2[0-8])))",
"description": "We expect yyyy-MM-dd"
},
"Comments":{
"type":"string",
"description":"Justification"
}
},
"if":{
"properties":{
"instances":{
"enum": [
"*"
]
}
}
},
"then":{
"properties":{
"ID":{
"description": "please enter the AssetID",
"minLength": 1
}
}
},
"required":[
"instances",
"ID"
]
},
"ABTRIC":{
"id": "#ABTRIC",
"type": "array",
"items":{
"type": "object",
"properties":{
"instances":{
"description":"ThE Instance(Comma Separated Allowed)",
"type":"string",
"minLength": 1
},
"ID":{
"description":"The ID of the Instance",
"type":"string",
"minLength": 1
},
"Number":{
"description":"Mention The Number associated",
"type":"string"
},
"EndDate":{
"type":"string",
"format": "date",
"pattern": "(((19|20)([2468][048]|[13579][26]|0[48])|2000)[/-]02[/-]29|((19|20)[0-9]{2}[/-](0[469]|11)[/-](0[1-9]|[12][0-9]|30)|(19|20)[0-9]{2}[/-](0[13578]|1[02])[/-](0[1-9]|[12][0-9]|3[01])|(19|20)[0-9]{2}[/-]02[/-](0[1-9]|1[0-9]|2[0-8])))",
"description": "We expect yyyy-MM-dd"
},
"StartDate":{
"type":"string",
"format": "date",
"pattern": "(((19|20)([2468][048]|[13579][26]|0[48])|2000)[/-]02[/-]29|((19|20)[0-9]{2}[/-](0[469]|11)[/-](0[1-9]|[12][0-9]|30)|(19|20)[0-9]{2}[/-](0[13578]|1[02])[/-](0[1-9]|[12][0-9]|3[01])|(19|20)[0-9]{2}[/-]02[/-](0[1-9]|1[0-9]|2[0-8])))",
"description": "We expect yyyy-MM-dd"
},
"Comments":{
"type":"string",
"description":"Justification"
}
},
"if":{
"properties":{
"instances":{
"enum": [
"*"
]
}
}
},
"then":{
"properties":{
"ID":{
"description": "please enter the AssetID",
"minLength": 1
}
}
},
"required":[
"instances",
"ID"
]
}
}

这就是我提供的json。

{
"FRETL":
[
{
"instances": "i-123",
"AssetID": "1231",
"Number": "12312",
"StartDate": "2021/12/12", 
"EndDate": "2021/12/12", 
"Justification": "Testing Example"
}
]

}

如果我处理这个问题并运行python验证器,它将正常工作,正如预期的那样,当我将FRETL的名称更改为ABTRIC时,JSON表示它仍然有效,并且它根据我在模式中提到的任何规则运行。但是,如果我在JSON输入中将属性名称更改为上面提到的2以外的其他名称(FRETL和ABTRIC(,它仍然会将其标记为有效。如果JSON输入不包含ABTRIC或FRETL,我想确保它失败。

配置了它。必须使用一个

"oneOf": [
{ "required": ["FRETL"] },
{ "required": ["ABTRIC"] },
{ "required": ["ABCD"] }
]

最新更新