//#region src/core/version.d.ts /** * JSON Schema draft and OpenAPI version detection. * * Detects the version from `$schema` URIs and OpenAPI `openapi`/`swagger` * fields. Used by the normaliser to apply version-specific transformations * before the walker processes the schema. */ type JsonSchemaDraft = "draft-04" | "draft-06" | "draft-07" | "draft-2019-09" | "draft-2020-12"; /** * Match a `$schema` URI string to a known draft. Returns `undefined` * when the URI matches none of the documented Draft 04 – Draft 2020-12 * schema URIs (including the known prefix patterns) — callers can use * this to distinguish an authoritative match from a silent fallback. */ declare function matchJsonSchemaDraftUri(uri: string): JsonSchemaDraft | undefined; /** * Detect the JSON Schema draft version from a schema's `$schema` URI. * When `$schema` is absent, uses heuristic keyword detection via * `inferJsonSchemaDraft` to guess the draft version. * Returns `"draft-2020-12"` as the final fallback when no heuristic * matches either. */ declare function detectJsonSchemaDraft(schema: Record): JsonSchemaDraft; /** * Inference result carrying the detected draft and the heuristic * that triggered it. */ interface InferredDraft { draft: JsonSchemaDraft; inferredFrom: string; } /** * Infer the JSON Schema draft from keyword presence when `$schema` * is absent. Examined from highest-confidence to lowest. * * Heuristics: * 1. `$dynamicRef` / `$dynamicAnchor` / `prefixItems` → Draft 2020-12 * 2. `$recursiveRef` / `$recursiveAnchor` / `unevaluatedProperties` / * `dependentSchemas` → Draft 2019-09 * 3. `if` / `then` / `else`, `contentEncoding` / `contentMediaType` → Draft 07 * 4. `const`, `examples` (array), `propertyNames` → Draft 06 * 5. Boolean `exclusiveMinimum`, `id` (no `$`), `definitions` only → Draft 04 * 6. No signal → Draft 2020-12 */ declare function inferJsonSchemaDraft(schema: Record): JsonSchemaDraft; /** * Like `inferJsonSchemaDraft` but also returns the heuristic that * triggered the inference, for diagnostic emission. */ declare function inferJsonSchemaDraftWithReason(schema: Record): InferredDraft; /** * Parsed OpenAPI version triple (e.g. `{ major: 3, minor: 1, patch: 0 }`). * Produced by `detectOpenApiVersion` so downstream helpers can switch on * the canonical numeric form rather than re-parsing the raw `openapi` / * `swagger` string. */ interface OpenApiVersionInfo { major: number; minor: number; patch: number; } /** * Detect the OpenAPI/Swagger version from a document. * * Returns `undefined` when the document declares neither `swagger` nor * `openapi` strings, or when the declared version string is malformed * (missing parts or non-numeric segments). `Number("abc")` yields `NaN`, * which `parts[i] ?? default` does NOT replace — nullish coalescing only * substitutes `null`/`undefined` — so any unparseable segment surfaces * as `undefined` rather than a silent fabricated default. */ declare function detectOpenApiVersion(doc: Record): OpenApiVersionInfo | undefined; /** * Check if an OpenAPI version is 3.0.x (uses modified Draft 04 schemas * with `nullable` instead of `anyOf [T, null]`). */ declare function isOpenApi30(version: OpenApiVersionInfo): boolean; /** * Check if an OpenAPI version is 3.1.x (uses standard Draft 2020-12). */ declare function isOpenApi31(version: OpenApiVersionInfo): boolean; /** * Check if a document is Swagger 2.0. */ declare function isSwagger2(version: OpenApiVersionInfo): boolean; /** * Result of inspecting a document for the OpenAPI 3.1 `jsonSchemaDialect` * keyword. * * - `kind: "absent"`: the keyword is not declared. The walker assumes * Draft 2020-12, which is the spec-defined default. * - `kind: "known"`: the declared dialect URI matches one of the * supported drafts. The corresponding `JsonSchemaDraft` is returned so * the normaliser can route to the matching per-node transforms. * - `kind: "unknown"`: the keyword is present but its URI does not * match any supported draft. The caller should emit an * `unknown-json-schema-dialect` diagnostic and fall back to * Draft 2020-12. */ type JsonSchemaDialectInfo = { kind: "absent"; } | { kind: "known"; uri: string; draft: JsonSchemaDraft; } | { kind: "unknown"; uri: string; }; /** * Inspect an OpenAPI 3.1 document for a `jsonSchemaDialect` declaration. * * Per the OpenAPI 3.1 spec, an OpenAPI document may declare the default * JSON Schema dialect for its Schema Objects via the top-level * `jsonSchemaDialect` URI. Real-world 3.1 documents overwhelmingly omit * the keyword and rely on the spec-defined Draft 2020-12 default — this * helper surfaces the declaration so the normaliser can either honour a * known dialect or emit a diagnostic for an unknown one. */ declare function readJsonSchemaDialect(doc: Record): JsonSchemaDialectInfo; //#endregion export { detectJsonSchemaDraft as a, inferJsonSchemaDraftWithReason as c, isSwagger2 as d, matchJsonSchemaDraftUri as f, OpenApiVersionInfo as i, isOpenApi30 as l, JsonSchemaDialectInfo as n, detectOpenApiVersion as o, readJsonSchemaDialect as p, JsonSchemaDraft as r, inferJsonSchemaDraft as s, InferredDraft as t, isOpenApi31 as u };