Skip to content

Commit 5b435d1

Browse files
Frandolink2xt
authored andcommitted
feat(jsonrpc): generate OpenRPC definitions
When running `cargo test` in the deltachat-jsonrpc folder, a new file `openrpc/openrpc.json` will be created with an [OpenRPC](https://spec.open-rpc.org/) definition. It can be copy-pasted into the [OpenRPC playground](https://playground.open-rpc.org/) and used to generate clients in other languages.
1 parent b9b0d20 commit 5b435d1

File tree

17 files changed

+88
-38
lines changed

17 files changed

+88
-38
lines changed

Cargo.lock

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

deltachat-ffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ anyhow = "1"
2525
thiserror = "1"
2626
rand = "0.8"
2727
once_cell = "1.17.0"
28-
yerpc = { version = "0.4.4", features = ["anyhow_expose"] }
28+
yerpc = { version = "0.5.1", features = ["anyhow_expose"] }
2929

3030
[features]
3131
default = ["vendored"]

deltachat-jsonrpc/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ required-features = ["webserver"]
1515
anyhow = "1"
1616
deltachat = { path = ".." }
1717
num-traits = "0.2"
18+
schemars = "0.8.11"
1819
serde = { version = "1.0", features = ["derive"] }
1920
tempfile = "3.3.0"
2021
log = "0.4"
2122
async-channel = { version = "1.8.0" }
2223
futures = { version = "0.3.28" }
2324
serde_json = "1.0.96"
24-
yerpc = { version = "0.4.4", features = ["anyhow_expose"] }
25+
yerpc = { version = "0.5.1", features = ["anyhow_expose", "openrpc"] }
2526
typescript-type-def = { version = "0.5.5", features = ["json_value"] }
2627
tokio = { version = "1.28.0" }
2728
sanitize-filename = "0.4"

deltachat-jsonrpc/src/api/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ impl CommandApi {
144144
}
145145
}
146146

147-
#[rpc(all_positional, ts_outdir = "typescript/generated")]
147+
#[rpc(
148+
all_positional,
149+
ts_outdir = "typescript/generated",
150+
openrpc_outdir = "openrpc"
151+
)]
148152
impl CommandApi {
149153
/// Test function.
150154
async fn sleep(&self, delay: f64) {

deltachat-jsonrpc/src/api/types/account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use typescript_type_def::TypeDef;
66

77
use super::color_int_to_hex_string;
88

9-
#[derive(Serialize, TypeDef)]
9+
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
1010
#[serde(tag = "type")]
1111
pub enum Account {
1212
#[serde(rename_all = "camelCase")]

deltachat-jsonrpc/src/api/types/chat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use typescript_type_def::TypeDef;
1313
use super::color_int_to_hex_string;
1414
use super::contact::ContactObject;
1515

16-
#[derive(Serialize, TypeDef)]
16+
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
1717
#[serde(rename_all = "camelCase")]
1818
pub struct FullChat {
1919
id: u32,
@@ -121,7 +121,7 @@ impl FullChat {
121121
/// - can_send
122122
///
123123
/// used when you only need the basic metadata of a chat like type, name, profile picture
124-
#[derive(Serialize, TypeDef)]
124+
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
125125
#[serde(rename_all = "camelCase")]
126126
pub struct BasicChat {
127127
id: u32,
@@ -166,7 +166,7 @@ impl BasicChat {
166166
}
167167
}
168168

169-
#[derive(Clone, Serialize, Deserialize, TypeDef)]
169+
#[derive(Clone, Serialize, Deserialize, TypeDef, schemars::JsonSchema)]
170170
pub enum MuteDuration {
171171
NotMuted,
172172
Forever,
@@ -191,7 +191,7 @@ impl MuteDuration {
191191
}
192192
}
193193

194-
#[derive(Clone, Serialize, Deserialize, TypeDef)]
194+
#[derive(Clone, Serialize, Deserialize, TypeDef, schemars::JsonSchema)]
195195
#[serde(rename = "ChatVisibility")]
196196
pub enum JSONRPCChatVisibility {
197197
Normal,

deltachat-jsonrpc/src/api/types/chat_list.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ use deltachat::{
88
chatlist::Chatlist,
99
};
1010
use num_traits::cast::ToPrimitive;
11-
use serde::Serialize;
11+
use serde::{Deserialize, Serialize};
1212
use typescript_type_def::TypeDef;
1313

1414
use super::color_int_to_hex_string;
1515
use super::message::MessageViewtype;
1616

17-
#[derive(Serialize, TypeDef)]
17+
#[derive(Deserialize, Serialize, TypeDef, schemars::JsonSchema)]
18+
pub struct ChatListEntry(pub u32, pub u32);
19+
20+
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
1821
#[serde(tag = "type")]
1922
pub enum ChatListItemFetchResult {
2023
#[serde(rename_all = "camelCase")]

deltachat-jsonrpc/src/api/types/contact.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use typescript_type_def::TypeDef;
66

77
use super::color_int_to_hex_string;
88

9-
#[derive(Serialize, TypeDef)]
9+
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
1010
#[serde(rename = "Contact", rename_all = "camelCase")]
1111
pub struct ContactObject {
1212
address: String,

deltachat-jsonrpc/src/api/types/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use deltachat::{Event as CoreEvent, EventType as CoreEventType};
22
use serde::Serialize;
33
use typescript_type_def::TypeDef;
44

5-
#[derive(Serialize, TypeDef)]
5+
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
66
#[serde(rename_all = "camelCase")]
77
pub struct Event {
88
/// Event payload.
@@ -21,7 +21,7 @@ impl From<CoreEvent> for Event {
2121
}
2222
}
2323

24-
#[derive(Serialize, TypeDef)]
24+
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
2525
#[serde(tag = "type")]
2626
pub enum EventType {
2727
/// The library-user may write an informational string to the log.

deltachat-jsonrpc/src/api/types/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use deltachat::net::HttpResponse as CoreHttpResponse;
22
use serde::Serialize;
33
use typescript_type_def::TypeDef;
44

5-
#[derive(Serialize, TypeDef)]
5+
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
66
pub struct HttpResponse {
77
/// base64-encoded response body.
88
blob: String,

0 commit comments

Comments
 (0)