How do you reference other property values in JSON schema?

末鹿安然 提交于 2019-12-06 05:37:07

问题


I have a JSON schema with 2 properties, minimumTolerance and maximumTolerance. I need to make sure that the value of maximumTolerance is not smaller than minimumTolerance & vice versa. Is this possible in JSON schema?

Here is an example of what I'd like to be able to do:

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "title": "MinMax",
  "description": "Minum & Maximum",
  "type": "object",
  "properties": {
    "minimumTolerance":{
      "type": "number"
      "maximum":{
        "$ref":"maximumTolerance"
      }
    }
    "maximumTolerance":{
      "type": "number"
      "minumum": {
        "$ref":"minimumTolerance"
      }
    }
}

回答1:


As of Draft-7 of the specification there is no way to do this with JSON Schema.




回答2:


Yes, but it may not be the dynamic answer you are looking for...put in the values of min and max for the range expected:

            "MinimumTolerance": {
                "type": "number",
                "minimum": 0,
                "maximum": 6000,
            },
            "MaximumTolerance": {
                "type": "number",
                "minimum": 6001,
            },


来源:https://stackoverflow.com/questions/49997246/how-do-you-reference-other-property-values-in-json-schema

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!