As a JSON Schema user, I want to require certain properties based on the numeric value of another property.
An example case here is that I have a system where user can purchase a bus ticket (with value of 1) or a train ticket (with value of 2). If a train ticket is purchased, a seat must be included as tickets are tied to a specific seat but with bus, such requirement does not exist.
Bus ticket data
Train ticket data
To validate this, our schema looks something like this:
Here we define our two properties, ticket_type
and seat
. In oneOf
restrictions, we require one of the two rules to match: either ticket_type
equals 1 or ticket_type
equals 2 AND seat
is required.
If we want to instead do ranges (for example, require seat for any ticket_type
that is larger than zero), we do: