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

    Type Alias ResolveOpenAPIRef<Spec, Ref, Depth, Mode>

    ResolveOpenAPIRef: SpecDefs<Spec> extends infer Defs extends
        Record<string, unknown>
        ? Ref extends `#/components/schemas/${infer Name}`
            ? Spec["components"] extends Record<string, unknown>
                ? Spec["components"]["schemas"] extends Record<string, unknown>
                    ? Name extends keyof Spec["components"]["schemas"]
                        ? FromJSONSchema<
                            Spec["components"]["schemas"][Name],
                            Defs,
                            Depth,
                            Mode,
                        >
                        : unknown
                    : unknown
                : unknown
            : Ref extends `#/definitions/${infer Name}`
                ? Spec["definitions"] extends Record<string, unknown>
                    ? Name extends keyof Spec["definitions"]
                        ? FromJSONSchema<Spec["definitions"][Name], Defs, Depth, Mode>
                        : unknown
                    : unknown
                : Ref extends `#/paths/${infer PathRest}`
                    ? ResolvePathBasedRef<Spec, PathRest>
                    : unknown
        : unknown

    Resolves an OpenAPI ref string to its JSON Schema, then parses it.

    SOURCE-OF-TRUTH: mirrors runtime resolveRef in packages/core/src/core/ref.ts (line 90), which is invoked by the walker entry point in packages/core/src/core/walker.ts (lines 144-154) for OpenAPI documents. Any change to the runtime ref-resolution rules (new ref forms, different cycle handling, JSON Pointer decoding) must be reflected here and pinned in packages/core/tests/typeInference-walker-parity.test.ts.

    Handles:

    • #/components/schemas/Name (OpenAPI 3.x)
    • #/definitions/Name (Swagger 2.0)
    • #/paths/... (path-based refs, navigating the document tree)

    When the resolved schema itself contains nested $refs, the helper seeds FromJSONSchema's Defs parameter with the document's components.schemas (OAS 3.x) and definitions (Swagger 2.0) maps so the nested refs resolve correctly. Depth is threaded too so the recursion budget is shared with the calling context. Earlier revisions called FromJSONSchema<...> with the empty defaults and silently produced unknown for any nested ref.

    Type Parameters

    • Spec extends Record<string, unknown>
    • Ref extends string
    • Depth extends readonly unknown[] = []
    • Mode extends FromJSONSchemaMode = "both"