diff --git a/CodeSmith/CSharp/ApiGenerate/Controller.cst b/CodeSmith/CSharp/ApiGenerate/Controller.cst index fdfb966f..30119a0e 100644 --- a/CodeSmith/CSharp/ApiGenerate/Controller.cst +++ b/CodeSmith/CSharp/ApiGenerate/Controller.cst @@ -28,7 +28,9 @@ namespace OpenAuth.WebApi.Controllers { private readonly <%=ModuleName%>App _app; - //获取详情 + /// + /// //获取详情 + /// [HttpGet] public Response<<%=ModuleName%>> Get(string id) { @@ -46,7 +48,9 @@ namespace OpenAuth.WebApi.Controllers return result; } - //添加 + /// + /// 添加 + /// [HttpPost] public Response Add(AddOrUpdate<%=ModuleName%>Req obj) { @@ -65,7 +69,9 @@ namespace OpenAuth.WebApi.Controllers return result; } - //修改 + /// + /// 修改 + /// [HttpPost] public Response Update(AddOrUpdate<%=ModuleName%>Req obj) { diff --git a/CodeSmith/CSharp/Web/Controller.cst b/CodeSmith/CSharp/Web/Controller.cst index 307d1fe0..8b9a47e5 100644 --- a/CodeSmith/CSharp/Web/Controller.cst +++ b/CodeSmith/CSharp/Web/Controller.cst @@ -36,9 +36,13 @@ namespace OpenAuth.Mvc.Controllers return View(); } - //添加或修改 + /// + /// MVC界面添加 + /// + /// + /// [HttpPost] - public string Add(<%=ModuleName%> obj) + public string Add(AddOrUpdate<%=ModuleName%>Req obj) { try { @@ -53,9 +57,13 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(Result); } - //添加或修改 + /// + /// MVC界面修改 + /// + /// + /// [HttpPost] - public string Update(<%=ModuleName%> obj) + public string Update(AddOrUpdate<%=ModuleName%>Req obj) { try { diff --git a/OpenAuth.App/Flow/FlowRuntime.cs b/OpenAuth.App/Flow/FlowRuntime.cs index d5b4b06d..70ae339c 100644 --- a/OpenAuth.App/Flow/FlowRuntime.cs +++ b/OpenAuth.App/Flow/FlowRuntime.cs @@ -449,7 +449,7 @@ namespace OpenAuth.App.Flow /// /// 下一个节点对象 /// - public FlowNode nextNode => Nodes[nextNodeId]; + public FlowNode nextNode => nextNodeId != "-1"? Nodes[nextNodeId] : null; /// /// 上一个节点 diff --git a/OpenAuth.App/Test/TestFlow.cs b/OpenAuth.App/Test/TestFlow.cs index 1e07e310..8941874a 100644 --- a/OpenAuth.App/Test/TestFlow.cs +++ b/OpenAuth.App/Test/TestFlow.cs @@ -63,6 +63,15 @@ namespace OpenAuth.App.Test } + [Test] + public void GetDetail() + { + var app = _autofacServiceProvider.GetService(); + var flowinstance = app.GetForVerification("80e9db5f-419b-4b65-a274-abe2660608dd"); + Console.WriteLine(JsonHelper.Instance.Serialize(flowinstance)); + + } + [Test] public void Verificate() diff --git a/OpenAuth.WebApi/Controllers/AccessObjsController.cs b/OpenAuth.WebApi/Controllers/AccessObjsController.cs index 31f05081..f45fd438 100644 --- a/OpenAuth.WebApi/Controllers/AccessObjsController.cs +++ b/OpenAuth.WebApi/Controllers/AccessObjsController.cs @@ -13,6 +13,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 7271297e..a9b6b503 100644 --- a/OpenAuth.WebApi/Controllers/ApplicationsController.cs +++ b/OpenAuth.WebApi/Controllers/ApplicationsController.cs @@ -11,6 +11,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 6f888928..daad4877 100644 --- a/OpenAuth.WebApi/Controllers/BuilderTableColumnsController.cs +++ b/OpenAuth.WebApi/Controllers/BuilderTableColumnsController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 57bd53dd..36db44d8 100644 --- a/OpenAuth.WebApi/Controllers/BuilderTablesController.cs +++ b/OpenAuth.WebApi/Controllers/BuilderTablesController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 b3c0e817..e77880bc 100644 --- a/OpenAuth.WebApi/Controllers/CategoryTypesController.cs +++ b/OpenAuth.WebApi/Controllers/CategoryTypesController.cs @@ -13,6 +13,7 @@ using OpenAuth.App.Response; /// [Route("api/[controller]/[action]")] [ApiController] + [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 44e61b68..662fe648 100644 --- a/OpenAuth.WebApi/Controllers/CategorysController.cs +++ b/OpenAuth.WebApi/Controllers/CategorysController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 45ed0902..7fa488b6 100644 --- a/OpenAuth.WebApi/Controllers/CheckController.cs +++ b/OpenAuth.WebApi/Controllers/CheckController.cs @@ -32,6 +32,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [ApiExplorerSettings(GroupName = "Check")] public class CheckController : ControllerBase { private readonly IAuth _authUtil; diff --git a/OpenAuth.WebApi/Controllers/DataPrivilegeRulesController.cs b/OpenAuth.WebApi/Controllers/DataPrivilegeRulesController.cs index 5a879afb..a8987992 100644 --- a/OpenAuth.WebApi/Controllers/DataPrivilegeRulesController.cs +++ b/OpenAuth.WebApi/Controllers/DataPrivilegeRulesController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 0efcc459..7d63bed6 100644 --- a/OpenAuth.WebApi/Controllers/FilesController.cs +++ b/OpenAuth.WebApi/Controllers/FilesController.cs @@ -18,6 +18,7 @@ namespace OpenAuth.WebApi.Controllers [Route("api/[controller]/[action]")] [ApiController] + [ApiExplorerSettings(GroupName = "Files")] public class FilesController :ControllerBase { diff --git a/OpenAuth.WebApi/Controllers/FlowInstancesController.cs b/OpenAuth.WebApi/Controllers/FlowInstancesController.cs index 47cfbc61..d5eec81a 100644 --- a/OpenAuth.WebApi/Controllers/FlowInstancesController.cs +++ b/OpenAuth.WebApi/Controllers/FlowInstancesController.cs @@ -22,6 +22,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 d2269ce1..cd5e6082 100644 --- a/OpenAuth.WebApi/Controllers/FlowSchemesController.cs +++ b/OpenAuth.WebApi/Controllers/FlowSchemesController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 fd15d629..50d1f9a3 100644 --- a/OpenAuth.WebApi/Controllers/FormsController.cs +++ b/OpenAuth.WebApi/Controllers/FormsController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 20229566..79fedaf3 100644 --- a/OpenAuth.WebApi/Controllers/ModulesController.cs +++ b/OpenAuth.WebApi/Controllers/ModulesController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 36351190..7a6282ef 100644 --- a/OpenAuth.WebApi/Controllers/OpenJobsController.cs +++ b/OpenAuth.WebApi/Controllers/OpenJobsController.cs @@ -16,6 +16,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 bfd6eb73..07cd5cc7 100644 --- a/OpenAuth.WebApi/Controllers/OrgsController.cs +++ b/OpenAuth.WebApi/Controllers/OrgsController.cs @@ -11,6 +11,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 d5607804..6ad7e65e 100644 --- a/OpenAuth.WebApi/Controllers/ResourcesController.cs +++ b/OpenAuth.WebApi/Controllers/ResourcesController.cs @@ -17,6 +17,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 a7bc5d94..a1e69a74 100644 --- a/OpenAuth.WebApi/Controllers/RolesController.cs +++ b/OpenAuth.WebApi/Controllers/RolesController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 a7c856f0..535d8911 100644 --- a/OpenAuth.WebApi/Controllers/SysConfController.cs +++ b/OpenAuth.WebApi/Controllers/SysConfController.cs @@ -11,6 +11,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 34ade206..ed849a84 100644 --- a/OpenAuth.WebApi/Controllers/SysLogsController.cs +++ b/OpenAuth.WebApi/Controllers/SysLogsController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 55f0970e..0d0f88d4 100644 --- a/OpenAuth.WebApi/Controllers/SysMessagesController.cs +++ b/OpenAuth.WebApi/Controllers/SysMessagesController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 aa9c0352..27db6e74 100644 --- a/OpenAuth.WebApi/Controllers/UsersController.cs +++ b/OpenAuth.WebApi/Controllers/UsersController.cs @@ -12,7 +12,8 @@ namespace OpenAuth.WebApi.Controllers /// 用户操作 /// [Route("api/[controller]/[action]")] - [ApiController] + [ApiController] + [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 91810e24..1cc88ab8 100644 --- a/OpenAuth.WebApi/Controllers/WmsInboundOrderDtblsController.cs +++ b/OpenAuth.WebApi/Controllers/WmsInboundOrderDtblsController.cs @@ -15,6 +15,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [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 8e718117..08bcf3a4 100644 --- a/OpenAuth.WebApi/Controllers/WmsInboundOrderTblsController.cs +++ b/OpenAuth.WebApi/Controllers/WmsInboundOrderTblsController.cs @@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers /// [Route("api/[controller]/[action]")] [ApiController] + [ApiExplorerSettings(GroupName = "WmsInboundOrderTbls")] public class WmsInboundOrderTblsController : ControllerBase { private readonly WmsInboundOrderTblApp _app; diff --git a/OpenAuth.WebApi/Model/TagByApiExplorerSettingsOperationFilter.cs b/OpenAuth.WebApi/Model/TagByApiExplorerSettingsOperationFilter.cs new file mode 100644 index 00000000..f6db838f --- /dev/null +++ b/OpenAuth.WebApi/Model/TagByApiExplorerSettingsOperationFilter.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace OpenAuth.WebApi.Model +{ + public class TagByApiExplorerSettingsOperationFilter : IOperationFilter + { + public void Apply(OpenApiOperation operation, OperationFilterContext context) + { + if (context.ApiDescription.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor) + { + var apiExplorerSettings = controllerActionDescriptor + .ControllerTypeInfo.GetCustomAttributes(typeof(ApiExplorerSettingsAttribute), true) + .Cast().FirstOrDefault(); + if (apiExplorerSettings != null && !string.IsNullOrWhiteSpace(apiExplorerSettings.GroupName)) + { + operation.Tags = new List {new OpenApiTag {Name = apiExplorerSettings.GroupName}}; + } + else + { + operation.Tags = new List + {new OpenApiTag {Name = controllerActionDescriptor.ControllerName}}; + } + } + + } + } +} \ No newline at end of file diff --git a/OpenAuth.WebApi/Startup.cs b/OpenAuth.WebApi/Startup.cs index 623ff968..ee35ab65 100644 --- a/OpenAuth.WebApi/Startup.cs +++ b/OpenAuth.WebApi/Startup.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using Autofac; using IdentityServer4.AccessTokenValidation; using Infrastructure; @@ -35,22 +36,21 @@ namespace OpenAuth.WebApi Environment = environment; } + // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.Configure(options => - { - options.SuppressModelStateInvalidFilter = true; - }); - + services.Configure(options => { options.SuppressModelStateInvalidFilter = true; }); + services.AddSingleton(provider => { var service = provider.GetRequiredService>(); return new StartupLogger(service); }); var logger = services.BuildServiceProvider().GetRequiredService(); - - var identityServer = ((ConfigurationSection)Configuration.GetSection("AppSetting:IdentityServerUrl")).Value; + + var identityServer = + ((ConfigurationSection) Configuration.GetSection("AppSetting:IdentityServerUrl")).Value; if (!string.IsNullOrEmpty(identityServer)) { services.AddAuthorization(); @@ -59,26 +59,29 @@ namespace OpenAuth.WebApi .AddJwtBearer(options => { options.Authority = identityServer; - options.RequireHttpsMetadata = false; // 指定是否为HTTPS + options.RequireHttpsMetadata = false; // 指定是否为HTTPS options.Audience = "openauthapi"; - }); + }); } - + //添加swagger services.AddSwaggerGen(option => { - option.SwaggerDoc("v1", new OpenApiInfo + foreach (var controller in GetControllers()) { - Version = "v1", - Title = " OpenAuth.WebApi", - Description = "by yubaolee" - }); - + option.SwaggerDoc(controller.Name.Replace("Controller", ""), new OpenApiInfo + { + Version = "v1", + Title = controller.Name.Replace("Controller", ""), + Description = "by yubaolee" + }); + } + logger.LogInformation($"api doc basepath:{AppContext.BaseDirectory}"); foreach (var name in Directory.GetFiles(AppContext.BaseDirectory, "*.*", - SearchOption.AllDirectories).Where(f =>Path.GetExtension(f).ToLower() == ".xml")) + SearchOption.AllDirectories).Where(f => Path.GetExtension(f).ToLower() == ".xml")) { - option.IncludeXmlComments(name,includeControllerXmlComments:true); + option.IncludeXmlComments(name, includeControllerXmlComments: true); // logger.LogInformation($"find api file{name}"); } @@ -98,21 +101,16 @@ namespace OpenAuth.WebApi AuthorizationUrl = new Uri($"{identityServer}/connect/authorize"), Scopes = new Dictionary { - { "openauthapi", "同意openauth.webapi 的访问权限" }//指定客户端请求的api作用域。 如果为空,则客户端无法访问 + {"openauthapi", "同意openauth.webapi 的访问权限"} //指定客户端请求的api作用域。 如果为空,则客户端无法访问 } } } }); option.OperationFilter(); } - - }); services.Configure(Configuration.GetSection("AppSetting")); - services.AddControllers(option => - { - option.Filters.Add< OpenAuthFilter>(); - }).AddNewtonsoftJson(options => + services.AddControllers(option => { option.Filters.Add(); }).AddNewtonsoftJson(options => { //忽略循环引用 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; @@ -140,7 +138,7 @@ namespace OpenAuth.WebApi // policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().WithOrigins(origins))); //在startup里面只能通过这种方式获取到appsettings里面的值,不能用IOptions😰 - var dbtypes = ((ConfigurationSection)Configuration.GetSection("AppSetting:DbTypes")).GetChildren() + var dbtypes = ((ConfigurationSection) Configuration.GetSection("AppSetting:DbTypes")).GetChildren() .ToDictionary(x => x.Key, x => x.Value); var connectionString = Configuration.GetConnectionString("OpenAuthDBContext"); logger.LogInformation($"系统配置的数据库类型:{JsonHelper.Instance.Serialize(dbtypes)},连接字符串:{connectionString}"); @@ -149,12 +147,21 @@ namespace OpenAuth.WebApi services.AddHttpClient(); 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); @@ -164,7 +171,7 @@ namespace OpenAuth.WebApi public void Configure(IApplicationBuilder app, IHostEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddLog4Net(); - + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); @@ -181,36 +188,37 @@ namespace OpenAuth.WebApi } }; app.UseStaticFiles(staticfile); - + //todo:测试可以允许任意跨域,正式环境要加权限 app.UseCors(builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); - + app.UseRouting(); app.UseAuthentication(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - + + app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); + //配置ServiceProvider AutofacContainerModule.ConfigServiceProvider(app.ApplicationServices); - app.UseSwagger(); + app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { - c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs"); + foreach (var controller in GetControllers()) + { + c.SwaggerEndpoint($"/swagger/{controller.Name.Replace("Controller", "")}/swagger.json", + controller.Name.Replace("Controller", "")); + } + c.DocExpansion(DocExpansion.None); - c.OAuthClientId("OpenAuth.WebApi"); //oauth客户端名称 + c.OAuthClientId("OpenAuth.WebApi"); //oauth客户端名称 c.OAuthAppName("开源版webapi认证"); // 描述 }); - } } -} +} \ No newline at end of file diff --git a/OpenAuth.WebApi/appsettings.json b/OpenAuth.WebApi/appsettings.json index 3395c267..7dac34fd 100644 --- a/OpenAuth.WebApi/appsettings.json +++ b/OpenAuth.WebApi/appsettings.json @@ -7,7 +7,7 @@ "AllowedHosts": "*", "DataProtection": "temp-keys/", "ConnectionStrings": { - "OpenAuthDBContext": "Data Source=.;Initial Catalog=OpenAuthDB;User=sa;Password=000000" + "OpenAuthDBContext": "Data Source=.;Initial Catalog=OpenAuthPro;User=sa;Password=000000" //"OpenAuthDBContext2": "DATA SOURCE=192.168.0.118:1521/YUBAO;PASSWORD=000000;Validate Connection=true;PERSIST SECURITY INFO=True;USER ID=yubaolee;" //Oracle //"OpenAuthDBContext3": "server=127.0.0.1;user id=root;database=openauthpro;password=000000" //my sql },