With the second case (using "anyOf") - the default value from all matching
schemas is used. In your example, both schemas would apply, so the
instance has multiple defaults.
So the essence of the problem is the same as using "allOf" (the equivalent
of "extends" in v3):
{
"default": 1,
"allOf": [
{"default": 2},
{"default": 3}
]
}
The issue here is this: If we explicitly defined *which* default should be
used when there's more than one, we would need to define some kind of
ordering on the applied schemas. That's a can of worms I don't want to
open.
So on balance, I would rather that we left the behaviour of "default"
undefined in this case. Perhaps some wording clarifying this in the
specification, such as:
Since multiple schemas can describe an instance, instances may have
multiple conflicting default values. Which default value (if any) should
be used in this case is not defined.
The specification does not explicitly state what agents can or cannot do
with the default value. Given that, I don't think that we particularly
need to nail down what happens when there are multiple defaults.
On Thursday, 18 October 2012 15:50:50 UTC+1, Lionel Villad wrote:
> The specifications (v3 and v4) are quite terse on describing the semantic
> of 'default'. In particular they don't address the following issues:
> - The spec v4 says "This keyword can be used to substitute a default value
> for the production of a user interface.". First, it seems quite
> restrictive. Second, does that imply the input JSON is augmented with
> default values by the validator (similar to what XML schema validators do)?
> - There are many cases where the use of default produces unpredictable
> output. For instance (using v3 syntax):
> { "type": [ { "default": { "a":"a" } }, { "default": { "b":"b" } } ] }
> Which of the 2 default values should be taken?
> It seems to me 'default' is really underspecified and does not address
> edge cases.