Minimum value based off another value - JSON schema

53 Views Asked by At

I'm wanting to set a minimum amount on one field based off another field.

For example if I have a quoteAmountLower and quoteAmountUpper - I want quoteAmountUpper to be greater than quoteAmountLower.

If lower is 50 then upper has to be more than 50.

properties: {
  quotedAmountLower: {
    type: 'integer',
    minimum: 0
  },
  quotedAmountUpper: {
    type: 'integer',
    // more than quotedAmountLower
    minimum: 0
  }
}

Cheers

I've tried using a reference or $id on the quotedAmountLower

1

There are 1 best solutions below

0
jareon On BEST ANSWER

There is no keyword in the standard JSON Schema specification that can reference a value in an instance.

There are proposals, for instance https://docs.json-everything.net/schema/vocabs/data-2023/ (related: https://github.com/json-schema-org/json-schema-spec/issues/51) so you will probably either need to customize the JSON Schema library you are using or check if it supports something similar.