How do you reference other property values in JSON schema?

前端 未结 3 1194
感情败类
感情败类 2021-01-05 07: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 &a

相关标签:
3条回答
  • 2021-01-05 07:37

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

    0 讨论(0)
  • 2021-01-05 07:44

    If you are using AJV You can do this using $data and relative JSON pointers. Example:

      low: {
        type: 'integer',
        maximum: {
          $data: '1/high',
        },
        exclusiveMaximum: true,
      },
    
      high: {
        type: 'integer',
        minimum: {
          $data: '1/low',
        },
        exclusiveMinimum: true,
      },
    
    0 讨论(0)
  • 2021-01-05 07:47

    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,
                },
    
    0 讨论(0)
提交回复
热议问题