barectf: schemas: use conditionals intead of `oneOf` when possible
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 28 May 2020 18:18:48 +0000 (14:18 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 29 May 2020 19:23:10 +0000 (15:23 -0400)
commitf1ac89a942375a2ea1faba880598dc3fdbe289d2
treedcbcf0ab9bc7d936dd91d63a985d9e41f19794ce
parentc3aed479f08153ab791cf9eeea1eb85385fcc2b6
barectf: schemas: use conditionals intead of `oneOf` when possible

Using `if`/`then`/`else` instead of `oneOf` makes the `jsonschema`
validator create much more readable errors.

For example:

Before:
    Error:
      Configuration: Cannot create configuration from YAML file
        `config.yaml`
      Configuration object:
      `metadata` property:
      `clocks` property:
      `some_clock` property:
      `offset` property:
      `seconds` property: -2 is not valid under any of the given
        schemas: -2 is less than the minimum of 0; -2 is not of type
        'null' (from schema `2/config/config`)

Now:
    Error:
      Configuration: Cannot create configuration from YAML file
        `config.yaml`
      Configuration object:
      `metadata` property:
      `clocks` property:
      `some_clock` property:
      `offset` property:
      `seconds` property: -2 is less than the minimum of 0
        (from schema `2/config/config`)

This is because, with conditionals, we assume that the user intended
something with some valid schema, and add more constraints. The example
above is for an integer having a minimum value of 0, or a null value. As
soon as we know that the value is an integer, then we know its minimum
must be 0; we decide to not care about the fact that the whole value
could also be null (which the old message indicated). In my opinion,
this is a better UX.

The example above is simple. For more complex schemas, the UX gain is
even more obvious.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
barectf/schemas/2/config/config-pre-field-type-expansion.yaml
barectf/schemas/2/config/config.yaml
barectf/schemas/2/config/field-type.yaml
barectf/schemas/2/config/include-prop.yaml
This page took 0.024071 seconds and 4 git commands to generate.