diff --git a/Cargo.toml b/Cargo.toml index 31d80c5..0986c73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,4 @@ tracing = "0.1.41" tracing-subscriber = "0.3.19" utoipa = { version = "5.4.0", features = ["axum_extras"] } utoipa-axum = "0.2.0" +utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } diff --git a/src/api_docs.rs b/src/api_docs.rs index 19220ba..b59c95b 100644 --- a/src/api_docs.rs +++ b/src/api_docs.rs @@ -1,5 +1,25 @@ +use crate::schemas::InputMetric; use crate::endpoints::rest::__path_model_rest_handler; +use utoipa::OpenApi; -#[derive(utoipa::OpenApi)] -#[openapi(paths(model_rest_handler))] -struct ApiDoc; \ No newline at end of file +#[derive(OpenApi)] +#[openapi( + info( + title = "ML-API", + version = "0.1.0", + description = "API for communication with the Model", + contact( + name = "Vladislav Drozdov", + email = "_@_", + url = "https://___" + ) + ), + paths(model_rest_handler), + components( + schemas(InputMetric) + ), + tags( + (name = "models", description = "API for communication with the Model") + ) +)] +pub struct ApiDoc; \ No newline at end of file diff --git a/src/endpoints.rs b/src/endpoints.rs index aa6b8f0..799e438 100644 --- a/src/endpoints.rs +++ b/src/endpoints.rs @@ -21,14 +21,14 @@ pub mod rest { #[utoipa::path( get, + summary = "An endpoint using to REST communication with the Model", path = "/api/metrics/rest", + request_body = Vec, responses( - (status = 200, description = "Model successfully processed all given data and"), - (status = 500, description = "Some errors with model") - ), - params( - ("metrics" = Vec, Path, description = "Metrics list to work with"), - ) + (status = 200, description = "Model successfully processed all given data and"), + (status = 500, description = "Some errors with model"), + ), + tag = "query" )] pub async fn model_rest_handler( State(config) : State, diff --git a/src/main.rs b/src/main.rs index 067a1ef..806dfee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,6 @@ use std::sync::Arc; use tracing::{debug, info, trace}; use dotenv::dotenv; use endpoints::{ - openapi::swagger, rest::model_rest_handler, ws::model_ws_handler, }; @@ -18,6 +17,9 @@ use axum::{ routing::get, Router}; use lazy_static::lazy_static; +use utoipa_swagger_ui::SwaggerUi; +use api_docs::ApiDoc; +use utoipa::OpenApi; lazy_static! { static ref PROMPT: String = String::from("\n проанализируй ВЕСЬ этот список метрик системы, обращая внимание на статусы КАЖДОЙ МЕТРИКИ:\n 0 - не определен \n 1 - норма \n 2 - предупреждение \n 3 - критично \n 4 - авария \n напиши общую подробную оценку системы с указанием вообще всех слабых мест и рекомендаций по устранению проблем (ВАЖНО!!! : только на русском языке без форматирования и лишнего текста, без комментариев, только оценка и рекомендации) \n ВАЖНО! НЕ ИСПОЛЬЗУЙ MD-форматирование выходного текста, анализируй метрики выше и по ним делай выводы и рекомендации"); @@ -39,7 +41,8 @@ async fn main() -> anyhow::Result<()> { let router = Router::new() .nest("/api/metrics", api) - .route("/swagger", get(swagger)); + .merge(SwaggerUi::new("/swagger").url("/api-docs/openapi.json", ApiDoc::openapi())); + // .route("/swagger", get(swagger)); debug!("router for app : {:?}", router);