schema-components 1.13.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +4 -0
  2. package/dist/core/adapter.d.mts +8 -3
  3. package/dist/core/adapter.mjs +25 -10
  4. package/dist/core/constraints.d.mts +3 -2
  5. package/dist/core/constraints.mjs +14 -2
  6. package/dist/core/diagnostics.d.mts +2 -0
  7. package/dist/core/diagnostics.mjs +33 -0
  8. package/dist/core/errors.d.mts +1 -1
  9. package/dist/core/formats.d.mts +33 -0
  10. package/dist/core/formats.mjs +67 -0
  11. package/dist/core/merge.d.mts +17 -1
  12. package/dist/core/merge.mjs +30 -1
  13. package/dist/core/normalise.d.mts +3 -2
  14. package/dist/core/normalise.mjs +1 -170
  15. package/dist/core/openapi30.d.mts +4 -1
  16. package/dist/core/openapi30.mjs +1 -222
  17. package/dist/core/ref.d.mts +2 -25
  18. package/dist/core/ref.mjs +102 -23
  19. package/dist/core/renderer.d.mts +1 -1
  20. package/dist/core/swagger2.d.mts +2 -1
  21. package/dist/core/swagger2.mjs +1 -293
  22. package/dist/core/typeInference.d.mts +2 -2
  23. package/dist/core/types.d.mts +2 -2
  24. package/dist/core/types.mjs +4 -1
  25. package/dist/core/version.d.mts +2 -2
  26. package/dist/core/version.mjs +84 -12
  27. package/dist/core/walkBuilders.d.mts +15 -1
  28. package/dist/core/walkBuilders.mjs +1 -1
  29. package/dist/core/walker.d.mts +1 -1
  30. package/dist/core/walker.mjs +122 -22
  31. package/dist/diagnostics-DzbZmcLI.d.mts +64 -0
  32. package/dist/html/a11y.d.mts +2 -2
  33. package/dist/html/renderToHtml.d.mts +2 -2
  34. package/dist/html/renderToHtmlStream.d.mts +2 -2
  35. package/dist/html/renderers.d.mts +2 -2
  36. package/dist/html/streamRenderers.d.mts +2 -2
  37. package/dist/normalise-tL9FckAk.mjs +748 -0
  38. package/dist/openapi/ApiCallbacks.d.mts +16 -0
  39. package/dist/openapi/ApiCallbacks.mjs +34 -0
  40. package/dist/openapi/ApiLinks.d.mts +16 -0
  41. package/dist/openapi/ApiLinks.mjs +42 -0
  42. package/dist/openapi/ApiResponseHeaders.d.mts +16 -0
  43. package/dist/openapi/ApiResponseHeaders.mjs +35 -0
  44. package/dist/openapi/ApiSecurity.d.mts +19 -0
  45. package/dist/openapi/ApiSecurity.mjs +33 -0
  46. package/dist/openapi/bundle.d.mts +47 -0
  47. package/dist/openapi/bundle.mjs +95 -0
  48. package/dist/openapi/components.d.mts +7 -2
  49. package/dist/openapi/components.mjs +30 -6
  50. package/dist/openapi/parser.d.mts +1 -1
  51. package/dist/react/SchemaComponent.d.mts +12 -5
  52. package/dist/react/SchemaComponent.mjs +13 -7
  53. package/dist/react/SchemaView.d.mts +10 -3
  54. package/dist/react/SchemaView.mjs +13 -7
  55. package/dist/react/fieldPath.d.mts +1 -1
  56. package/dist/react/headless.d.mts +1 -1
  57. package/dist/react/headlessRenderers.d.mts +1 -1
  58. package/dist/react/headlessRenderers.mjs +1 -1
  59. package/dist/ref-DvWoULcy.d.mts +44 -0
  60. package/dist/{renderer-DseHeliw.d.mts → renderer-BdSqllx5.d.mts} +1 -1
  61. package/dist/themes/mantine.d.mts +1 -1
  62. package/dist/themes/mui.d.mts +1 -1
  63. package/dist/themes/mui.mjs +1 -1
  64. package/dist/themes/radix.d.mts +1 -1
  65. package/dist/themes/shadcn.d.mts +1 -1
  66. package/dist/{typeInference-CRPqVwKu.d.mts → typeInference-k7FXfTVO.d.mts} +44 -8
  67. package/dist/{types-ag2jYLqQ.d.mts → types-D_5ST7SS.d.mts} +11 -3
  68. package/dist/version-B5NV-35j.d.mts +69 -0
  69. package/package.json +1 -1
  70. package/dist/version-CLchheaH.d.mts +0 -40
  71. /package/dist/{errors-DIKI2C78.d.mts → errors-C5zRC2PU.d.mts} +0 -0
@@ -1,4 +1,4 @@
1
- import { j as WalkedField } from "../types-ag2jYLqQ.mjs";
1
+ import { M as WalkedField } from "../types-D_5ST7SS.mjs";
2
2
 
3
3
  //#region src/react/fieldPath.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { r as ComponentResolver } from "../renderer-DseHeliw.mjs";
1
+ import { r as ComponentResolver } from "../renderer-BdSqllx5.mjs";
2
2
 
3
3
  //#region src/react/headless.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { l as RenderProps } from "../renderer-DseHeliw.mjs";
1
+ import { l as RenderProps } from "../renderer-BdSqllx5.mjs";
2
2
  import { ReactNode } from "react";
3
3
 
4
4
  //#region src/react/headlessRenderers.d.ts
@@ -1,6 +1,6 @@
1
1
  import { isObject } from "../core/guards.mjs";
2
- import { isValidElement, useCallback, useRef } from "react";
3
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { isValidElement, useCallback, useRef } from "react";
4
4
  //#region src/react/headlessRenderers.tsx
5
5
  /**
6
6
  * Headless renderer functions — one per schema type.
@@ -0,0 +1,44 @@
1
+ import { i as DiagnosticsOptions } from "./diagnostics-DzbZmcLI.mjs";
2
+
3
+ //#region src/core/ref.d.ts
4
+ /**
5
+ * Resolver function for external $ref URIs.
6
+ * Called with the URI portion (everything before `#`) of an external ref.
7
+ * Returns the parsed document (JSON object) or undefined.
8
+ */
9
+ type ExternalResolver = (uri: string) => unknown;
10
+ /**
11
+ * Options for $ref resolution.
12
+ */
13
+ interface RefOptions {
14
+ diagnostics?: DiagnosticsOptions;
15
+ externalResolver?: ExternalResolver;
16
+ }
17
+ /**
18
+ * Count all distinct `$ref` strings reachable from a root document.
19
+ * A chain longer than the number of distinct refs is necessarily cyclic.
20
+ * Returns at least 1 so that single-ref schemas have a usable bound.
21
+ */
22
+ declare function countDistinctRefs(root: Record<string, unknown>): number;
23
+ /**
24
+ * Resolve a `$ref` in a schema against a root document.
25
+ * Returns the original schema if no `$ref` is present.
26
+ * Returns an unknown-schema placeholder on cycle or depth exceeded.
27
+ *
28
+ * The depth bound is derived from the number of distinct `$ref` strings
29
+ * in the root document — a chain longer than that count is necessarily
30
+ * cyclic. When `maxDepth` is not provided, a reasonable default is used.
31
+ */
32
+ declare function resolveRef(schema: Record<string, unknown>, rootDocument: Record<string, unknown>, visited: Set<string>, diagnostics?: DiagnosticsOptions, maxDepth?: number, externalResolver?: ExternalResolver): Record<string, unknown>;
33
+ /**
34
+ * Dereference a JSON Pointer fragment (`#/path/to/schema`) or an
35
+ * `$anchor` (`#SomeName`) against a root document.
36
+ */
37
+ declare function dereference(ref: string, root: Record<string, unknown>): Record<string, unknown> | undefined;
38
+ /**
39
+ * Recursively scan a schema document for a `$anchor` matching the given name.
40
+ * Returns the schema object containing the anchor, or undefined.
41
+ */
42
+ declare function findAnchor(node: unknown, anchorName: string): Record<string, unknown> | undefined;
43
+ //#endregion
44
+ export { findAnchor as a, dereference as i, RefOptions as n, resolveRef as o, countDistinctRefs as r, ExternalResolver as t };
@@ -1,4 +1,4 @@
1
- import { E as StringConstraints, b as ObjectConstraints, f as FileConstraints, j as WalkedField, t as ArrayConstraints, v as NumberConstraints, w as SchemaMeta } from "./types-ag2jYLqQ.mjs";
1
+ import { D as StringConstraints, M as WalkedField, T as SchemaMeta, f as FileConstraints, t as ArrayConstraints, x as ObjectConstraints, y as NumberConstraints } from "./types-D_5ST7SS.mjs";
2
2
 
