taplo
taplo copied to clipboard
Discrepancy in validation with JSON Schema draft 2020-12
With this schema, which defines an object with a property test
that contains an array of objects that can have certain properties, I am having issues where Taplo should be invalidating a test case but it isn't. This is probably due to something with the new property introduced in this draft, unevaluatedProperties
(see this discussion about it).
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"test": {
"type": "array",
"items": {
"$comment": "This schema is closed, and any property used which aren't defined are invalid/not allowed.",
"type": "object",
"properties": {
"foo": { "type": "string" }
},
"allOf": [{ "$ref": "#/$defs/bazExtension" }],
"unevaluatedProperties": false
}
}
},
"$defs": {
"bazExtension": {
"$comment": "This schema can be used as an extension",
"type": "object",
"properties": {
"baz": { "type": "boolean" }
}
}
}
}
These tests should be valid, with any combination of foo
and baz
together or separate:
{
"test": [
{
"foo": "foo",
"baz": true
}
]
}
{
"test": [
{
"foo": "foo"
}
]
}
{
"test": [
{
"baz": true
}
]
}
[[test]]
foo = "foo"
baz = true
[[test]]
foo = "foo"
[[test]]
baz = true
And these should be invalid, with an additional property not in the definition:
{
"test": [
{
"foo": "foo",
"baz": true,
"otherProperty": true
}
]
}
[[test]]
foo = "foo"
baz = true
otherProperty = true
You can test these on https://json-everything.net/json-schema/ for JSON and with taplo
obviously for TOML. My issue is that Taplo isn't invalidating the last example with the additional property otherProperty
when it should be.