diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-26 19:11:24 +0100 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-26 19:11:24 +0100 |
commit | c622eab39ac7dd9f794b5d60eb937e29c9b3bd6e (patch) | |
tree | a75067a661250a4ed74096929083948f65c01fdb /src/main.rs | |
parent | 5891af7e8c1411029fe1ad9c6d3182f88bcf3dfd (diff) |
add api documentation
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 59 |
1 files changed, 12 insertions, 47 deletions
diff --git a/src/main.rs b/src/main.rs index 69eed5d..fab6dd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,19 +2,15 @@ mod api; mod auth; mod database; mod extractors; +mod doc; -use actix_web::{web, App, HttpServer}; +use actix_web::web::Redirect; +use actix_web::{web, App, HttpServer, Responder}; use dotenv::dotenv; use std::env; use std::sync::Arc; -// use utoipa::{ -// openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, -// Modify, OpenApi, -// }; -// -// use utoipa_swagger_ui::SwaggerUi; -// use database::artist::Artist; +use utoipa_swagger_ui::SwaggerUi; #[derive(Clone)] struct AppState { @@ -47,56 +43,25 @@ async fn main() -> std::io::Result<()> { secret: jwt_secret, }; - // /* utoipa setup */ - // #[derive(OpenApi)] - // #[openapi( - // paths( - // ), - // components( - // schemas( - // Artist - // ) - // ), - // modifiers(&SecurityAddon) - // )] - // struct ApiDoc; - - // struct SecurityAddon; - // impl Modify for SecurityAddon { - // fn modify(&self, openapi : &mut utoipa::openapi::OpenApi) { - // let components = openapi.components.as_mut().unwrap(); - // components.add_security_scheme( - // "bearer_auth", - // SecurityScheme::Http( - // HttpBuilder::new() - // .scheme(HttpAuthScheme::Bearer) - // .bearer_format("JWT") - // .build() - // ), - // ); - // } - // } - - // let openapi = ApiDoc::openapi(); + /* OpenApi */ + let openapi = doc::get_openapi(); /* Server setup */ HttpServer::new(move || { App::new() .app_data(web::Data::new(app_state.clone())) - .route("/", web::get().to(root)) - // .service(SwaggerUi::new("/docs/{_:.*}").url( - // "/docs/openapi.json", - // openapi.clone(), - // )) .service(api::api_scope()) .service(auth::auth_scope()) + .service(SwaggerUi::new("/doc/{_:.*}").url("/docs/openapi.json", openapi.clone())) + .route("/", web::get().to(redirect_to_docs)) + .route("/doc", web::get().to(redirect_to_docs)) }) .bind(("127.0.0.1", 8000))? .run() .await } -/* Main page*/ -async fn root() -> String { - String::from("Server is up and running") +/* Redirection page */ +async fn redirect_to_docs() -> impl Responder { + Redirect::to("/doc/") } |