1
hutongqing
2024-10-29 9ca96199d92168fe221dda9aba56f55520a561d8
WIDESEAWCS_Server/WIDESEAWCS_Core/Middlewares/SwaggerMiddleware.cs
@@ -7,7 +7,6 @@
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core.Helper;
using static WIDESEAWCS_Core.Extensions.CustomApiVersion;
namespace WIDESEAWCS_Core.Middlewares
{
@@ -24,14 +23,9 @@
            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($"https://petstore.swagger.io/v2/swagger.json", $"{apiName} pet");
                var apiName = AppSettings.Get(new string[] { "ApiName" });
                c.SwaggerEndpoint($"/swagger/v1/swagger.json", $"{apiName} v1");
                // 将swagger首页,设置成我们自定义的页面,记得这个字符串的写法:{项目名.index.html}
                if (streamHtml.Invoke() == null)
                {
@@ -39,6 +33,10 @@
                    //Log.Error(msg);
                    throw new Exception(msg);
                }
                c.DocumentTitle = $"{apiName} 在线调试文档";
                c.InjectStylesheet("/css/swaggerdoc.css");
                c.InjectJavascript("/js/swaggerdoc.js");
                c.IndexStream = streamHtml;
                c.DocExpansion(DocExpansion.None); //->修改界面打开时自动折叠