Skip to content

Commit 26609e1

Browse files
committed
chore(deps): update schemars requirement from 0.8 to 0.9
1 parent abf7c7a commit 26609e1

File tree

6 files changed

+38
-42
lines changed

6 files changed

+38
-42
lines changed

crates/rmcp/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ paste = { version = "1", optional = true }
2828
oauth2 = { version = "5.0", optional = true }
2929

3030
# for auto generate schema
31-
schemars = { version = "0.8", optional = true, features = ["chrono"] }
31+
schemars = { version = "0.9", optional = true }
3232

3333
# for image encoding
3434
base64 = { version = "0.22", optional = true }
@@ -134,7 +134,7 @@ schemars = ["dep:schemars"]
134134

135135
[dev-dependencies]
136136
tokio = { version = "1", features = ["full"] }
137-
schemars = { version = "0.8" }
137+
schemars = { version = "0.9", features = ["chrono04"] }
138138

139139
anyhow = "1.0"
140140
tracing-subscriber = { version = "0.3", features = [

crates/rmcp/src/handler/server/tool.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
};
44

55
use futures::future::BoxFuture;
6-
use schemars::JsonSchema;
6+
use schemars::{JsonSchema, transform::AddNullable};
77
use serde::{Deserialize, Serialize, de::DeserializeOwned};
88
use tokio_util::sync::CancellationToken;
99

@@ -14,12 +14,11 @@ use crate::{
1414
};
1515
/// A shortcut for generating a JSON schema for a type.
1616
pub fn schema_for_type<T: JsonSchema>() -> JsonObject {
17-
let mut settings = schemars::r#gen::SchemaSettings::default();
18-
settings.option_nullable = true;
19-
settings.option_add_null_type = false;
20-
settings.definitions_path = "#/components/schemas/".to_owned();
17+
let mut settings = schemars::generate::SchemaSettings::default();
18+
19+
settings.definitions_path = Cow::Borrowed("#/components/schemas/");
2120
settings.meta_schema = None;
22-
settings.visitors = Vec::default();
21+
settings.transforms = vec![Box::new(AddNullable::default())];
2322
settings.inline_subschemas = false;
2423
let generator = settings.into_generator();
2524
let schema = generator.into_root_schema_for::<T>();
@@ -180,11 +179,11 @@ pub struct Parameter<K: ConstString, V>(pub K, pub V);
180179
pub struct Parameters<P>(pub P);
181180

182181
impl<P: JsonSchema> JsonSchema for Parameters<P> {
183-
fn schema_name() -> String {
182+
fn schema_name() -> Cow<'static, str> {
184183
P::schema_name()
185184
}
186185

187-
fn json_schema(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
186+
fn json_schema(generator: &mut schemars::SchemaGenerator) -> schemars::Schema {
188187
P::json_schema(generator)
189188
}
190189
}

crates/rmcp/src/model.rs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,19 @@ macro_rules! const_string {
9191

9292
#[cfg(feature = "schemars")]
9393
impl schemars::JsonSchema for $name {
94-
fn schema_name() -> String {
95-
stringify!($name).to_string()
94+
fn schema_name() -> Cow<'static, str> {
95+
Cow::Borrowed(stringify!($name))
9696
}
9797

98-
fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::schema::Schema {
99-
// Create a schema for a constant value of type String
100-
schemars::schema::Schema::Object(schemars::schema::SchemaObject {
101-
instance_type: Some(schemars::schema::InstanceType::String.into()),
102-
format: Some("const".to_string()),
103-
const_value: Some(serde_json::Value::String($value.into())),
104-
..Default::default()
105-
})
98+
fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
99+
use serde_json::{Map, json};
100+
101+
let mut schema_map = Map::new();
102+
schema_map.insert("type".to_string(), json!("string"));
103+
schema_map.insert("format".to_string(), json!("const"));
104+
schema_map.insert("const".to_string(), json!($value));
105+
106+
schemars::Schema::from(schema_map)
106107
}
107108
}
108109
};
@@ -212,27 +213,23 @@ impl<'de> Deserialize<'de> for NumberOrString {
212213

213214
#[cfg(feature = "schemars")]
214215
impl schemars::JsonSchema for NumberOrString {
215-
fn schema_name() -> String {
216-
"NumberOrString".to_string()
216+
fn schema_name() -> Cow<'static, str> {
217+
Cow::Borrowed("NumberOrString")
217218
}
218219

219-
fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::schema::Schema {
220-
schemars::schema::Schema::Object(schemars::schema::SchemaObject {
221-
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
222-
one_of: Some(vec![
223-
schemars::schema::Schema::Object(schemars::schema::SchemaObject {
224-
instance_type: Some(schemars::schema::InstanceType::Number.into()),
225-
..Default::default()
226-
}),
227-
schemars::schema::Schema::Object(schemars::schema::SchemaObject {
228-
instance_type: Some(schemars::schema::InstanceType::String.into()),
229-
..Default::default()
230-
}),
231-
]),
232-
..Default::default()
233-
})),
234-
..Default::default()
235-
})
220+
fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
221+
use serde_json::{Map, json};
222+
223+
let mut number_schema = Map::new();
224+
number_schema.insert("type".to_string(), json!("number"));
225+
226+
let mut string_schema = Map::new();
227+
string_schema.insert("type".to_string(), json!("string"));
228+
229+
let mut schema_map = Map::new();
230+
schema_map.insert("oneOf".to_string(), json!([number_schema, string_schema]));
231+
232+
schemars::Schema::from(schema_map)
236233
}
237234
}
238235

examples/servers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tracing-subscriber = { version = "0.3", features = [
3333
futures = "0.3"
3434
rand = { version = "0.9", features = ["std"] }
3535
axum = { version = "0.8", features = ["macros"] }
36-
schemars = { version = "0.8", optional = true }
36+
schemars = { version = "0.9", optional = true }
3737
reqwest = { version = "0.12", features = ["json"] }
3838
chrono = "0.4"
3939
uuid = { version = "1.6", features = ["v4", "serde"] }

examples/servers/src/common/counter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{borrow::Cow, sync::Arc};
22

33
use rmcp::{
44
Error as McpError, RoleServer, ServerHandler, const_string, model::*, schemars,

examples/transport/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tracing-subscriber = { version = "0.3", features = [
3636
] }
3737
futures = "0.3"
3838
rand = { version = "0.9" }
39-
schemars = { version = "0.8", optional = true }
39+
schemars = { version = "0.9", optional = true }
4040
hyper = { version = "1", features = ["client", "server", "http1"] }
4141
hyper-util = { version = "0.1", features = ["tokio"] }
4242
tokio-tungstenite = "0.26.2"

0 commit comments

Comments
 (0)