Recursively scan a schema document for a $anchor matching the given name.
Returns the schema object containing the anchor, or undefined.
Per JSON Schema 2020-12 §8.2, $anchor is scoped to the resource
defined by the nearest enclosing $id. A bare DFS would happily
cross resource boundaries and resolve to an anchor declared in an
unrelated sub-resource — that violates the spec and produces wrong
walker input when two sub-schemas use the same anchor name within
their own $id scope.
The walk skips into any sub-tree that introduces a new $id value:
such a sub-tree is a separate resource and its $anchors belong to
that resource, not the caller's. Anchors declared at the same $id
scope (or in nested sub-schemas without their own $id) remain
reachable.
The optional visited set guards against shared object references and
cycles introduced by the OpenAPI bundler's structuredClone-based
inlining of external refs. Without it a recursive document would stack
overflow before reaching the matching anchor.
When crossResourceBoundary is true the walker is currently
recursing into a sub-tree that introduced its own $id; we still
recurse so a nested $anchor declared inside that same sub-resource
is reachable from the caller that owns that resource, but we skip
further nested resources for the same reason as above.
Recursively scan a schema document for a
$anchormatching the given name. Returns the schema object containing the anchor, or undefined.Per JSON Schema 2020-12 §8.2,
$anchoris scoped to the resource defined by the nearest enclosing$id. A bare DFS would happily cross resource boundaries and resolve to an anchor declared in an unrelated sub-resource — that violates the spec and produces wrong walker input when two sub-schemas use the same anchor name within their own$idscope.The walk skips into any sub-tree that introduces a new
$idvalue: such a sub-tree is a separate resource and its$anchors belong to that resource, not the caller's. Anchors declared at the same$idscope (or in nested sub-schemas without their own$id) remain reachable.The optional
visitedset guards against shared object references and cycles introduced by the OpenAPI bundler'sstructuredClone-based inlining of external refs. Without it a recursive document would stack overflow before reaching the matching anchor.When
crossResourceBoundaryistruethe walker is currently recursing into a sub-tree that introduced its own$id; we still recurse so a nested$anchordeclared inside that same sub-resource is reachable from the caller that owns that resource, but we skip further nested resources for the same reason as above.