encoding/jsonschema: generation of templates with regular fields and default values
In #3472, we state that to conform to the specification, the jsonschema logic should not treat default values as part of the generated schema. But it would still be useful to be able to make use of those default values.
Straw man feature: we could have the option to generate a "template value" for a given JSON Schema that does define regular fields and default values.
Note that this is not a trivial thing to do, as defaults and regular fields do not
mix nicely with the validator-only nature of matchN, as generated by oneOf, allOf and anyOf.
For example:
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{
"properties": {
"a": {
"type": "string",
"default": "foo"
}
}
},
{
"properties": {
"b": {
"type": "string",
"default": "bar"
}
}
}
]
}
The natural encoding for this might be:
matchN(1, [{
a: string | *"foo"
...
}, {
b: string | *"bar"
...
}])
but that won't fill in defaults at all, because matchN is a pure validator. But I don't think we know how to combine templates and oneOf etc semantics right now.