diff options
author | rtkay123 <dev@kanjala.com> | 2025-08-12 05:13:32 +0200 |
---|---|---|
committer | rtkay123 <dev@kanjala.com> | 2025-08-12 05:13:32 +0200 |
commit | c5ea875f544824b0c042bf7c0a58b3134f9c0373 (patch) | |
tree | 4913d4ff2b408c7157e33894e40deec570ecce9e /crates/configuration/src/server/http_svc.rs | |
parent | 9c850d6c4d0ed468709c2eb5340d7b64bbb9aa68 (diff) | |
download | warden-c5ea875f544824b0c042bf7c0a58b3134f9c0373.tar.bz2 warden-c5ea875f544824b0c042bf7c0a58b3134f9c0373.zip |
feat(config): get active routing
Diffstat (limited to 'crates/configuration/src/server/http_svc.rs')
-rw-r--r-- | crates/configuration/src/server/http_svc.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/crates/configuration/src/server/http_svc.rs b/crates/configuration/src/server/http_svc.rs new file mode 100644 index 0000000..7b2a258 --- /dev/null +++ b/crates/configuration/src/server/http_svc.rs @@ -0,0 +1,63 @@ +mod routes; + +use axum::{Router, response::IntoResponse}; +use utoipa::OpenApi; +use utoipa_axum::router::OpenApiRouter; +#[cfg(feature = "redoc")] +use utoipa_redoc::Servable; +#[cfg(feature = "scalar")] +use utoipa_scalar::Servable as _; + +use crate::{server::http_svc, state::AppHandle}; + +const TAG_ROUTING: &str = "Routing"; + +#[derive(OpenApi)] +#[openapi( + tags( + (name = TAG_ROUTING, description = "Operations related to routing configuration"), + ) +)] +pub struct ApiDoc; + +/// Get health of the API. +#[utoipa::path( + method(get), + path = "/", + responses( + (status = OK, description = "Success", body = str, content_type = "text/plain") + ) +)] +pub async fn health_check() -> impl IntoResponse { + let name = env!("CARGO_PKG_NAME"); + let ver = env!("CARGO_PKG_VERSION"); + + format!("{name} v{ver} is live") +} + +pub fn build_router(state: AppHandle) -> Router { + let (router, _api) = OpenApiRouter::with_openapi(ApiDoc::openapi()) + .routes(utoipa_axum::routes!(health_check)) + .nest("/api", routes::router(state)) + .split_for_parts(); + + #[cfg(feature = "swagger")] + let router = router.merge( + utoipa_swagger_ui::SwaggerUi::new("/swagger-ui") + .url("/api-docs/swaggerdoc.json", _api.clone()), + ); + + #[cfg(feature = "redoc")] + let router = router.merge(utoipa_redoc::Redoc::with_url("/redoc", _api.clone())); + + #[cfg(feature = "rapidoc")] + let router = router.merge( + utoipa_rapidoc::RapiDoc::with_openapi("/api-docs/rapidoc.json", _api.clone()) + .path("/rapidoc"), + ); + + #[cfg(feature = "scalar")] + let router = router.merge(utoipa_scalar::Scalar::with_url("/scalar", _api)); + + warden_middleware::apply(router) +} |