Skip to content

Upgrading schemars 0.9 to 1

Breaking0.9.0 → 1.2.3Breaking38Platform3Deprecated2New28Changed15Fixed27Other1

BreakingUpgrade verdict

36 breaking changes and 3 platform requirement changes.

  • The old gen module has been deleted, so any code importing it will no longer compile.
  • The option to add an `x-rust-type` property to schemas has been removed.
  • Code calling the old method name must be updated.
  • Support for the enumset crate is gone, since the generated schema was wrong for how EnumSet normally serializes.
Top 5 of 41 that need code or config changes

schemars publishes an official migration guide for version 1. It covers more than the release notes do.

Migration guide ↗
Breaking36
Removes the deprecated gen module.
gen
Removes the include_type_name setting that added the "x-rust-type" property to generated schemas.
include_type_namex-rust-type
Renames JsonSchema::always_inline_schema() to inline_schema().
JsonSchema::always_inline_schema()JsonSchema::inline_schema()
Removes the optional enumset1/enumset dependency because its JsonSchema impl did not match EnumSet's default serialization format.
enumset1enumsetJsonSchemaEnumSet
Removes the phone validation attribute to match the latest validator crate.
phonerequired_nested
Renames SchemaSettings::visitors to SchemaSettings::transforms.
SchemaSettings::visitorsSchemaSettings::transforms
Renames SchemaSettings::with_visitor to SchemaSettings::with_transform.
SchemaSettings::with_visitorSchemaSettings::with_transform
Renames SchemaGenerator::visitors_mut to SchemaGenerator::transforms_mut.
SchemaGenerator::visitors_mutSchemaGenerator::transforms_mut
Renames GenVisitor to GenTransform.
GenVisitorGenTransform
Renames Visitor::visit_schema to Transform::transform.
Visitor::visit_schemaTransform::transform
Renames visit::visit_schema to transform::transform_subschemas.
visit::visit_schematransform::transform_subschemas
Requires GenTransform to implement Send but no longer requires Debug.
GenTransformSendDebug
Schemas from draft2019_09, draft2020_12 and default settings now use $defs instead of definitions.
SchemaSettings::draft2019_09()SchemaSettings::draft2020_12()$defsdefinitions
Removes JsonSchema::is_referenceable() and replaces it with JsonSchema::always_inline(), which returns the opposite value.
JsonSchema::is_referenceable()JsonSchema::always_inline()
Renames optional dependency features to include their versions: chrono04, either1, smallvec1, url2, bytes1, rust_decimal1, enumset1, smol_str02, semver1.
chrono04either1smallvec1url2bytes1rust_decimal1enumset1smol_str02
Removes deprecated SchemaGenerator methods make_extensible, schema_for_any and schema_for_none.
SchemaGenerator::make_extensibleSchemaGenerator::schema_for_anySchemaGenerator::schema_for_none
Removes the schemars::Set and schemars::Map type aliases.
schemars::Setschemars::Map
Removes visit_schema_object and visit_root_schema from the Visitor trait; visit_schema is unchanged.
Visitorvisit_schema_objectvisit_root_schemavisit_schema
Removes old optional dependency versions: indexmap, uuid08, arrayvec05 and bigdecimal03.
indexmapuuid08arrayvec05bigdecimal03indexmap2uuid1arrayvec07bigdecimal04
Removes the retain_examples field from SetSingleExample, which is now a unit struct.
SetSingleExampleretain_examples
Uses patternProperties on map schemas where appropriate, so BTreeMap and HashMap only implement JsonSchema when both K and V do.
patternPropertiesBTreeMapHashMapJsonSchema
Invalid with/serialize_with attributes now fail compilation instead of being silently ignored.
withserialize_with
Reworks nullable schema generation for Option<T>; option_nullable and option_add_null_type are no longer used and AddNullable transform controls nullable output.
Option<T>SchemaSettings::option_nullableSchemaSettings::option_add_null_typeAddNullable
Changes SchemaSettings::meta_schema and definitions_path from String to Cow<'static, str> to ease const construction.
SchemaSettings::meta_schemaSchemaSettings::definitions_pathCow<'static, str>
SchemaGenerator::take_definitions now takes an apply_transforms flag to apply the generator's current transforms to returned schemas.
SchemaGenerator::take_definitionsapply_transforms
Changes the example attribute value to an arbitrary expression instead of a string literal naming a function, making string-literal function paths a compile error.
example
Invalid attributes that were previously silently ignored, such as setting schema_with on structs, now cause compile errors.
schema_with
Requires regex and contains validation attributes in list form #[validate(regex(path = ...))] instead of name/value form.
regexcontains#[validate(regex(path = ...))]
Replaces the visit module and Visitor trait with transform and Transform, renaming related items.
visitVisitortransformTransformSchemaSettings::visitorsSchemaSettings::with_visitorSchemaGenerator::visitors_mutGenVisitor
Default SchemaSettings now conform to JSON Schema draft 2020-12 instead of draft 7.
SchemaSettingsschema_for!()schema_for_value!()SchemaGenerator::default()
JsonSchema::schema_name() now returns Cow<'static, str> instead of String.
JsonSchema::schema_name()Cow
The SchemaGenerator.definitions field is now a serde_json::Map<String, Value>.
SchemaGenerator.definitionsserde_json::Map
Removes the schema module; Schema is now at the crate root and all other module types are removed.
schemars::Schemaschemars::schema::SchemaRootSchemaSchemaObjectMetadataSubschemaValidationNumberValidationStringValidation
Removes the impl_json_schema feature flag; JsonSchema is now always implemented on Schema.
impl_json_schemaJsonSchemaSchema
Redefines the Schema type as a thin wrapper around a serde_json::Value.
Schemaserde_json::Value
Macros and functions that returned RootSchema now return Schema.
RootSchemaSchema
Platform3
Raises the minimum supported Rust version to 1.74.
Raises the minimum supported Rust version (MSRV) to 1.70.
Raises the minimum supported Rust version (MSRV) to 1.65.
Deprecated2
Deprecates GenTransform::as_any, to be removed before schemars 1.0 becomes stable.
GenTransform::as_any
Replaces the schemars::gen module with schemars::generate because gen is a reserved keyword in Rust 2024; schemars::gen remains but is deprecated.
schemars::genschemars::generate