The validation specification does not cover that situation. The validation is context-free, so it is independent of the wider context of the document - you should be able to embed part or all of these documents within a larger document/collection, and still validate by just referencing the appropriate schema.
However, you can express that relationship using links (from the hyper-schema spec). A normal "structural" validator would ignore links, but a "hyper-validator" that verifies links is perfectly possible.
Example schema:
{
"type": "object",
"properties": {
"referenceableItems": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {"type": "string"},
"name": {"type": "string"}
},
"links": [{
"href": "#{id}",
"rel": "self"
}]
}
},
"reference": {
"type": "string",
"links": [{
"href": "#{$}",
"rel": "full"
}]
}
}
}
Example data: - annotated with links defined by the schema
{
"referenceableItems": [
{ // "self" link means this item has fragment URL: #abc
"id": "abc",
"name": "Item A-B-C"
},
{ // "self" link means this item has fragment URL: #def
"id": "def",
"name": "Item D-E-F"
}
],
"reference": "abc" // has "full" link pointing to: #abc
}
So, the relationships between separate parts of the document can be described using links. A hyper-validator could inspect the links in the document, verify that the "self" links do not clash, and verify that the target of the "full" link did in fact exist. It even has the potential to support validation of cross-document links (if you are validating a whole set at once).
That may or may not be what you're looking for - however, I reckon it's what I would do.
Geraint
P.S. - are there any languages you're using in particular? I suspect that "hyper-validators" are not particularly common yet.