extract utoipa config into utoipa.rs
This commit is contained in:
parent
ca1d9db2cc
commit
454c40e310
3 changed files with 66 additions and 65 deletions
|
@ -67,10 +67,3 @@ impl MessageResponse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, ToSchema)]
|
|
||||||
pub struct ApiErrorResponse {
|
|
||||||
/// Error message
|
|
||||||
pub error: String,
|
|
||||||
/// HTTP status code
|
|
||||||
pub status: u16,
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,12 +2,12 @@ use actix_session::{SessionMiddleware, storage::RedisSessionStore};
|
||||||
use actix_web::cookie::SameSite;
|
use actix_web::cookie::SameSite;
|
||||||
use actix_web::{App, HttpServer, cookie::Key, middleware::Logger, web};
|
use actix_web::{App, HttpServer, cookie::Key, middleware::Logger, web};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use utoipa::OpenApi;
|
|
||||||
use utoipa_swagger_ui::SwaggerUi;
|
use utoipa_swagger_ui::SwaggerUi;
|
||||||
|
|
||||||
mod controller;
|
mod controller;
|
||||||
mod db;
|
mod db;
|
||||||
mod error;
|
mod error;
|
||||||
|
mod utoipa;
|
||||||
|
|
||||||
pub use db::Database;
|
pub use db::Database;
|
||||||
pub use db::entity;
|
pub use db::entity;
|
||||||
|
@ -20,62 +20,6 @@ struct AppConfig {
|
||||||
ldap_auth: bool,
|
ldap_auth: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(OpenApi)]
|
|
||||||
#[openapi(
|
|
||||||
info(
|
|
||||||
title = "PGG API",
|
|
||||||
description = "API for the PGG (Peer Group Grading) application",
|
|
||||||
version = "0.0.1-rc1",
|
|
||||||
),
|
|
||||||
paths(
|
|
||||||
controller::auth::login,
|
|
||||||
controller::auth::logout,
|
|
||||||
controller::project::get_projects,
|
|
||||||
controller::project::get_project,
|
|
||||||
controller::project::create_project,
|
|
||||||
controller::project::update_project,
|
|
||||||
controller::project::delete_project,
|
|
||||||
controller::user::get_users,
|
|
||||||
controller::user::get_user,
|
|
||||||
controller::user::create_user,
|
|
||||||
controller::user::update_user,
|
|
||||||
controller::user::delete_user,
|
|
||||||
controller::group::get_groups,
|
|
||||||
controller::group::get_groups_for_project,
|
|
||||||
controller::group::create_group,
|
|
||||||
controller::group::update_group,
|
|
||||||
controller::group::delete_group,
|
|
||||||
controller::class::get_classes,
|
|
||||||
controller::class::get_class,
|
|
||||||
controller::class::create_class,
|
|
||||||
controller::class::update_class,
|
|
||||||
controller::class::delete_class,
|
|
||||||
controller::template::get_templates,
|
|
||||||
controller::template::get_template,
|
|
||||||
controller::template::create_template,
|
|
||||||
controller::template::update_template,
|
|
||||||
controller::template::delete_template,
|
|
||||||
),
|
|
||||||
components(schemas(
|
|
||||||
controller::auth::LoginRequest,
|
|
||||||
error::MessageResponse,
|
|
||||||
error::ApiErrorResponse,
|
|
||||||
db::project::CreateProject,
|
|
||||||
controller::user::CreateUser,
|
|
||||||
entity::project::Model,
|
|
||||||
entity::user::Model,
|
|
||||||
)),
|
|
||||||
tags(
|
|
||||||
(name = "auth", description = "Authentication endpoints"),
|
|
||||||
(name = "users", description = "User management endpoints"),
|
|
||||||
(name = "projects", description = "Project management endpoints"),
|
|
||||||
(name = "groups", description = "Group management endpoints (Not Implemented)"),
|
|
||||||
(name = "classes", description = "Class management endpoints (Not Implemented)"),
|
|
||||||
(name = "templates", description = "Template management endpoints (Not Implemented)"),
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
struct ApiDoc;
|
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
dotenvy::dotenv().ok();
|
dotenvy::dotenv().ok();
|
||||||
|
@ -118,7 +62,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
.service(web::scope("/api/v1").configure(controller::register_controllers))
|
.service(web::scope("/api/v1").configure(controller::register_controllers))
|
||||||
.service(
|
.service(
|
||||||
SwaggerUi::new("/swagger-ui/{_:.*}")
|
SwaggerUi::new("/swagger-ui/{_:.*}")
|
||||||
.url("/api-docs/openapi.json", ApiDoc::openapi()),
|
.url("/api-docs/openapi.json", crate::utoipa::ApiDoc::openapi_spec()),
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "serve")]
|
#[cfg(feature = "serve")]
|
||||||
|
|
64
crates/backend/src/utoipa.rs
Normal file
64
crates/backend/src/utoipa.rs
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
use utoipa::OpenApi;
|
||||||
|
|
||||||
|
use crate::{controller, db, entity, error};
|
||||||
|
|
||||||
|
#[derive(OpenApi)]
|
||||||
|
#[openapi(
|
||||||
|
info(
|
||||||
|
title = "PGG API",
|
||||||
|
description = "API for the PGG (Peer Group Grading) application",
|
||||||
|
version = "0.0.1-rc1",
|
||||||
|
),
|
||||||
|
paths(
|
||||||
|
controller::auth::login,
|
||||||
|
controller::auth::logout,
|
||||||
|
controller::project::get_projects,
|
||||||
|
controller::project::get_project,
|
||||||
|
controller::project::create_project,
|
||||||
|
controller::project::update_project,
|
||||||
|
controller::project::delete_project,
|
||||||
|
controller::user::get_users,
|
||||||
|
controller::user::get_user,
|
||||||
|
controller::user::create_user,
|
||||||
|
controller::user::update_user,
|
||||||
|
controller::user::delete_user,
|
||||||
|
controller::group::get_groups,
|
||||||
|
controller::group::get_groups_for_project,
|
||||||
|
controller::group::create_group,
|
||||||
|
controller::group::update_group,
|
||||||
|
controller::group::delete_group,
|
||||||
|
controller::class::get_classes,
|
||||||
|
controller::class::get_class,
|
||||||
|
controller::class::create_class,
|
||||||
|
controller::class::update_class,
|
||||||
|
controller::class::delete_class,
|
||||||
|
controller::template::get_templates,
|
||||||
|
controller::template::get_template,
|
||||||
|
controller::template::create_template,
|
||||||
|
controller::template::update_template,
|
||||||
|
controller::template::delete_template,
|
||||||
|
),
|
||||||
|
components(schemas(
|
||||||
|
controller::auth::LoginRequest,
|
||||||
|
error::MessageResponse,
|
||||||
|
db::project::CreateProject,
|
||||||
|
controller::user::CreateUser,
|
||||||
|
entity::project::Model,
|
||||||
|
entity::user::Model,
|
||||||
|
)),
|
||||||
|
tags(
|
||||||
|
(name = "auth", description = "Authentication endpoints"),
|
||||||
|
(name = "users", description = "User management endpoints"),
|
||||||
|
(name = "projects", description = "Project management endpoints"),
|
||||||
|
(name = "groups", description = "Group management endpoints (Not Implemented)"),
|
||||||
|
(name = "classes", description = "Class management endpoints (Not Implemented)"),
|
||||||
|
(name = "templates", description = "Template management endpoints (Not Implemented)"),
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub struct ApiDoc;
|
||||||
|
|
||||||
|
impl ApiDoc {
|
||||||
|
pub fn openapi_spec() -> utoipa::openapi::OpenApi {
|
||||||
|
Self::openapi()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue