Closed meghprkh closed 1 week ago
I think the problem is you are using both $id
in the wrong way. $id
is a way to refer to a schema or subschema but I've not seen it used in $def
s before since they already have a syntax to refer to them. The $id
is most commonly used to define the base for all your $refs
. So basically your example works if you just remove these extra $id
props.
{
"$ref": "#/$defs/KVMap",
"$defs": {
"JSONValue": {
},
"KVMap": {
"type": "object",
"patternProperties": {
"^(.*)$": {
"$ref": "#/$defs/JSONValue"
}
}
}
}
}
What version of Ajv are you using? Does the issue happen if you use the latest version? Yes
Ajv options object
CLI invocation
ajv validate -s test.schema.json -d test.json
JSON Schema
This schema would work complain that:
I am unsure if refs should use IDs instead of JSON Pointers everywhere, but IDs do seem to work.
The inconsistency between VSCode and ajv's validator wrt IDs is that ajv accepts ID as
JSONValue
instead of#JSONValue
too, whereas VSCode does not. I cant find any mention of this on JSONSchema and think it might be VSCode which is wrong here.Sample data
What results did you expect?
This should be a valid case in JSON schema, because dictionaries are not sorted so it would be impossible to refer to a non-id anchor based def.
Are you going to resolve the issue? I dont know