Skip to content

Commit 6c7007f

Browse files
committed
Automatically generate RPC docs, bump version number for release
1 parent 557117b commit 6c7007f

File tree

14 files changed

+590
-37
lines changed

14 files changed

+590
-37
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ members = [
1010
[workspace.package]
1111
authors = [ "Ash Manning <[email protected]>" ]
1212
edition = "2021"
13-
version = "0.7.7"
13+
version = "0.7.8"
1414

1515
[workspace.dependencies.bip300301]
1616
git = "https://github.com/Ash-L2L/bip300301.git"

app/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ tokio-util = { version = "0.7.10", features = ["rt"] }
4444
tracing = "0.1.40"
4545
tracing-appender = "0.2.3"
4646
tracing-subscriber = "0.3.18"
47+
utoipa = "4.2.3"
4748

4849
[dependencies.libes]
4950
version = "0.9.1"

app/rpc_server.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ impl RpcServer for RpcServerImpl {
193193
Ok(utxos)
194194
}
195195

196+
async fn openapi_schema(&self) -> RpcResult<utoipa::openapi::OpenApi> {
197+
let res =
198+
<plain_bitnames_app_rpc_api::RpcDoc as utoipa::OpenApi>::openapi();
199+
Ok(res)
200+
}
201+
196202
async fn reserve_bitname(&self, plain_name: String) -> RpcResult<Txid> {
197203
let mut tx = Transaction::default();
198204
let () = match self.app.wallet.reserve_bitname(&mut tx, &plain_name) {

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ plain_bitnames = { path = "../lib" }
1313
plain_bitnames_app_rpc_api = { path = "../rpc-api" }
1414
serde_json = "1.0.113"
1515
tokio = "1.29.1"
16+
utoipa = "4.2.3"
1617

1718
[lib]
1819
name = "plain_bitnames_app_cli_lib"

cli/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ pub enum Command {
4343
},
4444
/// List owned UTXOs
4545
MyUtxos,
46+
/// Show OpenAPI schema
47+
#[command(name = "openapi-schema")]
48+
OpenApiSchema,
4649
/// Reserve a BitName
4750
ReserveBitname { plaintext_name: String },
4851
/// Set the wallet seed from a mnemonic seed phrase
@@ -144,6 +147,11 @@ impl Cli {
144147
let utxos = rpc_client.my_utxos().await?;
145148
serde_json::to_string_pretty(&utxos)?
146149
}
150+
Command::OpenApiSchema => {
151+
let openapi =
152+
<plain_bitnames_app_rpc_api::RpcDoc as utoipa::OpenApi>::openapi();
153+
openapi.to_pretty_json()?
154+
}
147155
Command::ReserveBitname { plaintext_name } => {
148156
let txid = rpc_client.reserve_bitname(plaintext_name).await?;
149157
format!("{txid}")

lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ tokio = { version = "1.29.1", features = ["rt-multi-thread", "sync"] }
4242
tokio-stream = { version = "0.1.15", features = ["sync"] }
4343
tokio-util = { version = "0.7.10", features = ["rt"] }
4444
tracing = "0.1.40"
45+
utoipa = "4.2.3"
4546
x25519-dalek = { version = "2.0.0", features = ["serde"] }
4647

4748
[target.'cfg(not(target_os = "windows"))'.dependencies.async_zmq]

lib/authorization.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use borsh::BorshSerialize;
22
use rayon::iter::{IntoParallelRefIterator as _, ParallelIterator as _};
33
use serde::{Deserialize, Serialize};
4+
use utoipa::ToSchema;
45

56
use crate::types::{
67
Address, AuthorizedTransaction, Body, GetAddress, Transaction, Verify,
@@ -49,12 +50,21 @@ where
4950
}
5051

5152
#[derive(
52-
BorshSerialize, Debug, Clone, Deserialize, Eq, PartialEq, Serialize,
53+
BorshSerialize,
54+
Debug,
55+
Clone,
56+
Deserialize,
57+
Eq,
58+
PartialEq,
59+
Serialize,
60+
ToSchema,
5361
)]
5462
pub struct Authorization {
5563
#[borsh(serialize_with = "borsh_serialize_verifying_key")]
64+
#[schema(schema_with = <String as utoipa::PartialSchema>::schema)]
5665
pub verifying_key: VerifyingKey,
5766
#[borsh(serialize_with = "borsh_serialize_signature")]
67+
#[schema(schema_with = <String as utoipa::PartialSchema>::schema)]
5868
pub signature: Signature,
5969
}
6070

lib/types/address.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,21 @@ impl Serialize for Address {
7979
}
8080
}
8181
}
82+
83+
impl utoipa::PartialSchema for Address {
84+
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
85+
let obj = utoipa::openapi::Object::with_type(
86+
utoipa::openapi::SchemaType::String,
87+
);
88+
utoipa::openapi::RefOr::T(utoipa::openapi::Schema::Object(obj))
89+
}
90+
}
91+
92+
impl utoipa::ToSchema<'static> for Address {
93+
fn schema() -> (
94+
&'static str,
95+
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
96+
) {
97+
("Address", <Address as utoipa::PartialSchema>::schema())
98+
}
99+
}

