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

    Type Alias IsSwagger2Doc<Doc>

    IsSwagger2Doc: Doc extends { swagger: `2.${string}` }
        ? true
        : Doc extends { swagger: 2 }
            ? true
            : Doc extends { swagger: 2 }
                ? true
                : Doc extends { swagger: { major: 2 } } ? true : false

    Detect whether a document is Swagger 2.0 (OpenAPI 2.0).

    SOURCE-OF-TRUTH: mirrors runtime isSwagger2 in packages/core/src/core/version.ts (line 305), which parses the swagger field via detectOpenApiVersion (line 264) and returns true for any document whose major version is 2. Runtime therefore accepts "2.0", "2.0.0", "2.1", any other 2.x form — and the numeric literals 2 and 2.0. The type-level detector must mirror every shape the runtime accepts, otherwise a numeric-versioned document silently bypasses the fallback and produces unknown instead of the __SchemaInferenceFellBack brand consumers expect.

    Type-level Swagger 2.0 documents cannot be fully normalised at compile time — the rewrite reorders the document tree (definitions → components/schemas, body parameters → requestBody, etc.) in ways TypeScript's mapped-type machinery cannot express. Detecting the version is tractable, so we surface __SchemaInferenceFellBack deliberately rather than silently producing unknown.

    Accepted shapes:

    • { swagger: "2.<anything>" } — the on-the-wire string form
    • { swagger: 2 } / { swagger: 2.0 } — numeric on-the-wire form (some YAML serialisers emit a number rather than a string)
    • { swagger: { major: 2, ... } } — the parsed OpenApiVersionInfo object form, mirroring the runtime's tolerance for pre-parsed version metadata

    Type Parameters

    • Doc