From 41a5531dc31a642623f0a7a766fbe9c256ba9247 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 11 二月 2025 13:53:29 +0800
Subject: [PATCH] 优化WMS前端
---
项目代码/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