JSON模式:日期大于另一个 [英] JSON schema: date greater than an other
问题描述
我有一个像这样的json模式:
I've a json schema like this:
{
"$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
?
How can I say in my schema that the dateFin
must be greater than the dateDebut
?
推荐答案
您不能在JSON-Schema级别上做到这一点.您必须分别为Operation
对象进行验证.通常,JSON-Schema仅提供一种格式正确"的健全性检查:关于属性是数字,日期还是与正则表达式匹配的字符串;或关于具有某些嵌套属性结构的对象.更高级的业务规则(例如您示例中的规则)应在其他位置进行控制.
You can't do that on the JSON-Schema level. You'd have to validate that separately for your Operation
objects. In general, JSON-Schema only provides a kind of "well-formed-ness" sanity checks: about a property being a number, date, or a string matching a regexp; or about an object having certain nested structure of properties. More advanced business rules like the one from your example should be controlled elsewhere.
这篇关于JSON模式:日期大于另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!