We already use callbacks on $ref to track the locations of all operations. We could do this in a more universal way - track the locations of all entities we encounter (using their $defs name), and then we can verify that $refs in the document (not in a json schema, but the openapi part of the doc) are pointing to the right location.
We can do this at runtime, in _resolve_ref, by passing in the name of the entity we expect to be at the other end, and comparing that to our entity index.
We could also do this at initialization time by also tracking the location of all $refs and then resolving the target and comparing against our list of entities. This may not work for $refs to other documents though, as those may not have been loaded yet. This would also incur a startup penalty that may not be worth it.
We already use callbacks on
$ref
to track the locations of all operations. We could do this in a more universal way - track the locations of all entities we encounter (using their$defs
name), and then we can verify that$ref
s in the document (not in a json schema, but the openapi part of the doc) are pointing to the right location.We can do this at runtime, in
_resolve_ref
, by passing in the name of the entity we expect to be at the other end, and comparing that to our entity index.We could also do this at initialization time by also tracking the location of all
$ref
s and then resolving the target and comparing against our list of entities. This may not work for $refs to other documents though, as those may not have been loaded yet. This would also incur a startup penalty that may not be worth it.