feat(model): add json schema generation support for all model types (#176)
* feat(model): add json schema generation support for all model types This commit adds JSON Schema support for all model types by implementing `schemars::JsonSchema` trait. The feature is gated behind the new `schemars` feature flag. This enables automatic schema generation for API documentation and validation purposes. Added tests to verify schema generation for client and server JSON-RPC messages. * fix(model): add manual json schema implementation for `NumberOrString` This commit adds a manual implementation of `JsonSchema` trait for the `NumberOrString` enum to properly represent its union type nature in JSON Schema. The schema now correctly specifies that the type can be either a number or a string using the `oneOf` validation keyword. * 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.
This commit is contained in:
parent
5d92061ece
commit
e9a5ae9901
1 changed files with 2790 additions and 1 deletions
|
|
@ -28,7 +28,7 @@ paste = { version = "1", optional = true }
|
|||
oauth2 = { version = "5.0", optional = true }
|
||||
|
||||
# for auto generate schema
|
||||
schemars = { version = "0.8", optional = true }
|
||||
schemars = { version = "0.8", optional = true, features = ["chrono"] }
|
||||
|
||||
# for image encoding
|
||||
base64 = { version = "0.21", optional = true }
|
||||
|
|
@ -89,6 +89,7 @@ tower = ["dep:tower-service"]
|
|||
__auth = ["dep:oauth2", "dep:reqwest", "dep:url"]
|
||||
auth = ["__auth", "reqwest?/rustls-tls"]
|
||||
auth-tls-no-provider = ["auth", "reqwest?/rustls-tls-no-provider"]
|
||||
schemars = ["dep:schemars"]
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
|
|
@ -131,3 +132,8 @@ name = "test_message_protocol"
|
|||
required-features = ["client"]
|
||||
path = "tests/test_message_protocol.rs"
|
||||
|
||||
[[test]]
|
||||
name = "test_message_schema"
|
||||
required-features = ["server", "client", "schemars"]
|
||||
path = "tests/test_message_schema.rs"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue