From 766cf9ea0c9cbbbc2699b7f655c8d17adb17f023 Mon Sep 17 00:00:00 2001 From: prplV Date: Wed, 25 Jun 2025 03:23:50 -0400 Subject: [PATCH] api start --- Cargo.toml | 1 + src/api_docs.rs | 5 +++++ src/endpoints.rs | 11 +++++++++++ src/main.rs | 1 + src/schemas.rs | 2 +- 5 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/api_docs.rs diff --git a/Cargo.toml b/Cargo.toml index c4bba56..31d80c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,5 @@ serde_json = "1.0.140" tokio = { version = "1.45.1", features = ["full"] } tracing = "0.1.41" tracing-subscriber = "0.3.19" +utoipa = { version = "5.4.0", features = ["axum_extras"] } utoipa-axum = "0.2.0" diff --git a/src/api_docs.rs b/src/api_docs.rs new file mode 100644 index 0000000..19220ba --- /dev/null +++ b/src/api_docs.rs @@ -0,0 +1,5 @@ +use crate::endpoints::rest::__path_model_rest_handler; + +#[derive(utoipa::OpenApi)] +#[openapi(paths(model_rest_handler))] +struct ApiDoc; \ No newline at end of file diff --git a/src/endpoints.rs b/src/endpoints.rs index 441c0fd..aa6b8f0 100644 --- a/src/endpoints.rs +++ b/src/endpoints.rs @@ -19,6 +19,17 @@ pub mod rest { use tracing::trace; use super::{IntoResponse, StatusCode, InputMetric, Json, Config, State}; + #[utoipa::path( + get, + path = "/api/metrics/rest", + 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"), + ) + )] pub async fn model_rest_handler( State(config) : State, Json(req) : Json>, diff --git a/src/main.rs b/src/main.rs index 54aa64e..067a1ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod endpoints; mod schemas; mod models; mod setup; +mod api_docs; use std::sync::Arc; use tracing::{debug, info, trace}; diff --git a/src/schemas.rs b/src/schemas.rs index 49544ae..c658e07 100644 --- a/src/schemas.rs +++ b/src/schemas.rs @@ -1,6 +1,6 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)] pub struct InputMetric { id : String, name : String,