Description
Currently, additionalItems
and additionalProperties
allow the booleans true
and false
as values, with the following equivalences:
true
is equivalent to {}
false
is equivalent to {"not": {}}
These are helpful because they more clearly indicate the intent of "this can't exist" and "this can exist in any form", particularly when it comes to false
. They are purely syntactical convenience, but they become very convenient when doing more complex schema algebra to work with complicated schema re-use.
We should allow true
and false
anywhere a schema is allowed (although requiring an object schema for the root would be reasonable, if we don't want booleans on their own to be legal schema documents).
This will allow expressing things like "all properties except..." and "only these properties with any value..." very clearly. In particular, false
is much more immediately understandable than {"not": {}}
. Allowing true
in all schema places also means that we can say {"not": true}
== false
.
{
"properties": {
"foo": false,
"bar": false
}
}
{
"properties": {
"foo": true,
"bar": true,
}
"additionalProperties": false
}
It also makes it a bit more clear to build a schema that forbids additional properties based on two sets of properties combined (I've inlined the constituent schemas instead of using $ref which would be more normal):
{
"definitions": {
"firstSet": {
"properties": {
"a": {...},
"b": {...},
"c": {...},
}
},
"lastSet": {
"properties": {
"x": {...},
"y": {...},
"z": {...}
}
}
},
"allOf": [
{"$ref": "#/definitions/firstSet"},
{"$ref": "#/definitions/lastSet"},
]
"properties": {
"a": true,
"b": true,
"c": true,
"x": true,
"y": true,
"z": true
},
"additionalProperties": false
}
This reads a bit more clearly as "allow only these things, which have their real schemas defined in the allOf".
Of course this is just a syntax of convenience, but that's true of the existing true
and false
use as well. It's just as convenient in other places.