Reputation: 3284
I have a draft7
schema.
Two required properties are totalSizeOfFarm
and totalAreaGrass
, both are type number
and have exclusiveMinimum
of 0.
I want the maximum of totalAreaGrass
not to exceed the value of totalSizeOfFarm
.
Can this be done?
I've been looking at if..then
but don't understand how to get the value of totalSizeOfFarm
.
Please advice.
Upvotes: 1
Views: 256
Reputation: 12295
You cannot use the specific value of a number from a JSON instance in your schema. What you describe is validation business logic, which is beyond the remit of JSON Schema.
If you had specific values, like those you would put in an enum, you can do things based on specific values up front, but not dynamically from the JSON instance you are validating.
That said, there's nothing to stop you adding your own key word, and using the interface for performing your own function based on that keyword. Not all libraries support such things (ajv does), AND this will make your JSON Schema no longer useable by others, which may be a consideration.
Upvotes: 1