Skip to content

Commit 35976a6

Browse files
committed
fix(model): skip extensions field in json schema generation
The `Extensions` type was incorrectly included in JSON schema generation, which could lead to confusing API documentation. This commit adds `#[schemars(skip)]` attribute to all `extensions` fields in request and notification structs, and removes the manual `JsonSchema` implementation for the `Extensions` type since it's an internal implementation detail that shouldn't be exposed in the schema.
1 parent d419550 commit 35976a6

File tree

5 files changed

+29
-261
lines changed

5 files changed

+29
-261
lines changed

crates/rmcp/src/model.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ pub struct Request<M = String, P = JsonObject> {
243243
/// extensions will carry anything possible in the context, including [`Meta`]
244244
///
245245
/// this is similar with the Extensions in `http` crate
246+
#[schemars(skip)]
246247
pub extensions: Extensions,
247248
}
248249

@@ -264,6 +265,7 @@ pub struct RequestOptionalParam<M = String, P = JsonObject> {
264265
/// extensions will carry anything possible in the context, including [`Meta`]
265266
///
266267
/// this is similar with the Extensions in `http` crate
268+
#[schemars(skip)]
267269
pub extensions: Extensions,
268270
}
269271

@@ -274,6 +276,7 @@ pub struct RequestNoParam<M = String> {
274276
/// extensions will carry anything possible in the context, including [`Meta`]
275277
///
276278
/// this is similar with the Extensions in `http` crate
279+
#[schemars(skip)]
277280
pub extensions: Extensions,
278281
}
279282

@@ -293,6 +296,7 @@ pub struct Notification<M = String, P = JsonObject> {
293296
/// extensions will carry anything possible in the context, including [`Meta`]
294297
///
295298
/// this is similar with the Extensions in `http` crate
299+
#[schemars(skip)]
296300
pub extensions: Extensions,
297301
}
298302

@@ -303,6 +307,7 @@ pub struct NotificationNoParam<M = String> {
303307
/// extensions will carry anything possible in the context, including [`Meta`]
304308
///
305309
/// this is similar with the Extensions in `http` crate
310+
#[schemars(skip)]
306311
pub extensions: Extensions,
307312
}
308313

crates/rmcp/src/model/extension.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,6 @@ impl fmt::Debug for Extensions {
279279
}
280280
}
281281

282-
impl schemars::JsonSchema for Extensions {
283-
fn schema_name() -> String {
284-
"Extensions".to_string()
285-
}
286-
287-
fn json_schema(generator: &mut schemars::SchemaGenerator) -> schemars::schema::Schema {
288-
generator.subschema_for::<serde_json::Value>()
289-
}
290-
}
291-
292282
trait AnyClone: Any {
293283
fn clone_box(&self) -> Box<dyn AnyClone + Send + Sync>;
294284
fn as_any(&self) -> &dyn Any;
Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1-
#[cfg(feature = "schemars")]
21
mod tests {
32
use rmcp::model::{ClientJsonRpcMessage, ServerJsonRpcMessage};
4-
use super::*;
53
use schemars::schema_for;
64

75
#[test]
86
fn test_client_json_rpc_message_schema() {
97
let schema = schema_for!(ClientJsonRpcMessage);
108
let schema_str = serde_json::to_string_pretty(&schema).unwrap();
11-
let expected = std::fs::read_to_string("tests/test_message_schema/client_json_rpc_message_schema.json").unwrap();
12-
assert_eq!(schema_str, expected, "Schema generation for ClientJsonRpcMessage should match expected output");
9+
let expected = std::fs::read_to_string(
10+
"tests/test_message_schema/client_json_rpc_message_schema.json",
11+
)
12+
.unwrap();
13+
14+
// Parse both strings to JSON values for more robust comparison
15+
let schema_json: serde_json::Value = serde_json::from_str(&schema_str).unwrap();
16+
let expected_json: serde_json::Value = serde_json::from_str(&expected).unwrap();
17+
assert_eq!(
18+
schema_json, expected_json,
19+
"Schema generation for ClientJsonRpcMessage should match expected output"
20+
);
1321
}
1422

1523
#[test]
1624
fn test_server_json_rpc_message_schema() {
1725
let schema = schema_for!(ServerJsonRpcMessage);
1826
let schema_str = serde_json::to_string_pretty(&schema).unwrap();
19-
let expected = std::fs::read_to_string("tests/test_message_schema/server_json_rpc_message_schema.json").unwrap();
20-
assert_eq!(schema_str, expected, "Schema generation for ServerJsonRpcMessage should match expected output");
27+
let expected = std::fs::read_to_string(
28+
"tests/test_message_schema/server_json_rpc_message_schema.json",
29+
)
30+
.unwrap();
31+
32+
// Parse both strings to JSON values for more robust comparison
33+
let schema_json: serde_json::Value = serde_json::from_str(&schema_str).unwrap();
34+
let expected_json: serde_json::Value = serde_json::from_str(&expected).unwrap();
35+
assert_eq!(
36+
schema_json, expected_json,
37+
"Schema generation for ServerJsonRpcMessage should match expected output"
38+
);
2139
}
2240
}

0 commit comments

Comments
 (0)