about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabua@gmail.com>2026-10-04 08:18:39 +0300
committerAlexander_Kabui <alexanderkabua@gmail.com>2026-10-04 08:18:39 +0300
commit6616beba3d6298c49cf2cf77ed63605bf5211168 (patch)
tree15b7959e36ea3f7a2c30a59a3d2973e5f7822f74 /src
parent08d6d33323d64c4dff6595adfac852257b27a2f9 (diff)
downloadgenenetwork4-6616beba3d6298c49cf2cf77ed63605bf5211168.tar.gz
Document all endpoints with utoipa summaries; add POST /api/v2/correlation stub
Summaries appear in the generated /openapi.json and make the spec
readable on its own. The correlation endpoint is a stub: it validates
the request shape and returns an envelope with canned data and a null
next pointer, establishing the contract ahead of the real engine.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs5
-rw-r--r--src/routes/correlation.rs58
-rw-r--r--src/routes/groups.rs6
-rw-r--r--src/routes/mod.rs1
-rw-r--r--src/routes/species.rs4
5 files changed, 67 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 39ac601..620aeb6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,6 +32,7 @@ pub fn app() -> Router {
         .routes(routes!(routes::groups::groups))
         .routes(routes!(routes::groups::group_by_name))
         .routes(routes!(routes::groups::group_strains))
+        .routes(routes!(routes::correlation::correlation))
         .split_for_parts();
     router
         .route("/openapi.json", axum::routing::get(|| async { Json(api) }))
@@ -49,7 +50,7 @@ fn request_id_string(request_id: &RequestId) -> Option<String> {
 
 // hello_world and version predate the domain-module split and don't
 // belong to a data domain; kept here as top-level utility routes.
-#[utoipa::path(get, path = "/", responses(
+#[utoipa::path(get, path = "/", summary = "Greeting; confirms the server is up", responses(
     (status = 200, description = "Greeting", body = String),
     (status = 500, description = "Internal error", body = ApiError)
 ))]
@@ -67,7 +68,7 @@ struct VersionInfo {
     git: &'static str,
 }
 
-#[utoipa::path(get, path = "/version", responses(
+#[utoipa::path(get, path = "/version", summary = "Build information: version, git commit, commit date", responses(
     (status = 200, description = "Build information", body = VersionInfo),
     (status = 500, description = "Internal error", body = ApiError)
 ))]
diff --git a/src/routes/correlation.rs b/src/routes/correlation.rs
new file mode 100644
index 0000000..d99190d
--- /dev/null
+++ b/src/routes/correlation.rs
@@ -0,0 +1,58 @@
+//! Correlation domain endpoint.
+//!
+//! STUB: returns canned data in the descriptive envelope so the route
+//! and the response shape can be exercised end to end. The engine
+//! integration is specified in topics/gn4/gn4-correlation.gmi
+//! (gn-gemtext-threads): correlation_rust in-process, rev-pinned.
+
+use axum::extract::Extension;
+use axum::Json;
+use serde::{Deserialize, Serialize};
+use tower_http::request_id::RequestId;
+
+use crate::error::ApiError;
+use crate::request_id_string;
+use crate::response::Envelope;
+
+#[derive(Deserialize, utoipa::ToSchema)]
+pub struct CorrelationRequest {
+    /// Correlation method: pearson, spearman or bicor.
+    pub method: String,
+    /// Dataset to correlate against, e.g. "BXD liver".
+    pub dataset: String,
+    /// The trait to correlate, e.g. "1435863_at".
+    pub trait_name: String,
+}
+
+#[derive(Serialize, utoipa::ToSchema)]
+pub struct CorrelationHit {
+    pub trait_id: u32,
+    pub correlation: f64,
+}
+
+#[utoipa::path(post, path = "/api/v2/correlation",
+    summary = "Compute a sample correlation (STUB: canned data)",
+    description = "Phase A target per topics/gn4/gn4-correlation.gmi. \
+Currently returns canned data wrapped in the descriptive envelope \
+({data, next}); the correlation_rust engine integration is pending.",
+    request_body = CorrelationRequest,
+    responses(
+        (status = 200, description = "Correlated traits, strongest first", body = Vec<CorrelationHit>),
+        (status = 500, description = "Internal error", body = ApiError)
+))]
+pub async fn correlation(
+    Extension(request_id): Extension<RequestId>,
+    Json(request): Json<CorrelationRequest>,
+) -> Result<Json<Envelope<Vec<CorrelationHit>>>, ApiError> {
+    // The stub accepts the request (and its request id, kept for the
+    // envelope/error plumbing) but computes nothing yet.
+    let _ = (request_id_string(&request_id), &request.method);
+    Ok(Json(
+        Envelope::of(vec![
+            CorrelationHit { trait_id: 1_435_863, correlation: 0.91 },
+            CorrelationHit { trait_id: 1_435_987, correlation: 0.87 },
+        ])
+        .with_next("/api/v2/correlation", "Correlate another trait")
+        .with_next("/species", "Narrow by species"),
+    ))
+}
diff --git a/src/routes/groups.rs b/src/routes/groups.rs
index 9686302..dd8c232 100644
--- a/src/routes/groups.rs
+++ b/src/routes/groups.rs
@@ -10,7 +10,7 @@ use crate::db;
 use crate::error::ApiError;
 use crate::request_id_string;
 
