Skip to content

Commit 9883a75

Browse files
0xterminatorpedronauck
authored andcommitted
feat(repo): Added open-api documentation (#428)
* feat(repo): Added rest endpoints Postman documentation * feat(repo): Added open-api documentation
1 parent 461c506 commit 9883a75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1808
-67
lines changed

Cargo.lock

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

crates/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ serde_json.workspace = true
3030
thiserror.workspace = true
3131
tokio.workspace = true
3232
tracing.workspace = true
33+
utoipa = { version = "5.3.1", features = ["actix_extras"] }
3334

3435
[dev-dependencies]
3536
pretty_assertions.workspace = true

crates/core/src/server/responses.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,34 @@ pub enum MessagePayload {
4646
Utxo(Arc<Utxo>),
4747
}
4848

49+
impl utoipa::ToSchema for MessagePayload {
50+
fn name() -> std::borrow::Cow<'static, str> {
51+
std::borrow::Cow::Borrowed("MessagePayload")
52+
}
53+
}
54+
55+
impl utoipa::PartialSchema for MessagePayload {
56+
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
57+
// Create a oneOf schema
58+
let mut one_of = utoipa::openapi::schema::OneOf::new();
59+
60+
// Add references to all possible payload types
61+
// We can use the schema() method directly from each type
62+
one_of.items.push(Block::schema());
63+
one_of.items.push(Input::schema());
64+
one_of.items.push(Output::schema());
65+
one_of.items.push(Transaction::schema());
66+
one_of.items.push(Receipt::schema());
67+
one_of.items.push(Utxo::schema());
68+
69+
// Build the oneOf schema with a description
70+
let schema = utoipa::openapi::schema::Schema::OneOf(one_of);
71+
72+
// Return the schema wrapped in RefOr::T
73+
utoipa::openapi::RefOr::T(schema)
74+
}
75+
}
76+
4977
impl MessagePayload {
5078
pub fn new(
5179
subject_id: &str,
@@ -133,7 +161,7 @@ pub enum StreamResponseError {
133161
RecordPacket(#[from] RecordPacketError),
134162
}
135163

136-
#[derive(Debug, Clone, Serialize, Deserialize)]
164+
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
137165
pub struct StreamResponse {
138166
pub version: String,
139167
#[serde(rename = "type")]

crates/domains/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ serde_with = "3.12.0"
3030
sqlx.workspace = true
3131
thiserror.workspace = true
3232
tokio.workspace = true
33+
utoipa = { version = "5.3.1", features = ["actix_extras"] }
3334

3435
[dev-dependencies]
3536
pretty_assertions.workspace = true

crates/domains/src/blocks/queryable.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ use serde::{Deserialize, Serialize};
1212
use super::{types::*, BlockDbItem};
1313
use crate::queryable::{HasPagination, QueryPagination, Queryable};
1414

15-
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
15+
#[derive(
16+
Debug,
17+
Default,
18+
Clone,
19+
Serialize,
20+
Deserialize,
21+
PartialEq,
22+
Eq,
23+
utoipa::ToSchema,
24+
)]
1625
pub enum TimeRange {
1726
#[serde(rename = "1h")]
1827
OneHour,
@@ -121,7 +130,16 @@ pub enum Blocks {
121130
BlockPropagationMs,
122131
}
123132

124-
#[derive(Debug, Clone, Default, Serialize, Deserialize, Eq, PartialEq)]
133+
#[derive(
134+
Debug,
135+
Clone,
136+
Default,
137+
Serialize,
138+
Deserialize,
139+
Eq,
140+
PartialEq,
141+
utoipa::ToSchema,
142+
)]
125143
#[serde(rename_all = "camelCase")]
126144
pub struct BlocksQuery {
127145
pub producer: Option<Address>,

0 commit comments

Comments
 (0)