added serving openapi options

This commit is contained in:
GW_MC
2025-12-18 22:19:16 +08:00
parent 08b1a055a4
commit 86fb222d18
3 changed files with 30 additions and 1 deletions

View File

@@ -87,7 +87,21 @@ pub async fn start_server() {
// build the axum app and run the server...
info!("Starting application...");
let app: Router = routes::get_root_router(Arc::new(get_app_state(&db_connection, &settings)));
let mut app: Router =
routes::get_root_router(Arc::new(get_app_state(&db_connection, &settings)));
if settings.server.serve_openapi {
info!("Enabling OpenAPI documentation endpoint at /openapi.json");
app = app.route(
"/openapi.json",
axum::routing::get(|| async {
use utoipa::OpenApi;
let doc = routes::ApiDoc::openapi();
doc.to_pretty_json()
.expect("Failed to serialize OpenAPI doc to JSON")
}),
);
}
let address = format!("{}:{}", settings.server.address, settings.server.port);
info!("Starting server at http://{}", address);