From a84c8c57adb6b85d68174e764b58da907a69b043 Mon Sep 17 00:00:00 2001 From: yubaolee Date: Fri, 11 Jun 2021 23:40:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E4=BC=98=E5=8C=96sw?= =?UTF-8?q?agger=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AccessObjsController.cs | 2 +- .../Controllers/ApplicationsController.cs | 2 +- .../BuilderTableColumnsController.cs | 2 +- .../Controllers/BuilderTablesController.cs | 2 +- .../Controllers/CategoryTypesController.cs | 2 +- .../Controllers/CategorysController.cs | 2 +- .../Controllers/CheckController.cs | 4 +- .../DataPrivilegeRulesController.cs | 2 +- .../Controllers/FilesController.cs | 2 +- .../Controllers/FlowInstancesController.cs | 2 +- .../Controllers/FlowSchemesController.cs | 2 +- .../Controllers/FormsController.cs | 2 +- .../Controllers/ModulesController.cs | 2 +- .../Controllers/OpenJobsController.cs | 2 +- OpenAuth.WebApi/Controllers/OrgsController.cs | 2 +- .../Controllers/ResourcesController.cs | 2 +- .../Controllers/RolesController.cs | 2 +- .../Controllers/SysConfController.cs | 2 +- .../Controllers/SysLogsController.cs | 2 +- .../Controllers/SysMessagesController.cs | 2 +- .../Controllers/UsersController.cs | 2 +- .../WmsInboundOrderDtblsController.cs | 2 +- .../WmsInboundOrderTblsController.cs | 2 +- OpenAuth.WebApi/Startup.cs | 74 ++++++++++++------- 24 files changed, 71 insertions(+), 51 deletions(-) diff --git a/OpenAuth.WebApi/Controllers/AccessObjsController.cs b/OpenAuth.WebApi/Controllers/AccessObjsController.cs index f45fd438..590167be 100644 --- a/OpenAuth.WebApi/Controllers/AccessObjsController.cs +++ b/OpenAuth.WebApi/Controllers/AccessObjsController.cs @@ -13,7 +13,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "AccessObjs")] + [ApiExplorerSettings(GroupName = "分配资源_AccessObjs")] public class AccessObjsController : ControllerBase { private readonly RevelanceManagerApp _app; diff --git a/OpenAuth.WebApi/Controllers/ApplicationsController.cs b/OpenAuth.WebApi/Controllers/ApplicationsController.cs index a9b6b503..880bf4a2 100644 --- a/OpenAuth.WebApi/Controllers/ApplicationsController.cs +++ b/OpenAuth.WebApi/Controllers/ApplicationsController.cs @@ -11,7 +11,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "Applications")] + [ApiExplorerSettings(GroupName = "应用管理_Applications")] public class ApplicationsController : ControllerBase { private readonly AppManager _app; diff --git a/OpenAuth.WebApi/Controllers/BuilderTableColumnsController.cs b/OpenAuth.WebApi/Controllers/BuilderTableColumnsController.cs index daad4877..bc2e7580 100644 --- a/OpenAuth.WebApi/Controllers/BuilderTableColumnsController.cs +++ b/OpenAuth.WebApi/Controllers/BuilderTableColumnsController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "BuilderTableColumns")] + [ApiExplorerSettings(GroupName = "代码生成器_字段_BuilderTableColumns")] public class BuilderTableColumnsController : ControllerBase { private readonly BuilderTableColumnApp _app; diff --git a/OpenAuth.WebApi/Controllers/BuilderTablesController.cs b/OpenAuth.WebApi/Controllers/BuilderTablesController.cs index 36db44d8..91e2639f 100644 --- a/OpenAuth.WebApi/Controllers/BuilderTablesController.cs +++ b/OpenAuth.WebApi/Controllers/BuilderTablesController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "BuilderTables")] + [ApiExplorerSettings(GroupName = "代码生成器_表_BuilderTables")] public class BuilderTablesController : ControllerBase { private readonly BuilderTableApp _app; diff --git a/OpenAuth.WebApi/Controllers/CategoryTypesController.cs b/OpenAuth.WebApi/Controllers/CategoryTypesController.cs index e77880bc..230f9ef6 100644 --- a/OpenAuth.WebApi/Controllers/CategoryTypesController.cs +++ b/OpenAuth.WebApi/Controllers/CategoryTypesController.cs @@ -13,7 +13,7 @@ using OpenAuth.App.Response; /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "CategoryTypes")] + [ApiExplorerSettings(GroupName = "字典所属分类_CategoryTypes")] public class CategoryTypesController : ControllerBase { private readonly CategoryTypeApp _app; diff --git a/OpenAuth.WebApi/Controllers/CategorysController.cs b/OpenAuth.WebApi/Controllers/CategorysController.cs index 662fe648..e1b2e28b 100644 --- a/OpenAuth.WebApi/Controllers/CategorysController.cs +++ b/OpenAuth.WebApi/Controllers/CategorysController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "Categorys")] + [ApiExplorerSettings(GroupName = "分类字典_Categorys")] public class CategorysController : ControllerBase { private readonly CategoryApp _app; diff --git a/OpenAuth.WebApi/Controllers/CheckController.cs b/OpenAuth.WebApi/Controllers/CheckController.cs index c4cb3f2b..63d0b86a 100644 --- a/OpenAuth.WebApi/Controllers/CheckController.cs +++ b/OpenAuth.WebApi/Controllers/CheckController.cs @@ -33,7 +33,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "Check")] + [ApiExplorerSettings(GroupName = "登录验证_Check")] public class CheckController : ControllerBase { private readonly IAuth _authUtil; @@ -341,7 +341,7 @@ namespace OpenAuth.WebApi.Controllers { var result = new LoginResult(); try - { + { result = _authUtil.Login(request.AppKey, request.Account, request.Password); } catch (Exception ex) diff --git a/OpenAuth.WebApi/Controllers/DataPrivilegeRulesController.cs b/OpenAuth.WebApi/Controllers/DataPrivilegeRulesController.cs index a8987992..e5dd0977 100644 --- a/OpenAuth.WebApi/Controllers/DataPrivilegeRulesController.cs +++ b/OpenAuth.WebApi/Controllers/DataPrivilegeRulesController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "DataPrivilegeRules")] + [ApiExplorerSettings(GroupName = "数据权限_DataPrivilegeRules")] public class DataPrivilegeRulesController : ControllerBase { private readonly DataPrivilegeRuleApp _app; diff --git a/OpenAuth.WebApi/Controllers/FilesController.cs b/OpenAuth.WebApi/Controllers/FilesController.cs index 7d63bed6..b7634e1b 100644 --- a/OpenAuth.WebApi/Controllers/FilesController.cs +++ b/OpenAuth.WebApi/Controllers/FilesController.cs @@ -18,7 +18,7 @@ namespace OpenAuth.WebApi.Controllers [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "Files")] + [ApiExplorerSettings(GroupName = "文件管理_Files")] public class FilesController :ControllerBase { diff --git a/OpenAuth.WebApi/Controllers/FlowInstancesController.cs b/OpenAuth.WebApi/Controllers/FlowInstancesController.cs index 6e60cd64..3cb6878e 100644 --- a/OpenAuth.WebApi/Controllers/FlowInstancesController.cs +++ b/OpenAuth.WebApi/Controllers/FlowInstancesController.cs @@ -22,7 +22,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "FlowInstances")] + [ApiExplorerSettings(GroupName = "流程实例_FlowInstances")] public class FlowInstancesController : ControllerBase { private readonly FlowInstanceApp _app; diff --git a/OpenAuth.WebApi/Controllers/FlowSchemesController.cs b/OpenAuth.WebApi/Controllers/FlowSchemesController.cs index cd5e6082..f517084d 100644 --- a/OpenAuth.WebApi/Controllers/FlowSchemesController.cs +++ b/OpenAuth.WebApi/Controllers/FlowSchemesController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "FlowSchemes")] + [ApiExplorerSettings(GroupName = "流程模版_FlowSchemes")] public class FlowSchemesController : ControllerBase { private readonly FlowSchemeApp _app; diff --git a/OpenAuth.WebApi/Controllers/FormsController.cs b/OpenAuth.WebApi/Controllers/FormsController.cs index 50d1f9a3..69d2b93c 100644 --- a/OpenAuth.WebApi/Controllers/FormsController.cs +++ b/OpenAuth.WebApi/Controllers/FormsController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "Forms")] + [ApiExplorerSettings(GroupName = "表单_Forms")] public class FormsController : ControllerBase { private readonly FormApp _app; diff --git a/OpenAuth.WebApi/Controllers/ModulesController.cs b/OpenAuth.WebApi/Controllers/ModulesController.cs index 79fedaf3..b58af267 100644 --- a/OpenAuth.WebApi/Controllers/ModulesController.cs +++ b/OpenAuth.WebApi/Controllers/ModulesController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "Modules")] + [ApiExplorerSettings(GroupName = "模块菜单_Modules")] public class ModulesController : ControllerBase { private ModuleManagerApp _app; diff --git a/OpenAuth.WebApi/Controllers/OpenJobsController.cs b/OpenAuth.WebApi/Controllers/OpenJobsController.cs index 7a6282ef..eb02eeb9 100644 --- a/OpenAuth.WebApi/Controllers/OpenJobsController.cs +++ b/OpenAuth.WebApi/Controllers/OpenJobsController.cs @@ -16,7 +16,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "OpenJobs")] + [ApiExplorerSettings(GroupName = "定时任务_OpenJobs")] public class OpenJobsController : ControllerBase { private readonly OpenJobApp _app; diff --git a/OpenAuth.WebApi/Controllers/OrgsController.cs b/OpenAuth.WebApi/Controllers/OrgsController.cs index 07cd5cc7..4e2d4980 100644 --- a/OpenAuth.WebApi/Controllers/OrgsController.cs +++ b/OpenAuth.WebApi/Controllers/OrgsController.cs @@ -11,7 +11,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "Orgs")] + [ApiExplorerSettings(GroupName = "组织机构_Orgs")] public class OrgsController : ControllerBase { private readonly OrgManagerApp _app; diff --git a/OpenAuth.WebApi/Controllers/ResourcesController.cs b/OpenAuth.WebApi/Controllers/ResourcesController.cs index 6ad7e65e..a7e63c98 100644 --- a/OpenAuth.WebApi/Controllers/ResourcesController.cs +++ b/OpenAuth.WebApi/Controllers/ResourcesController.cs @@ -17,7 +17,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "Resources")] + [ApiExplorerSettings(GroupName = "资源管理_Resources")] public class ResourcesController : ControllerBase { private readonly ResourceApp _app; diff --git a/OpenAuth.WebApi/Controllers/RolesController.cs b/OpenAuth.WebApi/Controllers/RolesController.cs index a1e69a74..a49d7e6c 100644 --- a/OpenAuth.WebApi/Controllers/RolesController.cs +++ b/OpenAuth.WebApi/Controllers/RolesController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "Roles")] + [ApiExplorerSettings(GroupName = "角色管理_Roles")] public class RolesController : ControllerBase { private readonly RoleApp _app; diff --git a/OpenAuth.WebApi/Controllers/SysConfController.cs b/OpenAuth.WebApi/Controllers/SysConfController.cs index 535d8911..1e35cb67 100644 --- a/OpenAuth.WebApi/Controllers/SysConfController.cs +++ b/OpenAuth.WebApi/Controllers/SysConfController.cs @@ -11,7 +11,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "SysConf")] + [ApiExplorerSettings(GroupName = "系统配置_SysConf")] public class SysConfController :ControllerBase { private IOptions _appConfiguration; diff --git a/OpenAuth.WebApi/Controllers/SysLogsController.cs b/OpenAuth.WebApi/Controllers/SysLogsController.cs index ed849a84..cc788e2c 100644 --- a/OpenAuth.WebApi/Controllers/SysLogsController.cs +++ b/OpenAuth.WebApi/Controllers/SysLogsController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "SysLogs")] + [ApiExplorerSettings(GroupName = "系统日志_SysLogs")] public class SysLogsController : ControllerBase { private readonly SysLogApp _app; diff --git a/OpenAuth.WebApi/Controllers/SysMessagesController.cs b/OpenAuth.WebApi/Controllers/SysMessagesController.cs index bb47f790..40033754 100644 --- a/OpenAuth.WebApi/Controllers/SysMessagesController.cs +++ b/OpenAuth.WebApi/Controllers/SysMessagesController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "SysMessages")] + [ApiExplorerSettings(GroupName = "消息中心_SysMessages")] public class SysMessagesController : ControllerBase { private readonly SysMessageApp _app; diff --git a/OpenAuth.WebApi/Controllers/UsersController.cs b/OpenAuth.WebApi/Controllers/UsersController.cs index 27db6e74..2774eac0 100644 --- a/OpenAuth.WebApi/Controllers/UsersController.cs +++ b/OpenAuth.WebApi/Controllers/UsersController.cs @@ -13,7 +13,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "Users")] + [ApiExplorerSettings(GroupName = "用户管理_Users")] public class UsersController : ControllerBase { private readonly UserManagerApp _app; diff --git a/OpenAuth.WebApi/Controllers/WmsInboundOrderDtblsController.cs b/OpenAuth.WebApi/Controllers/WmsInboundOrderDtblsController.cs index 1cc88ab8..8104b2cd 100644 --- a/OpenAuth.WebApi/Controllers/WmsInboundOrderDtblsController.cs +++ b/OpenAuth.WebApi/Controllers/WmsInboundOrderDtblsController.cs @@ -15,7 +15,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "WmsInboundOrderDtbls")] + [ApiExplorerSettings(GroupName = "订单明细_WmsInboundOrderDtbls")] public class WmsInboundOrderDtblsController : ControllerBase { private readonly WmsInboundOrderDtblApp _app; diff --git a/OpenAuth.WebApi/Controllers/WmsInboundOrderTblsController.cs b/OpenAuth.WebApi/Controllers/WmsInboundOrderTblsController.cs index 08bcf3a4..da3b10eb 100644 --- a/OpenAuth.WebApi/Controllers/WmsInboundOrderTblsController.cs +++ b/OpenAuth.WebApi/Controllers/WmsInboundOrderTblsController.cs @@ -14,7 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] - [ApiExplorerSettings(GroupName = "WmsInboundOrderTbls")] + [ApiExplorerSettings(GroupName = "订单_WmsInboundOrderTbls")] public class WmsInboundOrderTblsController : ControllerBase { private readonly WmsInboundOrderTblApp _app; diff --git a/OpenAuth.WebApi/Startup.cs b/OpenAuth.WebApi/Startup.cs index c3c96a3b..fcfe4313 100644 --- a/OpenAuth.WebApi/Startup.cs +++ b/OpenAuth.WebApi/Startup.cs @@ -41,11 +41,8 @@ namespace OpenAuth.WebApi // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - //在startup中需要强制创建log4net - var loggerFactory = LoggerFactory.Create(builder => - { - builder.AddLog4Net(); - }); + //在startup中需要强制创建log4net + var loggerFactory = LoggerFactory.Create(builder => { builder.AddLog4Net(); }); ILogger logger = loggerFactory.CreateLogger(); var identityServer = @@ -62,29 +59,32 @@ namespace OpenAuth.WebApi options.Audience = "openauthapi"; }); } + // 添加MiniProfiler服务 services.AddMiniProfiler(options => { // 设定访问分析结果URL的路由基地址 options.RouteBasePath = "/profiler"; - + options.ColorScheme = StackExchange.Profiling.ColorScheme.Auto; options.PopupRenderPosition = StackExchange.Profiling.RenderPosition.BottomLeft; options.PopupShowTimeWithChildren = true; options.PopupShowTrivial = true; options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter(); // options.IgnoredPaths.Add("/swagger/"); - }).AddEntityFramework();//显示SQL语句及耗时 + }).AddEntityFramework(); //显示SQL语句及耗时 //添加swagger services.AddSwaggerGen(option => { foreach (var controller in GetControllers()) { - option.SwaggerDoc(controller.Name.Replace("Controller", ""), new OpenApiInfo + var groupname = GetSwaggerGroupName(controller); + + option.SwaggerDoc(groupname, new OpenApiInfo { Version = "v1", - Title = controller.Name.Replace("Controller", ""), + Title = groupname, Description = "by yubaolee" }); } @@ -173,22 +173,11 @@ namespace OpenAuth.WebApi services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Configuration["DataProtection"])); - //设置定时启动的任务 services.AddHostedService(); } - private List GetControllers() - { - Assembly asm = Assembly.GetExecutingAssembly(); - - var controlleractionlist = asm.GetTypes() - .Where(type => typeof(ControllerBase).IsAssignableFrom(type)) - .OrderBy(x => x.Name).ToList(); - return controlleractionlist; - } - public void ConfigureContainer(ContainerBuilder builder) { AutofacExt.InitAutofac(builder); @@ -234,25 +223,56 @@ namespace OpenAuth.WebApi //配置ServiceProvider AutofacContainerModule.ConfigServiceProvider(app.ApplicationServices); - + + app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => - { - c.IndexStream = () => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("OpenAuth.WebApi.index.html"); - + { + c.IndexStream = () => + GetType().GetTypeInfo().Assembly.GetManifestResourceStream("OpenAuth.WebApi.index.html"); + foreach (var controller in GetControllers()) { - c.SwaggerEndpoint($"/swagger/{controller.Name.Replace("Controller", "")}/swagger.json", - controller.Name.Replace("Controller", "")); + var groupname = GetSwaggerGroupName(controller); + + c.SwaggerEndpoint($"/swagger/{groupname}/swagger.json", groupname); } - c.DocExpansion(DocExpansion.List); //默认展开列表 + c.DocExpansion(DocExpansion.List); //默认展开列表 c.OAuthClientId("OpenAuth.WebApi"); //oauth客户端名称 c.OAuthAppName("开源版webapi认证"); // 描述 }); } + + /// + /// 获取控制器对应的swagger分组值 + /// + private string GetSwaggerGroupName(Type controller) + { + var groupname = controller.Name.Replace("Controller", ""); + var apisetting = controller.GetCustomAttribute(typeof(ApiExplorerSettingsAttribute)); + if (apisetting != null) + { + groupname = ((ApiExplorerSettingsAttribute) apisetting).GroupName; + } + + return groupname; + } + + /// + /// 获取所有的控制器 + /// + private List GetControllers() + { + Assembly asm = Assembly.GetExecutingAssembly(); + + var controlleractionlist = asm.GetTypes() + .Where(type => typeof(ControllerBase).IsAssignableFrom(type)) + .OrderBy(x => x.Name).ToList(); + return controlleractionlist; + } } } \ No newline at end of file