moadim 0.4.0

Moadim.io MCP/REST server for managing cron jobs
//! OpenAPI 3.0 spec for the Moadim Server REST API, generated from utoipa path decorators.

#[derive(utoipa::OpenApi)]
#[openapi(
    info(title = "Moadim Server API", version = "0.1.0", description = "REST API for managing cron jobs"),
    servers((url = "http://127.0.0.1:5784", description = "Local development")),
    paths(
        crate::routes::http::index,
        crate::routes::http::health,
        crate::routes::http::shutdown,
        crate::routes::http::echo,
        crate::cron_jobs::list,
        crate::cron_jobs::create,
        crate::cron_jobs::get,
        crate::cron_jobs::replace,
        crate::cron_jobs::update,
        crate::cron_jobs::delete,
        crate::cron_jobs::trigger,
        crate::cron_jobs::get_logs,
        crate::routines::list,
        crate::routines::list_agents,
        crate::routines::create,
        crate::routines::get,
        crate::routines::replace,
        crate::routines::update,
        crate::routines::delete,
        crate::routines::trigger,
        crate::routines::get_logs,
    ),
    components(schemas(
        crate::cron_jobs::CronJob,
        crate::cron_jobs::CronJobResponse,
        crate::cron_jobs::CronJobSourceType,
        crate::cron_jobs::CreateRequest,
        crate::cron_jobs::UpdateRequest,
        crate::routines::Routine,
        crate::routines::Repository,
        crate::routines::RoutineResponse,
        crate::routines::CreateRoutineRequest,
        crate::routines::UpdateRoutineRequest,
        crate::routes::http::HealthResponse,
        crate::routes::http::ShutdownResponse,
        crate::routes::http::EchoRequest,
        crate::routes::http::EchoResponse,
    ))
)]
/// OpenAPI document aggregating all REST paths and component schemas.
pub struct ApiDoc;

impl ApiDoc {
    /// Serialize the OpenAPI spec to a pretty-printed JSON string.
    pub fn to_json() -> String {
        use utoipa::OpenApi as _;
        serde_json::to_string_pretty(&Self::openapi()).unwrap_or_default()
    }
}

#[cfg(test)]
mod tests {
    use super::ApiDoc;

    /// Keep the committed `apis/openapi.json` in sync with the path decorators. On drift this
    /// rewrites the file (so `cargo test` regenerates it) and then fails so the change is committed.
    #[test]
    fn committed_spec_is_current() {
        let path = concat!(env!("CARGO_MANIFEST_DIR"), "/apis/openapi.json");
        let generated = ApiDoc::to_json();
        let committed = std::fs::read_to_string(path).unwrap_or_default();
        if committed != generated {
            std::fs::write(path, &generated).unwrap();
            panic!("apis/openapi.json was stale — regenerated; re-run tests and commit the change");
        }
    }
}