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
Detect whether a document is Swagger 2.0 (OpenAPI 2.0).
SOURCE-OF-TRUTH: mirrors runtime
isSwagger2inpackages/core/src/core/version.ts(line 305), which parses theswaggerfield viadetectOpenApiVersion(line 264) and returns true for any document whose major version is2. Runtime therefore accepts"2.0","2.0.0","2.1", any other2.xform — and the numeric literals2and2.0. The type-level detector must mirror every shape the runtime accepts, otherwise a numeric-versioned document silently bypasses the fallback and producesunknowninstead of the__SchemaInferenceFellBackbrand 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
__SchemaInferenceFellBackdeliberately rather than silently producingunknown.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 parsedOpenApiVersionInfoobject form, mirroring the runtime's tolerance for pre-parsed version metadata