WIP: Add support for generating rpc.discover
method
#1608
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR implements optional generation of
rpc.discover
method which returns OpenRPC specification from trait definition. For thatopen-rpc
crate was forked to fix compatibility issues with official examples and to add some useful conversion functions (about that a little bit later).This works by using
utoipa::schema!
andutoipa::ToSchema
crate macros, that generateutoipa::openapi::Schema
structure at runtime, which later converted toopen_rpc::Schema
and, with information from server trait definition, toopen_rpc::ContentDescriptor
.With these information about each trait method,
open_rpc::OpenRpc
structure is constructed insiderpc.discover
method at runtime. For now it's constructed on eachrpc.discover
call, but this can be improved by adding some lazy static variable.Functionality
For example, you can take a look at
examples/examples/rpc_discover.rs
, run it:then send request to server:
Response
copy response, and introspect it, for example, using OpenRPC Playground.