From 6808e68b5d97cdb39aac1793e7fe30dfbecd7de2 Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期五, 01 八月 2025 17:31:28 +0800
Subject: [PATCH] feat:文档优化结果显示

---
 FlexJobApi.Core/Utils/SwaggerUtils/CustomOperationIdFilter.cs |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/FlexJobApi.Core/Utils/SwaggerUtils/CustomOperationIdFilter.cs b/FlexJobApi.Core/Utils/SwaggerUtils/CustomOperationIdFilter.cs
index e6701e4..b1dd550 100644
--- a/FlexJobApi.Core/Utils/SwaggerUtils/CustomOperationIdFilter.cs
+++ b/FlexJobApi.Core/Utils/SwaggerUtils/CustomOperationIdFilter.cs
@@ -3,6 +3,7 @@
 using Swashbuckle.AspNetCore.SwaggerGen;
 using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -23,6 +24,29 @@
 
             // 璁剧疆鏈�缁堢殑 OperationId
             operation.OperationId = $"{controllerName}-{actionName}";
+
+            // 鑾峰彇鎺ュ彛鏂规硶鐨勮繑鍥炵被鍨嬶紙鍙兘鏄� Task<ApiResult<T>> 鎴� ApiResult<T>锛�
+            var returnType = context.MethodInfo.ReturnType;
+
+            // 姝ラ 1锛氬鏋滄槸 Task 鎴� Task<ApiResult<T>>锛屾彁鍙栧唴閮ㄧ被鍨�
+            if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task<>))
+            {
+                returnType = returnType.GetGenericArguments()[0]; // 鎻愬彇 Task<T> 涓殑 T
+            }
+
+            // 姝ラ 3锛氭浛鎹� Swagger 鍝嶅簲绫诲瀷涓� Data 鐨勭被鍨�
+            operation.Responses.Clear();
+            operation.Responses.Add("200", new OpenApiResponse
+            {
+                Description = "鎿嶄綔鎴愬姛",
+                Content = new Dictionary<string, OpenApiMediaType>
+                {
+                    ["application/json"] = new OpenApiMediaType
+                    {
+                        Schema = context.SchemaGenerator.GenerateSchema(returnType, context.SchemaRepository)
+                    }
+                }
+            });
         }
     }
 }

--
Gitblit v1.9.1