From 1e5d8508e72dffb04e2aaf4e4d75d8b9d7aec47a Mon Sep 17 00:00:00 2001 From: zenghongyao <873884283@qq.com> Date: Thu, 19 Jun 2025 11:36:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0swagger=20=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Build.props | 2 +- .../IoTHttpApiHostModule.Configure.cs | 10 +++++++--- host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.cs | 8 ++++++-- host/JiShe.IoT.HttpApi.Host/appsettings.json | 8 +++++++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index cd3fd33..975f9b1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ - 1.0.5.35 + 1.0.5.36 9.1.1 diff --git a/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.Configure.cs b/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.Configure.cs index b3b98fb..66ebb8a 100644 --- a/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.Configure.cs +++ b/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.Configure.cs @@ -159,18 +159,22 @@ public partial class IoTHttpApiHostModule var configuration = context.Services.GetConfiguration(); var groupNames = EnumExtensions.GetEnumTypeValueNameList(); + var excludeSwaggerGroups = configuration.GetSection("ExcludeSwaggerGroup").Get>() ?? new List(); groupNames.ForEach(group => { - options.SwaggerDoc(group.Key, - new OpenApiInfo { Title = group.Value, Version = "v1"}); + if (!excludeSwaggerGroups.Where(e => e == group.Key).Any()) + { + options.SwaggerDoc(group.Key, + new OpenApiInfo { Title = group.Value, Version = "v1" }); + } }); options.DocInclusionPredicate((docName, description) => { return description.GroupName == docName; }); - options.EnableAnnotations(); // 启用注解 + //options.EnableAnnotations(); // 启用注解 options.DocumentFilter(); options.SchemaFilter(); // 加载所有xml注释,这里会导致swagger加载有点缓慢 diff --git a/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.cs b/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.cs index 0a81fc9..50db6fd 100644 --- a/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.cs +++ b/host/JiShe.IoT.HttpApi.Host/IoTHttpApiHostModule.cs @@ -73,11 +73,15 @@ namespace JiShe.IoT app.UseAbpSwaggerUI(options => { var groupNames = EnumExtensions.GetEnumTypeValueNameList(); - + var excludeSwaggerGroups = configuration.GetSection("ExcludeSwaggerGroup").Get>() ?? new List(); groupNames.ForEach(attr => { - options.SwaggerEndpoint($"/swagger/{attr.Key}/swagger.json", attr.Value); + if (!excludeSwaggerGroups.Where(e => e == attr.Key).Any()) + { + options.SwaggerEndpoint($"/swagger/{attr.Key}/swagger.json", attr.Value); + } }); + //options.SwaggerEndpoint("/swagger/AbpPro/swagger.json", "AbpPro API"); options.DocExpansion(DocExpansion.None); diff --git a/host/JiShe.IoT.HttpApi.Host/appsettings.json b/host/JiShe.IoT.HttpApi.Host/appsettings.json index f8bb961..97c3f7f 100644 --- a/host/JiShe.IoT.HttpApi.Host/appsettings.json +++ b/host/JiShe.IoT.HttpApi.Host/appsettings.json @@ -32,5 +32,11 @@ "App": { "SelfUrl": "http://localhost:44315", "CorsOrigins": "https://*.IoT.com,http://localhost:4200,http://localhost:3100" - } + }, + "ExcludeSwaggerGroup": [ + "FileManagement", + "NotificationManagement", + "CodeManagement", + "TemplateManagement" + ] // 排除Swagger分组 } \ No newline at end of file