use std::fs;
use std::path::PathBuf;
use std::thread;
use anyhow::Context as _;
use dynamo_llm::http::service::{openapi_docs, service_v2::HttpService};
const GENERATOR_STACK_SIZE: usize = 8 * 1024 * 1024;
fn main() -> anyhow::Result<()> {
let handle = thread::Builder::new()
.stack_size(GENERATOR_STACK_SIZE)
.spawn(generate_openapi)
.context("failed to spawn generator thread")?;
handle
.join()
.map_err(|e| anyhow::anyhow!("generator thread panicked: {:?}", e))?
}
fn generate_openapi() -> anyhow::Result<()> {
let http_service = HttpService::builder()
.enable_chat_endpoints(true)
.enable_cmpl_endpoints(true)
.enable_embeddings_endpoints(true)
.enable_responses_endpoints(true)
.enable_anthropic_endpoints(true)
.build()
.context("failed to build HttpService for OpenAPI generation")?;
let route_docs = http_service.route_docs().to_vec();
let openapi = openapi_docs::generate_openapi_spec(&route_docs);
let out_dir = PathBuf::from("docs/frontends");
let out_path = out_dir.join("openapi.json");
fs::create_dir_all(&out_dir)
.with_context(|| format!("failed to create OpenAPI output directory: {out_dir:?}"))?;
let json =
serde_json::to_string_pretty(&openapi).context("failed to serialize OpenAPI spec")?;
fs::write(&out_path, json)
.with_context(|| format!("failed to write OpenAPI spec to: {out_path:?}"))?;
println!(
"Generated Dynamo frontend OpenAPI specification at {}",
out_path.display()
);
Ok(())
}