use actix_web::{web, App, HttpResponse, HttpServer};
use utoipa_swagger_ui::{get_swagger_ui, DefaultConfig};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        let swagger_config = DefaultConfig::new("http://localhost:8080", "/openapi.json");
        App::new()
            .service(get_swagger_ui(&swagger_config))
            .route("/openapi.json", web::get().to(get_openapi_spec))
    })
    .bind("0.0.0.0:8080")?
    .run()
    .await
}

async fn get_openapi_spec() -> HttpResponse {
    let openapi_spec = r#"
    {
        "openapi": "3.0.0",
        "info": {
            "title": "Dummy API",
            "version": "1.0"
        },
        "paths": {}
    }
    "#;

    HttpResponse::Ok().body(openapi_spec)
}