feat(server): add OpenAPI JSON endpoint for API documentation (Phase 6)

Add /api/docs/openapi.json public endpoint returning the OpenAPI spec.
Uses utoipa derive macro with basic API metadata.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iven
2026-04-11 12:33:48 +08:00
parent bddd33ac2f
commit 5c899e6f4a

View File

@@ -3,12 +3,25 @@ mod db;
mod handlers;
mod state;
/// OpenAPI 规范定义。
#[derive(OpenApi)]
#[openapi(
info(
title = "ERP Platform API",
version = "0.1.0",
description = "ERP 平台底座 REST API 文档"
)
)]
struct ApiDoc;
use axum::Router;
use axum::middleware;
use axum::response::Json;
use config::AppConfig;
use erp_auth::middleware::jwt_auth_middleware_fn;
use state::AppState;
use tracing_subscriber::EnvFilter;
use utoipa::OpenApi;
use erp_core::events::EventBus;
use erp_core::module::{ErpModule, ModuleRegistry};
@@ -155,6 +168,9 @@ async fn main() -> anyhow::Result<()> {
let public_routes = Router::new()
.merge(handlers::health::health_check_router())
.merge(erp_auth::AuthModule::public_routes())
.route("/api/docs/openapi.json", axum::routing::get(|| async {
Json(ApiDoc::openapi())
}))
.with_state(state.clone());
// Protected routes (JWT authentication required)