json-schema-validator icon indicating copy to clipboard operation
json-schema-validator copied to clipboard

why schema keyword value can not be a path?

Open DaiKiQi opened this issue 6 years ago • 6 comments

I have recently used json schema to help validate json data. but i found that its hard to validate cascade relation. for example:

          "ageRange": {
            "minAge": 20,
            "maxAge": 30
          }

I want to limit 18<minAge<maxAge<50. its hard to limit minAge<maxAge. Because keyword minimum's value must be number. why schema keyword value can not be a path?like this:

"maxAge": {
              "minimum": "$.ageRange.minAge",
              "exclusiveMaximum": 50
            }

do you have any idea to implement this?

DaiKiQi avatar Dec 14 '19 12:12 DaiKiQi

@DaiKiQi I think your case is a good one; however, the JSON schema specification doesn't support it yet. Would you be able to open the same issue to ask if they can adjust the specification?

https://github.com/json-schema-org/json-schema-spec

stevehu avatar Dec 14 '19 14:12 stevehu

I have implemented in keyword minimum maximum,can you give some review?

DaiKiQi avatar Dec 14 '19 14:12 DaiKiQi

Yes. Please submit a PR. Meanwhile, we'd better open an issue in the json-schema-spec so that it can be a standard. Thanks.

stevehu avatar Dec 14 '19 14:12 stevehu

It's being discussed here with $data and relative json pointer. Not made it to the spec yet though.

https://github.com/json-schema-org/json-schema-spec/issues/51

SridharSubramaniam avatar Dec 19 '19 20:12 SridharSubramaniam

@SridharSubramaniam Thanks a lot for the spec link. It is quite a read :) I think it is not hard to implement it and I am looking forward to merging it into the spec. @DaiKiQi If we are doing something, the above discussion might guide us in the right direction.

stevehu avatar Dec 20 '19 03:12 stevehu

Given this has been discussed intensively, I am closing this issue. Thank you, everyone, for the inputs.

stevehu avatar Mar 20 '20 10:03 stevehu