#![expect(unused_crate_dependencies)]
#![cfg_attr(feature = "openapi", allow(clippy::needless_for_each))]
#[stately::entity]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Pipeline {
pub name: String,
pub description: Option<String>,
}
#[stately::entity]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct Source {
pub name: String,
pub url: String,
}
#[stately::entity]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct Sink {
pub name: String,
pub destination: String,
}
#[stately::entity(singleton, description = "Global configuration")]
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize, Default)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct Config {
pub max_connections: usize,
pub timeout_seconds: u64,
}
#[stately::entity]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct Task {
pub name: String,
pub status: String,
}
#[stately::entity]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct Job {
pub name: String,
pub priority: u32,
}
type TaskCache = stately::Collection<Task>;
#[stately::state(openapi)]
pub struct State {
#[singleton]
pub config: Config,
pub pipelines: Pipeline,
#[collection(variant = "ExplicitSource")]
pub sources: Source,
#[collection(TaskCache, variant = "CachedTask")]
pub tasks: Task,
#[collection(variant = "ArchivedPipeline")]
pub archived: Pipeline,
#[collection(TaskCache, variant = "BackgroundTask")]
pub background: Task,
pub sinks: Sink,
pub jobs: Job,
}
#[stately::axum_api(State, openapi)]
pub struct AppState {}
#[tokio::main]
async fn main() {
let state = State::new();
let app_state = AppState::new(state);
let _app: axum::Router = axum::Router::new()
.nest("/api/v1/entity", AppState::router(app_state.clone()))
.with_state(app_state);
println!("✓ Axum router created successfully!");
println!("✓ Available routes:");
println!(" GET /api/v1/entity/list");
println!(" GET /api/v1/entity/list/:type");
println!(" GET /api/v1/entity/search/:needle");
println!(" GET /api/v1/entity/:id?type=<type>");
#[cfg(feature = "openapi")]
{
use utoipa::OpenApi;
let api_doc = AppState::openapi();
println!("\n✓ OpenAPI documentation generated!");
println!(" Paths: {}", api_doc.paths.paths.len());
println!(" Components: {}", api_doc.components.as_ref().map_or(0, |c| c.schemas.len()));
}
println!("\n✓ Example completed successfully!");
}