-#[utoipa::path(get, path = "/groups", responses(
+#[utoipa::path(get, path = "/groups", summary = "List all groups (populations; InbredSet rows)", responses(
     (status = 200, description = "All groups (InbredSet rows) in the database", body = Vec<db::Group>),
     (status = 500, description = "Database error", body = ApiError)
 ))]
@@ -41,7 +41,7 @@ pub async fn groups(Extension(request_id): Extension<RequestId>) -> Result<Json<
         })
 }
 
-#[utoipa::path(get, path = "/groups/{group}", params(
+#[utoipa::path(get, path = "/groups/{group}", summary = "Get one group's full record by name or numeric id", params(
     ("group" = String, Path, description = "Group InbredSetName, Name, FullName or numeric Id")
 ), responses(
     (status = 200, description = "The matching row of the InbredSet table", body = db::GroupDetail),
@@ -95,7 +95,7 @@ pub struct GroupStrainsParams {
     used_for_mapping: Option<bool>,
 }
 
-#[utoipa::path(get, path = "/groups/{group}/strains", params(
+#[utoipa::path(get, path = "/groups/{group}/strains", summary = "List the strains/samples belonging to a group", params(
     ("group" = String, Path, description = "Group InbredSetName, Name, FullName or numeric Id"),
     ("used_for_mapping" = Option<bool>, Query, description = "Only strains/samples used for mapping")
 ), responses(
diff --git a/src/routes/mod.rs b/src/routes/mod.rs
index 71d51e0..4cd3f7b 100644
--- a/src/routes/mod.rs
+++ b/src/routes/mod.rs
@@ -3,5 +3,6 @@
 //! and utoipa annotations for one domain; lib.rs just registers them
 //! on the router.
 
+pub mod correlation;
 pub mod groups;
 pub mod species;
diff --git a/src/routes/species.rs b/src/routes/species.rs
index 9731726..c7c1b54 100644
--- a/src/routes/species.rs
+++ b/src/routes/species.rs
@@ -9,7 +9,7 @@ use crate::db;
 use crate::error::ApiError;
 use crate::request_id_string;
 
-#[utoipa::path(get, path = "/species", responses(
+#[utoipa::path(get, path = "/species", summary = "List all species in the database", responses(
     (status = 200, description = "All species in the database", body = Vec<db::Species>),
     (status = 500, description = "Database error", body = ApiError)
 ))]
@@ -42,7 +42,7 @@ pub async fn species(Extension(request_id): Extension<RequestId>) -> Result<Json
         })
 }
 
-#[utoipa::path(get, path = "/species/{species}", params(
+#[utoipa::path(get, path = "/species/{species}", summary = "Get one species' full record by name", params(
     ("species" = String, Path, description = "Species Name, FullName or SpeciesName")
 ), responses(
     (status = 200, description = "The matching row of the Species table", body = db::SpeciesDetail),