typed-openrpc
typed-openrpc is a Rust workspace that helps you describe JSON-RPC 2.0 methods with strong typing and produce OpenRPC-compliant specifications automatically. The workspace contains:
- typed-openrpc – the core library with the
RpcMethodtrait, registries, and OpenRPC JSON generation. - typed-openrpc-macros – a procedural macro crate that lets you declare methods with
#[rpc_method(...)]annotations.
Features
- Derive JSON Schemas for params/results using
schemars. - Collect method metadata in a registry and emit OpenRPC documents at runtime.
- Optional
inventoryintegration for auto-discovery of annotated methods. - Proc-macro attribute that wires everything together with minimal boilerplate, inferring method names automatically.
Cargo Features
proc-macro– exposes the#[rpc_method]attribute. Enabled through thefullfeature or directly.inventory– collects registered methods via theinventorycrate. Combine withproc-macrofor auto discovery.full– convenience feature that enables bothproc-macroandinventory.
Quick Start
use JsonSchema;
use ;
use ;
;
With the proc-macro feature enabled you can replace the manual impl with:
If you omit the name, the macro uses the function name (add here). The summary argument is optional as well and defaults to an empty string. You can still override the name or other metadata explicitly when needed.
Development
- Formatting:
cargo fmt - Linting:
cargo clippy --all-targets -- -D warnings - Tests:
cargo test
Generating OpenRPC During Build
Enable the inventory feature and use a build.rs script to emit the OpenRPC document at compile time:
// Cargo.toml
typed-openrpc =
typed-openrpc =
// build.rs
Every build refreshes openrpc.json, keeping the spec aligned with your registered methods.
License
Licensed under the MIT License.