3
3
  //#region src/core/renderer.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { r as ComponentResolver } from "../renderer-DseHeliw.mjs";
1
+ import { r as ComponentResolver } from "../renderer-BdSqllx5.mjs";
2
2
 
3
3
  //#region src/themes/mantine.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { r as ComponentResolver } from "../renderer-DseHeliw.mjs";
1
+ import { r as ComponentResolver } from "../renderer-BdSqllx5.mjs";
2
2
 
3
3
  //#region src/themes/mui.d.ts
4
4
  /**
@@ -1,8 +1,8 @@
1
1
  import { isObject } from "../core/guards.mjs";
2
2
  import { toReactNode } from "../react/headlessRenderers.mjs";
3
3
  import { headlessResolver } from "../react/headless.mjs";
4
- import { isValidElement } from "react";
5
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
+ import { isValidElement } from "react";
6
6
  //#region src/themes/mui.tsx
7
7
  function ariaRequired(tree) {
8
8
  return { required: tree.isOptional === false };
@@ -1,4 +1,4 @@
1
- import { r as ComponentResolver } from "../renderer-DseHeliw.mjs";
1
+ import { r as ComponentResolver } from "../renderer-BdSqllx5.mjs";
2
2
 
3
3
  //#region src/themes/radix.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { r as ComponentResolver } from "../renderer-DseHeliw.mjs";
1
+ import { r as ComponentResolver } from "../renderer-BdSqllx5.mjs";
2
2
 
3
3
  //#region src/themes/shadcn.d.ts
4
4
  declare const shadcnResolver: ComponentResolver;
@@ -1,4 +1,4 @@
1
- import { d as FieldOverrides, u as FieldOverride } from "./types-ag2jYLqQ.mjs";
1
+ import { d as FieldOverrides, u as FieldOverride } from "./types-D_5ST7SS.mjs";
2
2
 
3
3
  //#region src/core/typeInference.d.ts
4
4
  /**
@@ -52,6 +52,38 @@ type FromJSONSchema<S, Defs extends Record<string, unknown> = Record<string, nev
52
52
  } ? ArrayToUnion<E> : S extends {
53
53
  type: infer T;
54
54
  } ? TypeToTs<T, S, Defs> : S extends readonly (infer E)[] ? E : unknown;
55
+ /**
56
+ * Marker type emitted when OpenAPI $ref resolution hits the type-level
57
+ * recursion depth limit. Instead of silently falling back to
58
+ * `Record<string, FieldOverride>`, produces this branded type so
59
+ * consumers can detect it via conditional types.
60
+ *
61
+ * Usage:
62
+ * ```ts
63
+ * type Fields = InferRequestBodyFields<Doc, "/users", "post">;
64
+ * type IsFallback = Fields extends __SchemaInferenceFellBack ? true : false;
65
+ * ```
66
+ */
67
+ interface __SchemaInferenceFellBack {
68
+ readonly __schemaInferenceFallback: unique symbol;
69
+ }
70
+ /**
71
+ * Escape hatch for recursive schemas where type-level inference
72
+ * cannot proceed. Typed as `Record<string, FieldOverride>` but
73
+ * explicitly branded so callers know they are using the unsafe path.
74
+ *
75
+ * JSDoc trade-off note: This bypasses field-level type safety.
76
+ * Prefer restructuring the schema to avoid deep $ref chains
77
+ * when possible.
78
+ */
79
+ type UnsafeFields = Record<string, FieldOverride> & {
80
+ /** Marks this as the unsafe fallback for recursive schemas. */readonly __unsafe?: true;
81
+ };
82
+ /**
83
+ * Convert a `FromJSONSchema` result to `unknown` when recursion is detected.
84
+ * Returns the original type when the schema is non-recursive.
85
+ */
86
+ type DetectRecursiveFallback<T> = unknown extends T ? __SchemaInferenceFellBack : T;
55
87
  /**
56
88
  * Resolve a $ref against the local definitions context.
57
89
  * Supports:
@@ -59,7 +91,7 @@ type FromJSONSchema<S, Defs extends Record<string, unknown> = Record<string, nev
59
91
  * - `#/$defs/Name` and `#/definitions/Name` (named definitions)
60
92
  * - `#SomeName` ($anchor, $dynamicAnchor resolved from definitions)
61
93
  */
