Skip to content

Commit 24da539

Browse files
committed
feat(deltachat-rpc-server): add --openrpc option
1 parent 8eee389 commit 24da539

File tree

7 files changed

+28
-11
lines changed

7 files changed

+28
-11
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deltachat-jsonrpc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ log = "0.4"
2222
async-channel = { version = "1.8.0" }
2323
futures = { version = "0.3.28" }
2424
serde_json = "1.0.99"
25-
yerpc = { version = "0.5.1", features = ["anyhow_expose", "openrpc"] }
25+
yerpc = { version = "0.5.2", features = ["anyhow_expose", "openrpc"] }
2626
typescript-type-def = { version = "0.5.5", features = ["json_value"] }
2727
tokio = { version = "1.29.1" }
2828
sanitize-filename = "0.4"

deltachat-jsonrpc/src/api/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,7 @@ impl CommandApi {
142142
}
143143
}
144144

145-
#[rpc(
146-
all_positional,
147-
ts_outdir = "typescript/generated",
148-
openrpc_outdir = "openrpc"
149-
)]
145+
#[rpc(all_positional, ts_outdir = "typescript/generated")]
150146
impl CommandApi {
151147
/// Test function.
152148
async fn sleep(&self, delay: f64) {

deltachat-rpc-client/tests/test_something.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import asyncio
2+
import json
3+
import subprocess
24
from unittest.mock import MagicMock
35

46
import pytest
@@ -355,3 +357,12 @@ async def test_import_export(acfactory, tmp_path) -> None:
355357
files = list(tmp_path.glob("*.tar"))
356358
alice2 = await acfactory.get_unconfigured_account()
357359
await alice2.import_backup(files[0])
360+
361+
362+
@pytest.test()
363+
def test_openrpc_command_line() -> None:
364+
"""Test that "deltachat-rpc-server --openrpc" command returns an OpenRPC specification."""
365+
out = subprocess.run(["deltachat-rpc-server", "--openrpc"], capture_output=True).stdout
366+
openrpc = json.loads(out)
367+
assert "openrpc" in openrpc
368+
assert "methods" in openrpc

deltachat-rpc-server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ serde_json = "1.0.99"
2121
serde = { version = "1.0", features = ["derive"] }
2222
tokio = { version = "1.29.1", features = ["io-std"] }
2323
tokio-util = "0.7.8"
24-
yerpc = { version = "0.5.1", features = ["anyhow_expose"] }
24+
yerpc = { version = "0.5.2", features = ["anyhow_expose", "openrpc"] }
2525

2626
[features]
2727
default = ["vendored"]

deltachat-rpc-server/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ languages other than Rust, for example:
3232

3333
1. Python: https://github.com/deltachat/deltachat-core-rust/tree/master/deltachat-rpc-client/
3434
2. Go: https://github.com/deltachat/deltachat-rpc-client-go/
35+
36+
Run `deltachat-rpc-server --version` to check the version of the server.
37+
Run `deltachat-rpc-server --openrpc` to get [OpenRPC](https://open-rpc.org/) specification of the provided JSON-RPC API.

deltachat-rpc-server/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use deltachat::constants::DC_VERSION_STR;
1010
use deltachat_jsonrpc::api::{Accounts, CommandApi};
1111
use futures_lite::stream::StreamExt;
1212
use tokio::io::{self, AsyncBufReadExt, BufReader};
13+
use yerpc::RpcServer as _;
1314

1415
#[cfg(target_family = "unix")]
1516
use tokio::signal::unix as signal_unix;
@@ -39,6 +40,12 @@ async fn main_impl() -> Result<()> {
3940
}
4041
eprintln!("{}", &*DC_VERSION_STR);
4142
return Ok(());
43+
} else if first_arg.to_str() == Some("--openrpc") {
44+
if let Some(arg) = args.next() {
45+
return Err(anyhow!("Unrecognized argument {:?}", arg));
46+
}
47+
println!("{}", CommandApi::openrpc_specification()?);
48+
return Ok(());
4249
} else {
4350
return Err(anyhow!("Unrecognized option {:?}", first_arg));
4451
}

0 commit comments

Comments
 (0)