References to anchors misinterpreted, leading to validation errors
Per my reading of the anchors spec the below should pass validation, and [https://www.jsonschemavalidator.net/s/tOTgHWLN](other validators seem to agree).
The intent is "the value of a property should be (something), or an array of (something)s".
Schema:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"PROPERTY": {
"anyOf": [
{
"$anchor": "AAA",
"type": "string"
},
{
"type": "array",
"items": { "$ref": "#AAA" }
}
]
}
}
}
File:
{ "PROPERTY": [ "value" ] }
yajsv reports:
$ ~/go/bin/yajsv -s fail.schema.json fail.json
fail.json: fail: PROPERTY: Must validate at least one schema (anyOf)
fail.json: fail: PROPERTY.0: Invalid type. Expected: object, given: string
1 of 1 failed validation
fail.json: fail: PROPERTY: Must validate at least one schema (anyOf)
fail.json: fail: PROPERTY.0: Invalid type. Expected: object, given: string
$ ~/go/bin/yajsv -v
v1.4.0-dev
I haven't been following the developments of JSON Schema lately. Looking at the release notes, it appears $anchors were added in the 2019-09 draft. Unfortunately, that's one version newer than what's supported by xeipuuv/gojsonschema which is what yajsv depends on.
I found an open issue (https://github.com/xeipuuv/gojsonschema/issues/289) about adding support for 2019-09. That references some alternative libraries that could be options to use here. I'll have to dig into that when I have some time.
At a minimum, yajsv could check the value of the $schema key then warn and/or error if it's not supported. Depends on if 2019-09 is at least partially backward compatible with earlier versions.