Open nickray opened 2 years ago
ooh, didn't know about OpenRPC document
but I like the idea.
let's investigate how hard it will be to implement.
For context there is already some guys that has implemented this on-top of jsonrpsee:
See https://github.com/MystenLabs/sui/tree/main/crates/sui-open-rpc & https://github.com/MystenLabs/sui/tree/main/crates/sui-open-rpc-macros for inspiration
I think this could accomplished feasibly in conjunction with something like schemars
. It would have to be opt-in, as it would require instrumenting types with #[derive(JsonSchema)]
, but you could have a flag in the #[rpc]
macro that, when set, uses the JsonSchema
trait to assemble an OpenRPC spec that is included when .into_rpc()
is called. It would likely need to be handled specially in RpcModule
/Methods
, as merged modules should combine their specs.
this would really be the missing piece for us
I'm trying to push forward this one, starting from looking for existing solutions. There are some implementations that do vice versa and usually are marked as "proof-of-concept" rather than a working solution (for example iamgroot
).
So, for the first step, I picked up openrpc
spec definitions from open-rpc, but after initial testing on existing examples, I ended up forking it to make it compatible.
I'll try to implement some starting point for non-generic methods and some simple schemes later using it
It would be pretty convenient if the
#[rpc]
macro could infer an OpenRPC Document and implement therpc.discover
method.