我有一个像这样的json架构:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Operation",
"description": "The schema of an operation",
"type": "object",
"properties": {
"id":{
"description": "Unique identifier of the service",
"type": "string"
},
"description":{
"type": "string"
},
"dateDebut":{
"type": "string",
"format": "date-time"
},
"dateFin":{
"type": "string",
"format": "date-time"
}
}
}
如何在我的架构中说dateFin
必须大于dateDebut
?
答案 0 :(得分:6)
这个库支持它 https://github.com/epoberezkin/ajv#features
var ajv = Ajv({v5:true,allErrors: true})
{
"startDate": {
"format": "date",
"message": "Please Enter correct date format YYYY-MM-DD"
},
"endDate": {
"format": "date",
"message": "Please Enter correct date format YYYY-MM-DD",
"formatMinimum": {
"$data": "1/startDate"
}
}
}
答案 1 :(得分:4)
您无法在JSON-Schema级别上执行此操作。您必须单独为Operation
个对象验证。一般来说,JSON-Schema只提供了一种“良好形式”的#34;完整性检查:关于属性是数字,日期或匹配正则表达式的字符串;或关于具有某些嵌套结构属性的对象。更高级的业务规则应该在其他地方控制,例如你的例子。