feat: add utoipa path annotations to all API handlers and wire OpenAPI spec
- Add #[utoipa::path] annotations to all 70+ handler functions across auth, config, workflow, and message modules - Add IntoParams/ToSchema derives to Pagination, PaginatedResponse, ApiResponse in erp-core, and MessageQuery/TemplateQuery in erp-message - Collect all module paths into OpenAPI spec via AuthApiDoc, ConfigApiDoc, WorkflowApiDoc, MessageApiDoc structs in erp-server main.rs - Update openapi_spec handler to merge all module specs - The /docs/openapi.json endpoint now returns complete API documentation with all endpoints, request/response schemas, and security requirements
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
use axum::response::Json;
|
||||
use serde_json::Value;
|
||||
use utoipa::openapi::OpenApiBuilder;
|
||||
use utoipa::OpenApi;
|
||||
|
||||
use crate::{ApiDoc, AuthApiDoc, ConfigApiDoc, WorkflowApiDoc, MessageApiDoc};
|
||||
|
||||
/// GET /docs/openapi.json
|
||||
///
|
||||
/// 返回 OpenAPI 3.0 规范 JSON 文档
|
||||
/// 返回 OpenAPI 3.0 规范 JSON 文档,合并所有模块的路径和 schema。
|
||||
pub async fn openapi_spec() -> Json<Value> {
|
||||
let mut info = utoipa::openapi::Info::new("ERP Platform API", env!("CARGO_PKG_VERSION"));
|
||||
info.description = Some("ERP 平台底座 REST API 文档".to_string());
|
||||
let mut spec = ApiDoc::openapi();
|
||||
spec.merge(AuthApiDoc::openapi());
|
||||
spec.merge(ConfigApiDoc::openapi());
|
||||
spec.merge(WorkflowApiDoc::openapi());
|
||||
spec.merge(MessageApiDoc::openapi());
|
||||
|
||||
let spec = OpenApiBuilder::new().info(info).build();
|
||||
Json(serde_json::to_value(spec).unwrap_or_default())
|
||||
}
|
||||
|
||||
@@ -5,16 +5,167 @@ mod middleware;
|
||||
mod outbox;
|
||||
mod state;
|
||||
|
||||
/// OpenAPI 规范定义(预留,未来可通过 utoipa derive 合并各模块 schema)。
|
||||
/// OpenAPI 规范定义 — 通过 utoipa derive 合并各模块 schema。
|
||||
#[derive(OpenApi)]
|
||||
#[openapi(info(
|
||||
title = "ERP Platform API",
|
||||
version = "0.1.0",
|
||||
description = "ERP 平台底座 REST API 文档"
|
||||
))]
|
||||
#[allow(dead_code)]
|
||||
struct ApiDoc;
|
||||
|
||||
/// Auth 模块的 OpenAPI 路径收集
|
||||
#[derive(OpenApi)]
|
||||
#[openapi(
|
||||
paths(
|
||||
erp_auth::handler::auth_handler::login,
|
||||
erp_auth::handler::auth_handler::refresh,
|
||||
erp_auth::handler::auth_handler::logout,
|
||||
erp_auth::handler::user_handler::list_users,
|
||||
erp_auth::handler::user_handler::create_user,
|
||||
erp_auth::handler::user_handler::get_user,
|
||||
erp_auth::handler::user_handler::update_user,
|
||||
erp_auth::handler::user_handler::delete_user,
|
||||
erp_auth::handler::user_handler::assign_roles,
|
||||
erp_auth::handler::role_handler::list_roles,
|
||||
erp_auth::handler::role_handler::create_role,
|
||||
erp_auth::handler::role_handler::get_role,
|
||||
erp_auth::handler::role_handler::update_role,
|
||||
erp_auth::handler::role_handler::delete_role,
|
||||
erp_auth::handler::role_handler::assign_permissions,
|
||||
erp_auth::handler::role_handler::get_role_permissions,
|
||||
erp_auth::handler::role_handler::list_permissions,
|
||||
),
|
||||
components(
|
||||
schemas(
|
||||
erp_auth::dto::LoginReq,
|
||||
erp_auth::dto::LoginResp,
|
||||
erp_auth::dto::RefreshReq,
|
||||
erp_auth::dto::UserResp,
|
||||
erp_auth::dto::CreateUserReq,
|
||||
erp_auth::dto::UpdateUserReq,
|
||||
erp_auth::dto::RoleResp,
|
||||
erp_auth::dto::CreateRoleReq,
|
||||
erp_auth::dto::UpdateRoleReq,
|
||||
erp_auth::dto::PermissionResp,
|
||||
erp_auth::dto::AssignPermissionsReq,
|
||||
)
|
||||
)
|
||||
)]
|
||||
struct AuthApiDoc;
|
||||
|
||||
/// Config 模块的 OpenAPI 路径收集
|
||||
#[derive(OpenApi)]
|
||||
#[openapi(
|
||||
paths(
|
||||
erp_config::handler::dictionary_handler::list_dictionaries,
|
||||
erp_config::handler::dictionary_handler::create_dictionary,
|
||||
erp_config::handler::dictionary_handler::update_dictionary,
|
||||
erp_config::handler::dictionary_handler::delete_dictionary,
|
||||
erp_config::handler::dictionary_handler::list_items_by_code,
|
||||
erp_config::handler::dictionary_handler::create_item,
|
||||
erp_config::handler::dictionary_handler::update_item,
|
||||
erp_config::handler::menu_handler::get_menus,
|
||||
erp_config::handler::menu_handler::create_menu,
|
||||
erp_config::handler::menu_handler::update_menu,
|
||||
erp_config::handler::menu_handler::delete_menu,
|
||||
erp_config::handler::numbering_handler::list_numbering_rules,
|
||||
erp_config::handler::numbering_handler::create_numbering_rule,
|
||||
erp_config::handler::numbering_handler::update_numbering_rule,
|
||||
erp_config::handler::numbering_handler::generate_number,
|
||||
erp_config::handler::numbering_handler::delete_numbering_rule,
|
||||
erp_config::handler::theme_handler::get_theme,
|
||||
erp_config::handler::theme_handler::update_theme,
|
||||
erp_config::handler::language_handler::list_languages,
|
||||
erp_config::handler::language_handler::update_language,
|
||||
erp_config::handler::setting_handler::get_setting,
|
||||
erp_config::handler::setting_handler::update_setting,
|
||||
erp_config::handler::setting_handler::delete_setting,
|
||||
),
|
||||
components(
|
||||
schemas(
|
||||
erp_config::dto::DictionaryResp,
|
||||
erp_config::dto::CreateDictionaryReq,
|
||||
erp_config::dto::UpdateDictionaryReq,
|
||||
erp_config::dto::DictionaryItemResp,
|
||||
erp_config::dto::CreateDictionaryItemReq,
|
||||
erp_config::dto::UpdateDictionaryItemReq,
|
||||
erp_config::dto::MenuResp,
|
||||
erp_config::dto::CreateMenuReq,
|
||||
erp_config::dto::UpdateMenuReq,
|
||||
erp_config::dto::NumberingRuleResp,
|
||||
erp_config::dto::CreateNumberingRuleReq,
|
||||
erp_config::dto::UpdateNumberingRuleReq,
|
||||
erp_config::dto::ThemeResp,
|
||||
)
|
||||
)
|
||||
)]
|
||||
struct ConfigApiDoc;
|
||||
|
||||
/// Workflow 模块的 OpenAPI 路径收集
|
||||
#[derive(OpenApi)]
|
||||
#[openapi(
|
||||
paths(
|
||||
erp_workflow::handler::definition_handler::list_definitions,
|
||||
erp_workflow::handler::definition_handler::create_definition,
|
||||
erp_workflow::handler::definition_handler::get_definition,
|
||||
erp_workflow::handler::definition_handler::update_definition,
|
||||
erp_workflow::handler::definition_handler::publish_definition,
|
||||
erp_workflow::handler::instance_handler::start_instance,
|
||||
erp_workflow::handler::instance_handler::list_instances,
|
||||
erp_workflow::handler::instance_handler::get_instance,
|
||||
erp_workflow::handler::instance_handler::suspend_instance,
|
||||
erp_workflow::handler::instance_handler::terminate_instance,
|
||||
erp_workflow::handler::instance_handler::resume_instance,
|
||||
erp_workflow::handler::task_handler::list_pending_tasks,
|
||||
erp_workflow::handler::task_handler::list_completed_tasks,
|
||||
erp_workflow::handler::task_handler::complete_task,
|
||||
erp_workflow::handler::task_handler::delegate_task,
|
||||
),
|
||||
components(
|
||||
schemas(
|
||||
erp_workflow::dto::ProcessDefinitionResp,
|
||||
erp_workflow::dto::CreateProcessDefinitionReq,
|
||||
erp_workflow::dto::UpdateProcessDefinitionReq,
|
||||
erp_workflow::dto::ProcessInstanceResp,
|
||||
erp_workflow::dto::StartInstanceReq,
|
||||
erp_workflow::dto::TaskResp,
|
||||
erp_workflow::dto::CompleteTaskReq,
|
||||
erp_workflow::dto::DelegateTaskReq,
|
||||
)
|
||||
)
|
||||
)]
|
||||
struct WorkflowApiDoc;
|
||||
|
||||
/// Message 模块的 OpenAPI 路径收集
|
||||
#[derive(OpenApi)]
|
||||
#[openapi(
|
||||
paths(
|
||||
erp_message::handler::message_handler::list_messages,
|
||||
erp_message::handler::message_handler::unread_count,
|
||||
erp_message::handler::message_handler::send_message,
|
||||
erp_message::handler::message_handler::mark_read,
|
||||
erp_message::handler::message_handler::mark_all_read,
|
||||
erp_message::handler::message_handler::delete_message,
|
||||
erp_message::handler::template_handler::list_templates,
|
||||
erp_message::handler::template_handler::create_template,
|
||||
erp_message::handler::subscription_handler::update_subscription,
|
||||
),
|
||||
components(
|
||||
schemas(
|
||||
erp_message::dto::MessageResp,
|
||||
erp_message::dto::SendMessageReq,
|
||||
erp_message::dto::MessageQuery,
|
||||
erp_message::dto::UnreadCountResp,
|
||||
erp_message::dto::MessageTemplateResp,
|
||||
erp_message::dto::CreateTemplateReq,
|
||||
erp_message::dto::MessageSubscriptionResp,
|
||||
erp_message::dto::UpdateSubscriptionReq,
|
||||
)
|
||||
)
|
||||
)]
|
||||
struct MessageApiDoc;
|
||||
|
||||
use axum::Router;
|
||||
use axum::middleware as axum_middleware;
|
||||
use config::AppConfig;
|
||||
|
||||
Reference in New Issue
Block a user