Upgrading schemars 0.9 to 1
Breaking0.9.0 → 1.2.3Breaking38Platform3Deprecated2New28Changed15Fixed27Other1
BreakingUpgrade verdict
36 breaking changes and 3 platform requirement changes.
In plain terms
- 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.
Must act 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 ↗What you must change
Breaking36
Removes the deprecated gen module.
genRemoves the
include_type_name setting that added the "x-rust-type" property to generated schemas.include_type_namex-rust-typeRenames 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.
enumset1enumsetJsonSchemaEnumSetRemoves the
phone validation attribute to match the latest validator crate.phonerequired_nestedRenames
SchemaSettings::visitors to SchemaSettings::transforms.SchemaSettings::visitorsSchemaSettings::transformsRenames
SchemaSettings::with_visitor to SchemaSettings::with_transform.SchemaSettings::with_visitorSchemaSettings::with_transformRenames
SchemaGenerator::visitors_mut to SchemaGenerator::transforms_mut.SchemaGenerator::visitors_mutSchemaGenerator::transforms_mutRenames
GenVisitor to GenTransform.GenVisitorGenTransformRenames
Visitor::visit_schema to Transform::transform.Visitor::visit_schemaTransform::transformRenames
visit::visit_schema to transform::transform_subschemas.visit::visit_schematransform::transform_subschemasRequires
GenTransform to implement Send but no longer requires Debug.GenTransformSendDebugSchemas from draft2019_09, draft2020_12 and default settings now use
$defs instead of definitions.SchemaSettings::draft2019_09()SchemaSettings::draft2020_12()$defsdefinitionsRemoves
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_str02Removes deprecated
SchemaGenerator methods make_extensible, schema_for_any and schema_for_none.SchemaGenerator::make_extensibleSchemaGenerator::schema_for_anySchemaGenerator::schema_for_noneRemoves the
schemars::Set and schemars::Map type aliases.schemars::Setschemars::MapRemoves
visit_schema_object and visit_root_schema from the Visitor trait; visit_schema is unchanged.Visitorvisit_schema_objectvisit_root_schemavisit_schemaRemoves old optional dependency versions: indexmap, uuid08, arrayvec05 and bigdecimal03.
indexmapuuid08arrayvec05bigdecimal03indexmap2uuid1arrayvec07bigdecimal04Removes the
retain_examples field from SetSingleExample, which is now a unit struct.SetSingleExampleretain_examplesUses patternProperties on map schemas where appropriate, so BTreeMap and HashMap only implement JsonSchema when both K and V do.
patternPropertiesBTreeMapHashMapJsonSchemaInvalid
with/serialize_with attributes now fail compilation instead of being silently ignored.withserialize_withReworks 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_typeAddNullableChanges 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_transformsChanges the
example attribute value to an arbitrary expression instead of a string literal naming a function, making string-literal function paths a compile error.exampleInvalid attributes that were previously silently ignored, such as setting
schema_with on structs, now cause compile errors.schema_withRequires
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_mutGenVisitorDefault
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()CowThe
SchemaGenerator.definitions field is now a serde_json::Map<String, Value>.SchemaGenerator.definitionsserde_json::MapRemoves the
schema module; Schema is now at the crate root and all other module types are removed.schemars::Schemaschemars::schema::SchemaRootSchemaSchemaObjectMetadataSubschemaValidationNumberValidationStringValidationRemoves the
impl_json_schema feature flag; JsonSchema is now always implemented on Schema.impl_json_schemaJsonSchemaSchemaRedefines the
Schema type as a thin wrapper around a serde_json::Value.Schemaserde_json::ValueMacros and functions that returned
RootSchema now return Schema.RootSchemaSchemaPlatform3
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.
Deprecations to plan for
Deprecated2
Deprecates GenTransform::as_any, to be removed before schemars 1.0 becomes stable.
GenTransform::as_anyReplaces 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