clkhash icon indicating copy to clipboard operation
clkhash copied to clipboard

Improve handling of schema defaults

Open nbgl opened this issue 6 years ago • 0 comments

Currently, the defaults are embedded in the code. This is in addition to them being listed in the master schema. This can lead to inconsistencies if the defaults are changed in one place but not the other. It can also be the cause of bugs. It would be nice to have one place for storing all the defaults, or at least a way to ensure that all the defaults match.

One idea is to have JsonSchema populate objects' defaults from the schema. This is something it doesn't do by default, but is capable of doing with minor hacking. See their documentation. They say, … none of the other validators modify the instance either. … It’s perfectly valid (and perhaps even useful) to have a default that is not valid under the schema it lives in! So an instance modified by the default would pass validation the first time, but fail the second! Still, this would be more elegant than the current solution.

Another solution may be to write a test that reads both sets of defaults and compares them. It would fail if anything is changed in only one place. However, it would require maintenance if ever we add any more defaults.

Aha! Link: https://csiro.aha.io/features/ANONLINK-45

nbgl avatar Mar 20 '18 00:03 nbgl