lib/types/hashes.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ impl FromStr for BlockHash {
7979
}
8080
}
8181

82+
impl utoipa::PartialSchema for BlockHash {
83+
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
84+
let obj = utoipa::openapi::Object::with_type(
85+
utoipa::openapi::SchemaType::String,
86+
);
87+
utoipa::openapi::RefOr::T(utoipa::openapi::Schema::Object(obj))
88+
}
89+
}
90+
91+
impl utoipa::ToSchema<'static> for BlockHash {
92+
fn schema() -> (
93+
&'static str,
94+
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
95+
) {
96+
("BlockHash", <Self as utoipa::PartialSchema>::schema())
97+
}
98+
}
99+
82100
#[derive(
83101
BorshSerialize,
84102
Clone,
@@ -120,6 +138,24 @@ impl std::fmt::Debug for MerkleRoot {
120138
}
121139
}
122140

141+
impl utoipa::PartialSchema for MerkleRoot {
142+
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
143+
let obj = utoipa::openapi::Object::with_type(
144+
utoipa::openapi::SchemaType::String,
145+
);
146+
utoipa::openapi::RefOr::T(utoipa::openapi::Schema::Object(obj))
147+
}
148+
}
149+
150+
impl utoipa::ToSchema<'static> for MerkleRoot {
151+
fn schema() -> (
152+
&'static str,
153+
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
154+
) {
155+
("MerkleRoot", <Self as utoipa::PartialSchema>::schema())
156+
}
157+
}
158+
123159
#[derive(
124160
BorshSerialize,
125161
Clone,
@@ -180,6 +216,24 @@ impl FromStr for Txid {
180216
}
181217
}
182218

219+
impl utoipa::PartialSchema for Txid {
220+
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
221+
let obj = utoipa::openapi::Object::with_type(
222+
utoipa::openapi::SchemaType::String,
223+
);
224+
utoipa::openapi::RefOr::T(utoipa::openapi::Schema::Object(obj))
225+
}
226+
}
227+
228+
impl utoipa::ToSchema<'static> for Txid {
229+
fn schema() -> (
230+
&'static str,
231+
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
232+
) {
233+
("Txid", <Self as utoipa::PartialSchema>::schema())
234+
}
235+
}
236+
183237
/// Identifier for a BitName
184238
#[derive(
185239
BorshDeserialize,
@@ -213,6 +267,24 @@ impl FromHex for BitName {
213267
}
214268
}
215269

270+
impl utoipa::PartialSchema for BitName {
271+
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
272+
let obj = utoipa::openapi::Object::with_type(
273+
utoipa::openapi::SchemaType::String,
274+
);
275+
utoipa::openapi::RefOr::T(utoipa::openapi::Schema::Object(obj))
276+
}
277+
}
278+
279+
impl utoipa::ToSchema<'static> for BitName {
280+
fn schema() -> (
281+
&'static str,
282+
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
283+
) {
284+
("BitName", <Self as utoipa::PartialSchema>::schema())
285+
}
286+
}
287+
216288
pub fn hash<T>(data: &T) -> Hash
217289
where
218290
T: BorshSerialize,

0 commit comments

Comments
 (0)