paritytech / jsonrpsee

Rust JSON-RPC library on top of async/await
MIT License
619 stars 166 forks source link

Automagically generate `rpc.discover` method? #737

Open nickray opened 2 years ago

nickray commented 2 years ago

It would be pretty convenient if the #[rpc] macro could infer an OpenRPC Document and implement the rpc.discover method.

niklasad1 commented 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.

niklasad1 commented 2 years ago

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

tjjfvi commented 2 years ago

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.

v-morlock commented 6 months ago

this would really be the missing piece for us

Velnbur commented 1 month ago

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