Skip to main content

Module import

Module import 

Source
Expand description

Importing repair schemas from JSON Schema documents

Converts a JSON Schema (as a serde_json::Value) into a TaggedEnumSchema or ObjectSchema, so schemas produced by schemars, Pydantic, or any other tool can drive fuzzy repair without hand-written builder code. With the schemars cargo feature enabled, [TaggedEnumSchema::from_type] / [ObjectSchema::from_type] derive the repair schema directly from a #[derive(JsonSchema)] type.

§Supported subset (v1)

  • Tagged enums: oneOf where every branch carries a common tag property with a const (or single-element enum) string value — the shape schemars emits for #[serde(tag = "...")] (internally tagged) and #[serde(tag = "...", content = "...")] (adjacently tagged).
  • Keywords: properties, enum, const, type, items, $ref / $defs (also legacy definitions), including the Draft 2020-12 sibling-$ref composition schemars emits for newtype variants. Option<T>-style nullable wrappers (anyOf: [T, {type: null}]) are unwrapped.
  • Type mapping: stringFieldKind::String, integerFieldKind::Integer, numberFieldKind::Number, booleanFieldKind::Bool, objectFieldKind::Object (recursive), arrays of string enums → FieldKind::EnumArray, arrays of objects → FieldKind::ObjectArray.

§Deliberately unsupported (v1)

  • Externally tagged enums (serde’s default representation) and untagged enums: rejected with an error. Annotate the enum with #[serde(tag = "...")] so a tag field exists for repair to anchor on.
  • required / default completion: missing fields are not filled in; the keywords are ignored.
  • Constructs with no repair semantics (allOf, patternProperties, tuples via prefixItems, nested oneOf on fields, recursive $ref cycles) degrade to FieldKind::Any and are reported as ImportWarnings rather than silently dropped.

Structs§

ImportWarning
A construct in the source JSON Schema that could not be converted.
SchemaImport
Result of a JSON Schema import: the converted schema plus warnings for every construct that could not be mapped (degraded to FieldKind::Any).