JSON模式:日期大于另一个 [英] JSON schema: date greater than an other

查看:88
本文介绍了JSON模式:日期大于另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