62
- type ResolveSchemaRef<R extends string, Defs extends Record<string, unknown>> = R extends "#" ? unknown : R extends `#/$defs/${infer Name}` ? Name extends keyof Defs ? FromJSONSchema<Defs[Name], Defs> : unknown : R extends `#/definitions/${infer Name}` ? Name extends keyof Defs ? FromJSONSchema<Defs[Name], Defs> : unknown : R extends `#${infer AnchorName}` ? AnchorName extends keyof Defs ? FromJSONSchema<Defs[AnchorName], Defs> : unknown : unknown;
94
+ type ResolveSchemaRef<R extends string, Defs extends Record<string, unknown>, Depth extends number = 0> = Depth extends 10 ? __SchemaInferenceFellBack : R extends "#" ? unknown : R extends `#/$defs/${infer Name}` ? Name extends keyof Defs ? DetectRecursiveFallback<FromJSONSchema<Defs[Name], Defs>> : unknown : R extends `#/definitions/${infer Name}` ? Name extends keyof Defs ? DetectRecursiveFallback<FromJSONSchema<Defs[Name], Defs>> : unknown : R extends `#${infer AnchorName}` ? AnchorName extends keyof Defs ? DetectRecursiveFallback<FromJSONSchema<Defs[AnchorName], Defs>> : unknown : unknown;
63
95
  /**
64
96
  * Merge an allOf array into an intersection type.
65
97
  */
@@ -264,17 +296,21 @@ type OpenAPIRequestBodyType<Doc, Path extends string, Method extends string> = R
264
296
  type OpenAPIResponseType<Doc, Path extends string, Method extends string, Status extends string> = ResolveMaybeRef<Doc, ResponseSchemaOf<OperationOf<PathItemOf<Doc, Path>, Method>, Status>>;
265
297
  /**
266
298
  * Infer the fields prop type for ApiRequestBody.
267
- * Falls back to Record<string, FieldOverride> for runtime documents.
299
+ * Surfaces `__SchemaInferenceFellBack` when the schema contains
300
+ * recursive $ref chains that exceed type-level depth limits.
301
+ * Falls back to `Record<string, FieldOverride>` for runtime documents.
268
302
  */
269
- type InferRequestBodyFields<Doc, Path extends string, Method extends string> = unknown extends OpenAPIRequestBodyType<Doc, Path, Method> ? Record<string, FieldOverride> : FieldOverrides<OpenAPIRequestBodyType<Doc, Path, Method>>;
303
+ type InferRequestBodyFields<Doc, Path extends string, Method extends string> = unknown extends OpenAPIRequestBodyType<Doc, Path, Method> ? OpenAPIRequestBodyType<Doc, Path, Method> extends __SchemaInferenceFellBack ? __SchemaInferenceFellBack : Record<string, FieldOverride> : FieldOverrides<OpenAPIRequestBodyType<Doc, Path, Method>>;
270
304
  /**
271
305
  * Infer the fields prop type for ApiResponse.
272
- * Falls back to Record<string, FieldOverride> for runtime documents.
306
+ * Surfaces `__SchemaInferenceFellBack` when the schema contains
307
+ * recursive $ref chains that exceed type-level depth limits.
308
+ * Falls back to `Record<string, FieldOverride>` for runtime documents.
273
309
  */
274
- type InferResponseFields<Doc, Path extends string, Method extends string, Status extends string> = unknown extends OpenAPIResponseType<Doc, Path, Method, Status> ? Record<string, FieldOverride> : FieldOverrides<OpenAPIResponseType<Doc, Path, Method, Status>>;
310
+ type InferResponseFields<Doc, Path extends string, Method extends string, Status extends string> = unknown extends OpenAPIResponseType<Doc, Path, Method, Status> ? OpenAPIResponseType<Doc, Path, Method, Status> extends __SchemaInferenceFellBack ? __SchemaInferenceFellBack : Record<string, FieldOverride> : FieldOverrides<OpenAPIResponseType<Doc, Path, Method, Status>>;
275
311
  /**
276
312
  * Infer the overrides prop type for ApiParameters.
277
- * Falls back to Record<string, FieldOverride> for runtime documents.
313
+ * Falls back to `Record<string, FieldOverride>` for runtime documents.
278
314
  */
