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:
@@ -3,12 +3,25 @@ mod db;
|
|||||||
mod handlers;
|
mod handlers;
|
||||||
mod state;
|
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::Router;
|
||||||
use axum::middleware;
|
use axum::middleware;
|
||||||
|
use axum::response::Json;
|
||||||
use config::AppConfig;
|
use config::AppConfig;
|
||||||
use erp_auth::middleware::jwt_auth_middleware_fn;
|
use erp_auth::middleware::jwt_auth_middleware_fn;
|
||||||
use state::AppState;
|
use state::AppState;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
use utoipa::OpenApi;
|
||||||
|
|
||||||
use erp_core::events::EventBus;
|
use erp_core::events::EventBus;
|
||||||
use erp_core::module::{ErpModule, ModuleRegistry};
|
use erp_core::module::{ErpModule, ModuleRegistry};
|
||||||
@@ -155,6 +168,9 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
let public_routes = Router::new()
|
let public_routes = Router::new()
|
||||||
.merge(handlers::health::health_check_router())
|
.merge(handlers::health::health_check_router())
|
||||||
.merge(erp_auth::AuthModule::public_routes())
|
.merge(erp_auth::AuthModule::public_routes())
|
||||||
|
.route("/api/docs/openapi.json", axum::routing::get(|| async {
|
||||||
|
Json(ApiDoc::openapi())
|
||||||
|
}))
|
||||||
.with_state(state.clone());
|
.with_state(state.clone());
|
||||||
|
|
||||||
// Protected routes (JWT authentication required)
|
// Protected routes (JWT authentication required)
|
||||||
|
|||||||
Reference in New Issue
Block a user