From 38d1c2f92afbcd3355d5cede3b2ab917367fe318 Mon Sep 17 00:00:00 2001 From: Hewt <109787524@qq.com> Date: Mon, 23 Mar 2026 09:21:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0swagger=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_ServiceExtensions/SwaggerSetup.cs | 5 ++++- IRaCIS.Core.API/wwwroot/swagger/ui/Index.html | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs index 153bfe38d..ebba8c3ca 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; @@ -116,6 +116,9 @@ public static class SwaggerSetup //DocExpansion设置为none可折叠所有方法 options.DocExpansion(DocExpansion.None); + // 开启Swagger UI的搜索/过滤功能 + options.EnableFilter(); + //DefaultModelsExpandDepth设置为 - 1 可不显示models options.DefaultModelsExpandDepth(-1); }); diff --git a/IRaCIS.Core.API/wwwroot/swagger/ui/Index.html b/IRaCIS.Core.API/wwwroot/swagger/ui/Index.html index fff5ae586..0943ce0e3 100644 --- a/IRaCIS.Core.API/wwwroot/swagger/ui/Index.html +++ b/IRaCIS.Core.API/wwwroot/swagger/ui/Index.html @@ -1,4 +1,4 @@ - + @@ -112,8 +112,23 @@ }, info: function () { return null; } + }, + fn: { + opsFilter: function (taggedOps, phrase) { + var normalPhrase = phrase.toLowerCase(); + return taggedOps.map(function (tagObj, tag) { + var operations = tagObj.get("operations").filter(function (op) { + var summary = op.getIn(["operation", "summary"]) || ""; + var path = op.get("path") || ""; + var tagMatch = tag.toLowerCase().indexOf(normalPhrase) !== -1; + return tagMatch || summary.toLowerCase().indexOf(normalPhrase) !== -1 || path.toLowerCase().indexOf(normalPhrase) !== -1; + }); + return tagObj.set("operations", operations); + }).filter(function (tagObj) { + return tagObj.get("operations").size > 0; + }); + } } - } } ];