schema-components - v3.7.0
    Preparing search index...

    Function findAnchor

    • 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.

      Parameters

      • node: unknown
      • anchorName: string
      • visited: WeakSet<object> = ...

      Returns Record<string, unknown> | undefined