Closed xiaoxiangmoe closed 8 months ago
That is technically a valid schema. In JSON Schema, unknown keywords are ignored. This allows for extension, but can also result in confusing cases like this one. So, what's happening is that Bar
is being interpreted as an unknown schema keyword and everything under Bar
is getting ignored. Given that Bar
is ignored, it might seem strange that you can successfully reference it. There's another quirk of JSON Schema that anything you reference will be interpreted as a schema. So even though from $defs
s perspective, Bar
(and its value) is ignored, it's still considered a schema because it was referenced using $ref
.
So, as odd as it seems, this is actually the correct behavior. However, in the next version of JSON Schema, unknown keywords will no longer be allowed and ignored and an issue like this will be considered an error.
https://json-schema.hyperjump.io/
schema
instance
All check passed
But see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00
But the object
{ "Bar": { "type": "boolean" } }
not seems to be a valid JSON Schema.