279
315
  type InferParameterOverrides<Doc, Path extends string, Method extends string> = string extends ParameterNamesOf<Doc, Path, Method> ? Record<string, FieldOverride> : Partial<Record<ParameterNamesOf<Doc, Path, Method>, FieldOverride>>;
280
316
  /**
@@ -296,4 +332,4 @@ type PathOfType<T, Prefix extends string = ""> = IsNarrowObject<T> extends true
296
332
  */
297
333
  type TypeAtPath<T, P extends string> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? TypeAtPath<T[Key], Rest> : unknown : P extends keyof T ? T[P] : unknown;
298
334
  //#endregion
299
- export { OpenAPIRequestBodyType as a, ResolveOpenAPIRef as c, InferResponseFields as i, TypeAtPath as l, InferParameterOverrides as n, OpenAPIResponseType as o, InferRequestBodyFields as r, PathOfType as s, FromJSONSchema as t };
335
+ export { OpenAPIRequestBodyType as a, ResolveOpenAPIRef as c, __SchemaInferenceFellBack as d, InferResponseFields as i, TypeAtPath as l, InferParameterOverrides as n, OpenAPIResponseType as o, InferRequestBodyFields as r, PathOfType as s, FromJSONSchema as t, UnsafeFields as u };
@@ -59,13 +59,15 @@ type FieldOverride = Partial<SchemaMeta> & {
59
59
  * All schema types the walker can produce.
60
60
  * Used as the discriminant in the WalkedField tagged union.
61
61
  */
62
- type SchemaType = "string" | "number" | "boolean" | "null" | "enum" | "literal" | "object" | "array" | "tuple" | "record" | "union" | "discriminatedUnion" | "conditional" | "negation" | "recursive" | "file" | "unknown";
62
+ type SchemaType = "string" | "number" | "boolean" | "null" | "enum" | "literal" | "object" | "array" | "tuple" | "record" | "union" | "discriminatedUnion" | "conditional" | "negation" | "recursive" | "file" | "never" | "unknown";
63
63
  /** Constraints that apply to string schemas. */
64
64
  interface StringConstraints {
65
65
  minLength?: number;
66
66
  maxLength?: number;
67
67
  pattern?: string;
68
68
  format?: string;
69
+ /** Derived RegExp from the format string, if the format is recognised. */
70
+ formatPattern?: RegExp;
69
71
  contentEncoding?: string;
70
72
  contentMediaType?: string;
71
73
  }
@@ -231,6 +233,11 @@ interface RecursiveField extends FieldBase {
231
233
  /** The $ref string that would create the cycle (e.g. "#" or "#Node"). */
232
234
  refTarget: string;
233
235
  }
236
+ /** Schema position where `false` appears — the field cannot have any value. */
237
+ interface NeverField extends FieldBase {
238
+ type: "never";
239
+ constraints: Record<string, never>;
240
+ }
234
241
  interface UnknownField extends FieldBase {
235
242
  type: "unknown";
236
243
  constraints: Record<string, never>;
@@ -239,7 +246,7 @@ interface UnknownField extends FieldBase {
239
246
  * Tagged union of all schema field types produced by the walker.
240
247
  * Use `field.type` to narrow to a specific variant.
241
248
  */
242
- type WalkedField = StringField | NumberField | BooleanField | NullField | EnumField | LiteralField | ObjectField | ArrayField | TupleField | RecordField | UnionField | DiscriminatedUnionField | ConditionalField | NegationField | RecursiveField | FileField | UnknownField;
249
+ type WalkedField = StringField | NumberField | BooleanField | NullField | EnumField | LiteralField | ObjectField | ArrayField | TupleField | RecordField | UnionField | DiscriminatedUnionField | ConditionalField | NegationField | RecursiveField | NeverField | FileField | UnknownField;
243
250
  declare function isStringField(field: WalkedField): field is StringField;
244
251
  declare function isNumberField(field: WalkedField): field is NumberField;
245
252
  declare function isBooleanField(field: WalkedField): field is BooleanField;
@@ -256,6 +263,7 @@ declare function isConditionalField(field: WalkedField): field is ConditionalFie
256
263
  declare function isNegationField(field: WalkedField): field is NegationField;
257
264
  declare function isFileField(field: WalkedField): field is FileField;
258
265
  declare function isRecursiveField(field: WalkedField): field is RecursiveField;
266
+ declare function isNeverField(field: WalkedField): field is NeverField;
259
267
  declare function isUnknownField(field: WalkedField): field is UnknownField;
260
268
  //#endregion
261
- export { UnknownField as A, isNullField as B, RecursiveField as C, StringField as D, StringConstraints as E, isDiscriminatedUnionField as F, isStringField as G, isObjectField as H, isEnumField as I, isUnknownField as J, isTupleField as K, isFileField as L, isArrayField as M, isBooleanField as N, TupleField as O, isConditionalField as P, isLiteralField as R, RecordField as S, SchemaType as T, isRecordField as U, isNumberField as V, isRecursiveField as W, resolveEditability as Y, NullField as _, DiscriminatedUnionField as a, ObjectConstraints as b, FieldBase as c, FieldOverrides as d, FileConstraints as f, NegationField as g, LiteralField as h, ConditionalField as i, WalkedField as j, UnionField as k, FieldConstraints as l, JsonObject as m, ArrayField as n, Editability as o, FileField as p, isUnionField as q, BooleanField as r, EnumField as s, ArrayConstraints as t, FieldOverride as u, NumberConstraints as v, SchemaMeta as w, ObjectField as x, NumberField as y, isNegationField as z };
269
+ export { UnionField as A, isNegationField as B, RecordField as C, StringConstraints as D, SchemaType as E, isConditionalField as F, isRecordField as G, isNullField as H, isDiscriminatedUnionField as I, isTupleField as J, isRecursiveField as K, isEnumField as L, WalkedField as M, isArrayField as N, StringField as O, isBooleanField as P, isFileField as R, ObjectField as S, SchemaMeta as T, isNumberField as U, isNeverField as V, isObjectField as W, isUnknownField as X, isUnionField as Y, resolveEditability as Z, NeverField as _, DiscriminatedUnionField as a, NumberField as b, FieldBase as c, FieldOverrides as d, FileConstraints as f, NegationField as g, LiteralField as h, ConditionalField as i, UnknownField as j, TupleField as k, FieldConstraints as l, JsonObject as m, ArrayField as n, Editability as o, FileField as p, isStringField as q, BooleanField as r, EnumField as s, ArrayConstraints as t, FieldOverride as u, NullField as v, RecursiveField as w, ObjectConstraints as x, NumberConstraints as y, isLiteralField as z };
@@ -0,0 +1,69 @@
1
+ //#region src/core/version.d.ts
2
+ /**
3
+ * JSON Schema draft and OpenAPI version detection.
4
+ *
5
+ * Detects the version from `$schema` URIs and OpenAPI `openapi`/`swagger`
6
+ * fields. Used by the normaliser to apply version-specific transformations
7
+ * before the walker processes the schema.
8
+ */
9
+ type JsonSchemaDraft = "draft-04" | "draft-06" | "draft-07" | "draft-2019-09" | "draft-2020-12";
10
+ /**
11
+ * Detect the JSON Schema draft version from a schema's `$schema` URI.
12
+ * When `$schema` is absent, uses heuristic keyword detection via
13
+ * `inferJsonSchemaDraft` to guess the draft version.
14
+ * Returns `"draft-2020-12"` as the final fallback when no heuristic
15
+ * matches either.
16
+ */
17
+ declare function detectJsonSchemaDraft(schema: Record<string, unknown>): JsonSchemaDraft;
18
+ /**
19
+ * Inference result carrying the detected draft and the heuristic
20
+ * that triggered it.
21
+ */
22
+ interface InferredDraft {
23
+ draft: JsonSchemaDraft;
24
+ inferredFrom: string;
25
+ }
26
+ /**
27
+ * Infer the JSON Schema draft from keyword presence when `$schema`
28
+ * is absent. Examined from highest-confidence to lowest.
29
+ *
30
+ * Heuristics:
31
+ * 1. `$dynamicRef` / `$dynamicAnchor` / `prefixItems` → Draft 2020-12
32
+ * 2. `$recursiveRef` / `$recursiveAnchor` / `unevaluatedProperties` /
33
+ * `dependentSchemas` → Draft 2019-09
34
+ * 3. `if` / `then` / `else`, `contentEncoding` / `contentMediaType` → Draft 07
35
+ * 4. `const`, `examples` (array), `propertyNames` → Draft 06
36
+ * 5. Boolean `exclusiveMinimum`, `id` (no `$`), `definitions` only → Draft 04
37
+ * 6. No signal → Draft 2020-12
38
+ */
39
+ declare function inferJsonSchemaDraft(schema: Record<string, unknown>): JsonSchemaDraft;
40
+ /**
41
+ * Like `inferJsonSchemaDraft` but also returns the heuristic that
42
+ * triggered the inference, for diagnostic emission.
43
+ */
44
+ declare function inferJsonSchemaDraftWithReason(schema: Record<string, unknown>): InferredDraft;
45
+ interface OpenApiVersionInfo {
46
+ major: number;
47
+ minor: number;
48
+ patch: number;
49
+ }
50
+ /**
51
+ * Detect the OpenAPI/Swagger version from a document.
52
+ * Returns `undefined` for documents that are not OpenAPI or Swagger.
53
+ */
54
+ declare function detectOpenApiVersion(doc: Record<string, unknown>): OpenApiVersionInfo | undefined;
55
+ /**
56
+ * Check if an OpenAPI version is 3.0.x (uses modified Draft 04 schemas
57
+ * with `nullable` instead of `anyOf [T, null]`).
58
+ */
59
+ declare function isOpenApi30(version: OpenApiVersionInfo): boolean;
60
+ /**
61
+ * Check if an OpenAPI version is 3.1.x (uses standard Draft 2020-12).
62
+ */
63
+ declare function isOpenApi31(version: OpenApiVersionInfo): boolean;
64
+ /**
65
+ * Check if a document is Swagger 2.0.
66
+ */
67
+ declare function isSwagger2(version: OpenApiVersionInfo): boolean;
68
+ //#endregion
69
+ export { detectOpenApiVersion as a, isOpenApi30 as c, detectJsonSchemaDraft as i, isOpenApi31 as l, JsonSchemaDraft as n, inferJsonSchemaDraft as o, OpenApiVersionInfo as r, inferJsonSchemaDraftWithReason as s, InferredDraft as t, isSwagger2 as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schema-components",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "React components that render UI from Zod schemas, JSON Schema, and OpenAPI documents",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -1,40 +0,0 @@
1
- //#region src/core/version.d.ts
2
- /**
3
- * JSON Schema draft and OpenAPI version detection.
4
- *
5
- * Detects the version from `$schema` URIs and OpenAPI `openapi`/`swagger`
6
- * fields. Used by the normaliser to apply version-specific transformations
7
- * before the walker processes the schema.
8
- */
9
- type JsonSchemaDraft = "draft-04" | "draft-06" | "draft-07" | "draft-2019-09" | "draft-2020-12";
10
- /**
11
- * Detect the JSON Schema draft version from a schema's `$schema` URI.
12
- * Returns `"draft-2020-12"` as the default when `$schema` is absent —
13
- * this is the most compatible assumption for modern schemas.
14
- */
15
- declare function detectJsonSchemaDraft(schema: Record<string, unknown>): JsonSchemaDraft;
16
- interface OpenApiVersionInfo {
17
- major: number;
18
- minor: number;
19
- patch: number;
20
- }
21
- /**
22
- * Detect the OpenAPI/Swagger version from a document.
23
- * Returns `undefined` for documents that are not OpenAPI or Swagger.
24
- */
25
- declare function detectOpenApiVersion(doc: Record<string, unknown>): OpenApiVersionInfo | undefined;
26
- /**
27
- * Check if an OpenAPI version is 3.0.x (uses modified Draft 04 schemas
28
- * with `nullable` instead of `anyOf [T, null]`).
29
- */
30
- declare function isOpenApi30(version: OpenApiVersionInfo): boolean;
31
- /**
32
- * Check if an OpenAPI version is 3.1.x (uses standard Draft 2020-12).
33
- */
34
- declare function isOpenApi31(version: OpenApiVersionInfo): boolean;
35
- /**
36
- * Check if a document is Swagger 2.0.
37
- */
38
- declare function isSwagger2(version: OpenApiVersionInfo): boolean;
39
- //#endregion
40
- export { isOpenApi30 as a, detectOpenApiVersion as i, OpenApiVersionInfo as n, isOpenApi31 as o, detectJsonSchemaDraft as r, isSwagger2 as s, JsonSchemaDraft as t };