From f3055c71f50bf8bbdbb368ba883394ea6a68c9dd Mon Sep 17 00:00:00 2001 From: Aaron Longwell Date: Tue, 24 Feb 2026 15:25:30 -0800 Subject: [PATCH] feat!: upgrade schemars from 0.8 to 1.2 BREAKING CHANGE: `ToolInputSchema::from_root_schema()` renamed to `from_schema()` and now accepts `&schemars::Schema` instead of `&schemars::schema::RootSchema`, which was removed in schemars 1.0. Schemars 1.x generates JSON Schema Draft 2020-12 by default (using `$defs` instead of `definitions`). All `#[derive(JsonSchema)]` usage across the workspace is compatible without changes. Bumps workspace version to 0.4.0. --- Cargo.toml | 8 ++++---- mixtape-anthropic-sdk/src/tools.rs | 19 ++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 70686cc..a92aa49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["mixtape-core", "mixtape-anthropic-sdk", "mixtape-tools", "mixtape-cl resolver = "2" [workspace.package] -version = "0.3.1" +version = "0.4.0" edition = "2021" license = "MIT" homepage = "https://github.com/adlio/mixtape" @@ -11,8 +11,8 @@ repository = "https://github.com/adlio/mixtape" [workspace.dependencies] # Internal crates -mixtape-core = { version = "0.3.1", path = "./mixtape-core" } -mixtape-anthropic-sdk = { version = "0.3.1", path = "./mixtape-anthropic-sdk" } +mixtape-core = { version = "0.4.0", path = "./mixtape-core" } +mixtape-anthropic-sdk = { version = "0.4.0", path = "./mixtape-anthropic-sdk" } mixtape-tools = { path = "./mixtape-tools" } mixtape-cli = { path = "./mixtape-cli" } mixtape-server = { path = "./mixtape-server" } @@ -33,7 +33,7 @@ tower-http = { version = "0.6", features = ["cors", "trace"] } # Serialization serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -schemars = "0.8" +schemars = "1.2" # Error handling thiserror = "1.0" diff --git a/mixtape-anthropic-sdk/src/tools.rs b/mixtape-anthropic-sdk/src/tools.rs index 69e1830..8c5dbf1 100644 --- a/mixtape-anthropic-sdk/src/tools.rs +++ b/mixtape-anthropic-sdk/src/tools.rs @@ -128,7 +128,7 @@ impl ToolInputSchema { } } - /// Create a ToolInputSchema from a schemars RootSchema + /// Create a ToolInputSchema from a schemars Schema /// /// This converts a schema generated by `schemars::schema_for!()` into /// the format expected by the Anthropic API. Requires the `schemars` feature. @@ -149,12 +149,12 @@ impl ToolInputSchema { /// } /// /// let schema = schema_for!(WeatherParams); - /// let tool_schema = ToolInputSchema::from_root_schema(&schema); + /// let tool_schema = ToolInputSchema::from_schema(&schema); /// # } /// ``` #[cfg(feature = "schemars")] - pub fn from_root_schema(schema: &schemars::schema::RootSchema) -> Self { - // Convert the root schema to a Value, then extract what we need + pub fn from_schema(schema: &schemars::Schema) -> Self { + // Convert the schema to a Value, then extract what we need let schema_value = serde_json::to_value(schema).unwrap_or(Value::Object(Default::default())); @@ -176,10 +176,7 @@ impl ToolInputSchema { .collect() }); - // Copy over definitions if present (for nested types) - if let Some(defs) = schema_value.get("definitions") { - additional.insert("definitions".to_string(), defs.clone()); - } + // Copy over $defs if present (for nested types) if let Some(defs) = schema_value.get("$defs") { additional.insert("$defs".to_string(), defs.clone()); } @@ -407,7 +404,7 @@ mod tests { #[cfg(feature = "schemars")] #[test] - fn test_from_root_schema() { + fn test_from_schema() { use schemars::{schema_for, JsonSchema}; #[derive(JsonSchema)] @@ -417,8 +414,8 @@ mod tests { unit: Option, } - let root_schema = schema_for!(TestParams); - let tool_schema = ToolInputSchema::from_root_schema(&root_schema); + let schema = schema_for!(TestParams); + let tool_schema = ToolInputSchema::from_schema(&schema); assert_eq!(tool_schema.schema_type, "object"); assert!(tool_schema.properties.is_some());