Draft: slapconfiguration: Fix jsonschema design bugs
Rewrite jsonschema validation to correctly collect defaults only from valid validation paths: when a wider sub-schema is not validated by a wider sub-instance, all of the sub(sub)schemas that were validated by sub(sub)instances are to be discarded from consideration for defaults collection. An example of this is provided in the tests.
Also, defaults are now recursively validated, which allows objects to
set e.g. {}
as the default, and still collect the defaults of defined
by each property of that object, as in:
{
"type": "object",
"properties": {
"point": {
"type": "object",
"default": {},
"properties": {
"x": {
"type": "integer",
"default": 0
},
"y": {
"type": "integer",
"default": 0
}
}
}
}
}
Passing the instance {}
should result, after default application, in
{"point": {"x": 0, "y": 0}}
, not in {"point": {}}
. This is important
also because otherwise the behavior is inconsistent between applying
defaults and setting the same value directly: given this schema, the
input {}
and the input {"point": {}}
should produce the same output,
namely {"point": {"x": 0, "y": 0}}
.
Also support collecting defaults specified indirectly via a $ref
, as
well as unstringifying properties that specify their type by a $ref
,
or even a succession of $ref
. This serves to support e.g.:
{
"type": "object",
"$defs": {
"coordinate": {
"type": "integer",
"default": 0
}
}
"properties": {
"point": {
"type": "object",
"default": {},
"properties": {
"x": { "$ref": "#/$defs/coordinate" },
"y": { "$ref": "#/$defs/coordinate" }
}
}
}
}