From b2ad000e07e1c87d3561b5aa94fdc88c779872f0 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 18 二月 2025 22:34:54 +0800
Subject: [PATCH] 1

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/SwaggerMiddleware.cs |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/SwaggerMiddleware.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/SwaggerMiddleware.cs"
new file mode 100644
index 0000000..5c88faf
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/SwaggerMiddleware.cs"
@@ -0,0 +1,58 @@
+锘�
+using Microsoft.AspNetCore.Builder;
+using Swashbuckle.AspNetCore.SwaggerUI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WIDESEA_Core.Helper;
+using static WIDESEA_Core.Extensions.CustomApiVersion;
+
+namespace WIDESEA_Core.Middlewares
+{
+    /// <summary>
+    /// Swagger涓棿浠�
+    /// </summary>
+    public static class SwaggerMiddleware
+    {
+        public static void UseSwaggerMiddle(this IApplicationBuilder app, Func<Stream> streamHtml)
+        {
+            if (app == null) throw new ArgumentNullException(nameof(app));
+
+            app.UseSwagger();
+            app.UseSwaggerUI(c =>
+            {
+                //鏍规嵁鐗堟湰鍚嶇О鍊掑簭 閬嶅巻灞曠ず
+                var apiName = AppSettings.app(new string[] { "ApiName" });
+                typeof(ApiVersions).GetEnumNames().OrderByDescending(e => e).ToList().ForEach(version =>
+                {
+                    c.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"{apiName} {version}");
+                });
+
+                //c.SwaggerEndpoint("/swagger/v1/swagger.json", "WIDESEA.Core鍚庡彴Api");
+
+                //c.SwaggerEndpoint($"https://petstore.swagger.io/v2/swagger.json", $"{apiName} pet");
+
+                // 灏唖wagger棣栭〉锛岃缃垚鎴戜滑鑷畾涔夌殑椤甸潰锛岃寰楄繖涓瓧绗︿覆鐨勫啓娉曪細{椤圭洰鍚�.index.html}
+                if (streamHtml.Invoke() == null)
+                {
+                    var msg = "index.html鐨勫睘鎬э紝蹇呴』璁剧疆涓哄祵鍏ョ殑璧勬簮";
+                    //Log.Error(msg);
+                    throw new Exception(msg);
+                }
+                c.IndexStream = streamHtml;
+                c.DocExpansion(DocExpansion.None); //->淇敼鐣岄潰鎵撳紑鏃惰嚜鍔ㄦ姌鍙�
+
+                //if (Permissions.IsUseIds4)
+                //{
+                //    c.OAuthClientId("blogadminjs");
+                //}
+
+
+                // 璺緞閰嶇疆锛岃缃负绌猴紝琛ㄧず鐩存帴鍦ㄦ牴鍩熷悕锛坙ocalhost:8001锛夎闂鏂囦欢,娉ㄦ剰localhost:8001/swagger鏄闂笉鍒扮殑锛屽幓launchSettings.json鎶妉aunchUrl鍘绘帀锛屽鏋滀綘鎯虫崲涓�涓矾寰勶紝鐩存帴鍐欏悕瀛楀嵆鍙紝姣斿鐩存帴鍐檆.RoutePrefix = "doc";
+                c.RoutePrefix = "";
+            });
+        }
+    }
+}

--
Gitblit v1.9.3