Skip to content

Commit

Permalink
feat(repo): Added open-api documentation (#428)
Browse files Browse the repository at this point in the history
* feat(repo): Added rest endpoints Postman documentation

* feat(repo): Added open-api documentation
  • Loading branch information
0xterminator authored and pedronauck committed Mar 11, 2025
1 parent 461c506 commit 9883a75
Show file tree
Hide file tree
Showing 50 changed files with 1,808 additions and 67 deletions.
155 changes: 155 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ serde_json.workspace = true
thiserror.workspace = true
tokio.workspace = true
tracing.workspace = true
utoipa = { version = "5.3.1", features = ["actix_extras"] }

[dev-dependencies]
pretty_assertions.workspace = true
Expand Down
30 changes: 29 additions & 1 deletion crates/core/src/server/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@ pub enum MessagePayload {
Utxo(Arc<Utxo>),
}

impl utoipa::ToSchema for MessagePayload {
fn name() -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("MessagePayload")
}
}

impl utoipa::PartialSchema for MessagePayload {
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
// Create a oneOf schema
let mut one_of = utoipa::openapi::schema::OneOf::new();

// Add references to all possible payload types
// We can use the schema() method directly from each type
one_of.items.push(Block::schema());
one_of.items.push(Input::schema());
one_of.items.push(Output::schema());
one_of.items.push(Transaction::schema());
one_of.items.push(Receipt::schema());
one_of.items.push(Utxo::schema());

// Build the oneOf schema with a description
let schema = utoipa::openapi::schema::Schema::OneOf(one_of);

// Return the schema wrapped in RefOr::T
utoipa::openapi::RefOr::T(schema)
}
}

impl MessagePayload {
pub fn new(
subject_id: &str,
Expand Down Expand Up @@ -133,7 +161,7 @@ pub enum StreamResponseError {
RecordPacket(#[from] RecordPacketError),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct StreamResponse {
pub version: String,
#[serde(rename = "type")]
Expand Down
1 change: 1 addition & 0 deletions crates/domains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ serde_with = "3.12.0"
sqlx.workspace = true
thiserror.workspace = true
tokio.workspace = true
utoipa = { version = "5.3.1", features = ["actix_extras"] }

[dev-dependencies]
pretty_assertions.workspace = true
Expand Down
22 changes: 20 additions & 2 deletions crates/domains/src/blocks/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ use serde::{Deserialize, Serialize};
use super::{types::*, BlockDbItem};
use crate::queryable::{HasPagination, QueryPagination, Queryable};

#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[derive(
Debug,
Default,
Clone,
Serialize,
Deserialize,
PartialEq,
Eq,
utoipa::ToSchema,
)]
pub enum TimeRange {
#[serde(rename = "1h")]
OneHour,
Expand Down Expand Up @@ -121,7 +130,16 @@ pub enum Blocks {
BlockPropagationMs,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize, Eq, PartialEq)]
#[derive(
Debug,
Clone,
Default,
Serialize,
Deserialize,
Eq,
PartialEq,
utoipa::ToSchema,
)]
#[serde(rename_all = "camelCase")]
pub struct BlocksQuery {
pub producer: Option<Address>,
Expand Down
Loading

0 comments on commit 9883a75

Please sign in to comment.