Q: How to specify conditions to be met for this schema?

I'm having this simple schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "A": {
      "type": "number"
    },
    "B": {
      "type": "number"
    },
    "C": {
      "type": "number"
    }
  }
}

Now I would like to enforce these conditions on that schema:

  • None of the properties A, B or C is mandatory
  • If A is specified, then at least B or C must be specified
  • If B or C is specified, there must be A specified.
  • B and C must not be specified together

How can I achieve this? I tried a lot with dependencies and allOf/oneOf/anyOf to no avail so far.

TIA



Read more here: https://stackoverflow.com/questions/68473313/q-how-to-specify-conditions-to-be-met-for-this-schema

Content Attribution

This content was originally published by decades at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: