diff --git a/Cargo.lock b/Cargo.lock index d7006b4e5d..721011b56c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1251,6 +1251,16 @@ dependencies = [ "tower-http", ] +[[package]] +name = "ckb-rpc-gen" +version = "0.1.0" +dependencies = [ + "ckb-rpc", + "schemars", + "serde", + "serde_json", +] + [[package]] name = "ckb-rust-unstable-port" version = "0.112.0-pre" diff --git a/Cargo.toml b/Cargo.toml index b02a4f2080..a3d88a3047 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,6 +89,7 @@ members = [ "util/launcher/migration-template", "util/light-client-protocol-server", "util/launcher", + "devtools/doc/rpc-gen", "ckb-bin" ] diff --git a/Makefile b/Makefile index 9772536262..fe76d6e010 100644 --- a/Makefile +++ b/Makefile @@ -107,8 +107,8 @@ doc-deps: ## Build the documentation for the local package and all dependencies. .PHONY: gen-rpc-doc gen-rpc-doc: ## Generate rpc documentation - cd rpc && cargo build - ./target/debug/ckb-rpc-gen-doc rpc/README.md + cd devtools/doc/rpc-gen && cargo build + ./target/debug/ckb-rpc-gen rpc/README.md .PHONY: gen-hashes gen-hashes: ## Generate docs/hashes.toml diff --git a/devtools/doc/rpc-gen/Cargo.toml b/devtools/doc/rpc-gen/Cargo.toml new file mode 100644 index 0000000000..288127338a --- /dev/null +++ b/devtools/doc/rpc-gen/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "ckb-rpc-gen" +version = "0.1.0" +edition = "2021" + +[dependencies] +ckb-rpc ={ path = "../../../rpc", version = "= 0.112.0-pre" } +schemars = { git = "https://github.com/chenyukang/schemars", branch = "fix-derive" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "~1.0" diff --git a/rpc/src/gen_doc/gen.rs b/devtools/doc/rpc-gen/src/gen.rs similarity index 99% rename from rpc/src/gen_doc/gen.rs rename to devtools/doc/rpc-gen/src/gen.rs index fcfccef5c0..d15ca00734 100644 --- a/rpc/src/gen_doc/gen.rs +++ b/devtools/doc/rpc-gen/src/gen.rs @@ -333,7 +333,7 @@ fn gen_errors_content(res: &mut String) { /// generate subscription module, which is handled specially here /// since jsonrpc-utils ignore the `SubscriptionRpc` fn gen_subscription_rpc_doc(res: &mut String) { - let pubsub_module_source = include_str!("../module/subscription.rs"); + let pubsub_module_source = include_str!("../../../../rpc/src/module/subscription.rs"); // read comments before `pub trait SubscriptionRpc` and treat it as module summary let summary = pubsub_module_source .lines() diff --git a/rpc/src/gen_doc/main.rs b/devtools/doc/rpc-gen/src/main.rs similarity index 94% rename from rpc/src/gen_doc/main.rs rename to devtools/doc/rpc-gen/src/main.rs index c227aabd8b..37f21e85f8 100644 --- a/rpc/src/gen_doc/main.rs +++ b/devtools/doc/rpc-gen/src/main.rs @@ -26,7 +26,8 @@ fn dump_openrpc_json() -> Result<(), Box> { Ok(()) } -fn gen_rpc_readme(readme_path: &str) -> Result<(), Box> { +/// Generate rpc readme +pub fn gen_rpc_readme(readme_path: &str) -> Result<(), Box> { let all_rpc = vec![ alert_rpc_doc(), net_rpc_doc(), diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 86083e8035..9d57ef0192 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -8,10 +8,6 @@ description = "CKB RPC server." homepage = "https://github.com/nervosnetwork/ckb" repository = "https://github.com/nervosnetwork/ckb" -[[bin]] -name = "ckb-rpc-gen-doc" -path = "src/gen_doc/main.rs" - [dependencies] ckb-chain-spec = { path = "../spec", version = "= 0.112.0-pre" } ckb-types = { path = "../util/types", version = "= 0.112.0-pre" } @@ -53,7 +49,7 @@ futures-util = { version = "0.3.21" } tower-http = { version = "0.3.5", features = ["timeout"] } async-stream = "0.3.3" ckb-async-runtime = { path = "../util/runtime", version = "= 0.112.0-pre" } -schemars = { git = "https://github.com/chenyukang/schemars", branch = "fix-derive"} +schemars = { git = "https://github.com/chenyukang/schemars", branch = "fix-derive" } #schemars = "0.8.15" [dev-dependencies] diff --git a/rpc/src/module/alert.rs b/rpc/src/module/alert.rs index 7e0def8f04..0d1d150343 100644 --- a/rpc/src/module/alert.rs +++ b/rpc/src/module/alert.rs @@ -57,7 +57,7 @@ pub trait AlertRpc { /// /// Response /// - /// ```json + /// ```json /// { /// "error": { /// "code": -1000,