#![cfg(feature = "openapi")] use axum::{routing, Json, Router}; use docker_compose_spec::DockerCompose; use std::net::{Ipv4Addr, SocketAddr}; use tokio::net::TcpListener; use utoipa::OpenApi; use utoipa_swagger_ui::SwaggerUi; #[tokio::main(flavor = "current_thread")] async fn main() -> anyhow::Result<()> { #[derive(OpenApi)] #[openapi( nest( (path = "/hello", api = HelloApi), ) )] struct ApiDoc; #[derive(OpenApi)] #[openapi(paths(hello), components(schemas(DockerCompose)))] struct HelloApi; let app = Router::new() .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi())) .route("/hello", routing::get(hello)); let address = SocketAddr::from((Ipv4Addr::UNSPECIFIED, 8080)); let listener = TcpListener::bind(&address).await?; axum::serve(listener, app.into_make_service()).await.map_err(anyhow::Error::from) } #[utoipa::path( get, path = "", responses( (status = 200, description = "Cluster role rules", body = DockerCompose) ), tag = "TEST" )] async fn hello() -> Json { let doc = DockerCompose::from_path("./tests/docker-compose-to-merge.yml").await.unwrap(); Json(doc) }