diff --git a/backend/aide b/backend/aide new file mode 160000 index 00000000..2bad9abd --- /dev/null +++ b/backend/aide @@ -0,0 +1 @@ +Subproject commit 2bad9abdfe84639fc9138384b322d8fda22fc35a diff --git a/backend/server/Cargo.toml b/backend/server/Cargo.toml index e348b09c..058b58e0 100644 --- a/backend/server/Cargo.toml +++ b/backend/server/Cargo.toml @@ -26,6 +26,8 @@ rust-s3 = "0.34.0" rs-snowflake = "0.6" jsonwebtoken = "9.1" dotenvy = "0.15" -aide = { version = "0.13.4", features = ["axum", "macros"]} +#aide = { version = "0.13.4", features = ["axum", "macros", "http"]} +aide = { path="../aide/crates/aide", features = ["axum", "macros", "http"]} +aide-macros = { path="../aide/crates/aide-macros"} +axum-jsonschema = { path="../aide/crates/axum-jsonschema"} schemars = {version = "0.8.21", features = ["chrono"]} - diff --git a/backend/server/src/handler/organisation.rs b/backend/server/src/handler/organisation.rs index 88fbf106..0c4a7fe4 100644 --- a/backend/server/src/handler/organisation.rs +++ b/backend/server/src/handler/organisation.rs @@ -8,8 +8,7 @@ use crate::models::transaction::DBTransaction; use crate::service; use axum::extract::{Json, Path, State}; use axum::http::StatusCode; -use axum::response::IntoResponse; -use aide::OperationOutput; +//use http::status::StatusCode; use aide::axum::IntoApiResponse; pub struct OrganisationHandler; diff --git a/backend/server/src/main.rs b/backend/server/src/main.rs index ca061611..f5b20afd 100644 --- a/backend/server/src/main.rs +++ b/backend/server/src/main.rs @@ -10,6 +10,7 @@ use sqlx::postgres::PgPoolOptions; use std::env; use axum::Json; +use aide::OperationOutput; use aide::{ axum::{ routing::{get, post, patch, put}, diff --git a/backend/server/src/models/error.rs b/backend/server/src/models/error.rs index 8fa33d98..65836b4c 100644 --- a/backend/server/src/models/error.rs +++ b/backend/server/src/models/error.rs @@ -1,13 +1,18 @@ use axum::http::StatusCode; use axum::response::{IntoResponse, Redirect, Response}; -use aide::OperationIo; +use aide::{OperationIo, OperationOutput, + gen, + openapi::Operation, +}; +use schemars::JsonSchema; /// Custom error enum for Chaos. /// /// Handles all errors thrown by libraries (when `?` is used) alongside /// specific errors for business logic. -#[derive(thiserror::Error, Debug, OperationIo)] -#[aide(output)] +//#[derive(thiserror::Error, Debug, OperationIo)] +//#[aide(output)] +#[derive(thiserror::Error, Debug)] pub enum ChaosError { #[error("Not logged in")] NotLoggedIn, @@ -59,3 +64,19 @@ impl IntoResponse for ChaosError { } } } + +impl OperationOutput for ChaosError { + type Inner = Self; + + fn inferred_responses( + ctx: &mut gen::GenContext, + operation: &mut Operation, + ) -> Vec<(Option, aide::openapi::Response)> { + Vec::from([ + (Some(400), Default::default()), // Bad request + (Some(401), Default::default()), // Unauthorized + (Some(403), Default::default()), // Forbidden + (Some(500), Default::default()), // Internal Server Error + ]) + } +} diff --git a/backend/server/src/models/organisation.rs b/backend/server/src/models/organisation.rs index 618e7381..944918f6 100644 --- a/backend/server/src/models/organisation.rs +++ b/backend/server/src/models/organisation.rs @@ -29,7 +29,7 @@ pub struct NewOrganisation { } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, JsonSchema)] pub struct OrganisationDetails { pub id: i64, pub name: String, @@ -37,21 +37,21 @@ pub struct OrganisationDetails { pub created_at: DateTime, } -#[derive(Deserialize, Serialize, sqlx::Type, Clone)] +#[derive(Deserialize, Serialize, sqlx::Type, Clone, JsonSchema)] #[sqlx(type_name = "organisation_role", rename_all = "PascalCase")] pub enum OrganisationRole { User, Admin, } -#[derive(Deserialize, Serialize, FromRow)] +#[derive(Deserialize, Serialize, FromRow, JsonSchema)] pub struct Member { pub id: i64, pub name: String, pub role: OrganisationRole, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, OperationIo, JsonSchema)] pub struct MemberList { pub members: Vec, }