fix issue #I3ODI5 swagger增加分组的功能

fix issue #I3PE3R 会签节点异常,提示'-1' was not present in ...
fix CodeSmith生成的后端代码报错 https://gitee.com/yubaolee/OpenAuth.Core/issues/I3OXJZ
This commit is contained in:
yubaolee 2021-05-07 23:38:53 +08:00
parent 4148427f1a
commit 2834a62fc7
30 changed files with 140 additions and 53 deletions

View File

@ -28,7 +28,9 @@ namespace OpenAuth.WebApi.Controllers
{ {
private readonly <%=ModuleName%>App _app; private readonly <%=ModuleName%>App _app;
//获取详情 /// <summary>
/// //获取详情
/// </summary>
[HttpGet] [HttpGet]
public Response<<%=ModuleName%>> Get(string id) public Response<<%=ModuleName%>> Get(string id)
{ {
@ -46,7 +48,9 @@ namespace OpenAuth.WebApi.Controllers
return result; return result;
} }
//添加 /// <summary>
/// 添加
/// </summary>
[HttpPost] [HttpPost]
public Response Add(AddOrUpdate<%=ModuleName%>Req obj) public Response Add(AddOrUpdate<%=ModuleName%>Req obj)
{ {
@ -65,7 +69,9 @@ namespace OpenAuth.WebApi.Controllers
return result; return result;
} }
//修改 /// <summary>
/// 修改
/// </summary>
[HttpPost] [HttpPost]
public Response Update(AddOrUpdate<%=ModuleName%>Req obj) public Response Update(AddOrUpdate<%=ModuleName%>Req obj)
{ {

View File

@ -36,9 +36,13 @@ namespace OpenAuth.Mvc.Controllers
return View(); return View();
} }
//添加或修改 /// <summary>
/// MVC界面添加
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
[HttpPost] [HttpPost]
public string Add(<%=ModuleName%> obj) public string Add(AddOrUpdate<%=ModuleName%>Req obj)
{ {
try try
{ {
@ -53,9 +57,13 @@ namespace OpenAuth.Mvc.Controllers
return JsonHelper.Instance.Serialize(Result); return JsonHelper.Instance.Serialize(Result);
} }
//添加或修改 /// <summary>
/// MVC界面修改
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
[HttpPost] [HttpPost]
public string Update(<%=ModuleName%> obj) public string Update(AddOrUpdate<%=ModuleName%>Req obj)
{ {
try try
{ {

View File

@ -449,7 +449,7 @@ namespace OpenAuth.App.Flow
/// <summary> /// <summary>
/// 下一个节点对象 /// 下一个节点对象
/// </summary> /// </summary>
public FlowNode nextNode => Nodes[nextNodeId]; public FlowNode nextNode => nextNodeId != "-1"? Nodes[nextNodeId] : null;
/// <summary> /// <summary>
/// 上一个节点 /// 上一个节点

View File

@ -63,6 +63,15 @@ namespace OpenAuth.App.Test
} }
[Test]
public void GetDetail()
{
var app = _autofacServiceProvider.GetService<FlowInstanceApp>();
var flowinstance = app.GetForVerification("80e9db5f-419b-4b65-a274-abe2660608dd");
Console.WriteLine(JsonHelper.Instance.Serialize(flowinstance));
}
[Test] [Test]
public void Verificate() public void Verificate()

View File

@ -13,6 +13,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "AccessObjs")]
public class AccessObjsController : ControllerBase public class AccessObjsController : ControllerBase
{ {
private readonly RevelanceManagerApp _app; private readonly RevelanceManagerApp _app;

View File

@ -11,6 +11,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "Applications")]
public class ApplicationsController : ControllerBase public class ApplicationsController : ControllerBase
{ {
private readonly AppManager _app; private readonly AppManager _app;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "BuilderTableColumns")]
public class BuilderTableColumnsController : ControllerBase public class BuilderTableColumnsController : ControllerBase
{ {
private readonly BuilderTableColumnApp _app; private readonly BuilderTableColumnApp _app;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "BuilderTables")]
public class BuilderTablesController : ControllerBase public class BuilderTablesController : ControllerBase
{ {
private readonly BuilderTableApp _app; private readonly BuilderTableApp _app;

View File

@ -13,6 +13,7 @@ using OpenAuth.App.Response;
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "CategoryTypes")]
public class CategoryTypesController : ControllerBase public class CategoryTypesController : ControllerBase
{ {
private readonly CategoryTypeApp _app; private readonly CategoryTypeApp _app;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "Categorys")]
public class CategorysController : ControllerBase public class CategorysController : ControllerBase
{ {
private readonly CategoryApp _app; private readonly CategoryApp _app;

View File

@ -32,6 +32,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "Check")]
public class CheckController : ControllerBase public class CheckController : ControllerBase
{ {
private readonly IAuth _authUtil; private readonly IAuth _authUtil;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "DataPrivilegeRules")]
public class DataPrivilegeRulesController : ControllerBase public class DataPrivilegeRulesController : ControllerBase
{ {
private readonly DataPrivilegeRuleApp _app; private readonly DataPrivilegeRuleApp _app;

View File

@ -18,6 +18,7 @@ namespace OpenAuth.WebApi.Controllers
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "Files")]
public class FilesController :ControllerBase public class FilesController :ControllerBase
{ {

View File

@ -22,6 +22,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "FlowInstances")]
public class FlowInstancesController : ControllerBase public class FlowInstancesController : ControllerBase
{ {
private readonly FlowInstanceApp _app; private readonly FlowInstanceApp _app;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "FlowSchemes")]
public class FlowSchemesController : ControllerBase public class FlowSchemesController : ControllerBase
{ {
private readonly FlowSchemeApp _app; private readonly FlowSchemeApp _app;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "Forms")]
public class FormsController : ControllerBase public class FormsController : ControllerBase
{ {
private readonly FormApp _app; private readonly FormApp _app;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "Modules")]
public class ModulesController : ControllerBase public class ModulesController : ControllerBase
{ {
private ModuleManagerApp _app; private ModuleManagerApp _app;

View File

@ -16,6 +16,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "OpenJobs")]
public class OpenJobsController : ControllerBase public class OpenJobsController : ControllerBase
{ {
private readonly OpenJobApp _app; private readonly OpenJobApp _app;

View File

@ -11,6 +11,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "Orgs")]
public class OrgsController : ControllerBase public class OrgsController : ControllerBase
{ {
private readonly OrgManagerApp _app; private readonly OrgManagerApp _app;

View File

@ -17,6 +17,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "Resources")]
public class ResourcesController : ControllerBase public class ResourcesController : ControllerBase
{ {
private readonly ResourceApp _app; private readonly ResourceApp _app;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "Roles")]
public class RolesController : ControllerBase public class RolesController : ControllerBase
{ {
private readonly RoleApp _app; private readonly RoleApp _app;

View File

@ -11,6 +11,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "SysConf")]
public class SysConfController :ControllerBase public class SysConfController :ControllerBase
{ {
private IOptions<AppSetting> _appConfiguration; private IOptions<AppSetting> _appConfiguration;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "SysLogs")]
public class SysLogsController : ControllerBase public class SysLogsController : ControllerBase
{ {
private readonly SysLogApp _app; private readonly SysLogApp _app;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "SysMessages")]
public class SysMessagesController : ControllerBase public class SysMessagesController : ControllerBase
{ {
private readonly SysMessageApp _app; private readonly SysMessageApp _app;

View File

@ -13,6 +13,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "Users")]
public class UsersController : ControllerBase public class UsersController : ControllerBase
{ {
private readonly UserManagerApp _app; private readonly UserManagerApp _app;

View File

@ -15,6 +15,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "WmsInboundOrderDtbls")]
public class WmsInboundOrderDtblsController : ControllerBase public class WmsInboundOrderDtblsController : ControllerBase
{ {
private readonly WmsInboundOrderDtblApp _app; private readonly WmsInboundOrderDtblApp _app;

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary> /// </summary>
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
[ApiExplorerSettings(GroupName = "WmsInboundOrderTbls")]
public class WmsInboundOrderTblsController : ControllerBase public class WmsInboundOrderTblsController : ControllerBase
{ {
private readonly WmsInboundOrderTblApp _app; private readonly WmsInboundOrderTblApp _app;

View File

@ -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<ApiExplorerSettingsAttribute>().FirstOrDefault();
if (apiExplorerSettings != null && !string.IsNullOrWhiteSpace(apiExplorerSettings.GroupName))
{
operation.Tags = new List<OpenApiTag> {new OpenApiTag {Name = apiExplorerSettings.GroupName}};
}
else
{
operation.Tags = new List<OpenApiTag>
{new OpenApiTag {Name = controllerActionDescriptor.ControllerName}};
}
}
}
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using Autofac; using Autofac;
using IdentityServer4.AccessTokenValidation; using IdentityServer4.AccessTokenValidation;
using Infrastructure; using Infrastructure;
@ -35,13 +36,11 @@ namespace OpenAuth.WebApi
Environment = environment; Environment = environment;
} }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.Configure<ApiBehaviorOptions>(options => services.Configure<ApiBehaviorOptions>(options => { options.SuppressModelStateInvalidFilter = true; });
{
options.SuppressModelStateInvalidFilter = true;
});
services.AddSingleton(provider => services.AddSingleton(provider =>
{ {
@ -50,7 +49,8 @@ namespace OpenAuth.WebApi
}); });
var logger = services.BuildServiceProvider().GetRequiredService<StartupLogger>(); var logger = services.BuildServiceProvider().GetRequiredService<StartupLogger>();
var identityServer = ((ConfigurationSection)Configuration.GetSection("AppSetting:IdentityServerUrl")).Value; var identityServer =
((ConfigurationSection) Configuration.GetSection("AppSetting:IdentityServerUrl")).Value;
if (!string.IsNullOrEmpty(identityServer)) if (!string.IsNullOrEmpty(identityServer))
{ {
services.AddAuthorization(); services.AddAuthorization();
@ -64,15 +64,18 @@ namespace OpenAuth.WebApi
}); });
} }
//添加swagger
services.AddSwaggerGen(option => services.AddSwaggerGen(option =>
{ {
option.SwaggerDoc("v1", new OpenApiInfo foreach (var controller in GetControllers())
{
option.SwaggerDoc(controller.Name.Replace("Controller", ""), new OpenApiInfo
{ {
Version = "v1", Version = "v1",
Title = " OpenAuth.WebApi", Title = controller.Name.Replace("Controller", ""),
Description = "by yubaolee" Description = "by yubaolee"
}); });
}
logger.LogInformation($"api doc basepath:{AppContext.BaseDirectory}"); logger.LogInformation($"api doc basepath:{AppContext.BaseDirectory}");
foreach (var name in Directory.GetFiles(AppContext.BaseDirectory, "*.*", foreach (var name in Directory.GetFiles(AppContext.BaseDirectory, "*.*",
@ -105,14 +108,9 @@ namespace OpenAuth.WebApi
}); });
option.OperationFilter<AuthResponsesOperationFilter>(); option.OperationFilter<AuthResponsesOperationFilter>();
} }
}); });
services.Configure<AppSetting>(Configuration.GetSection("AppSetting")); services.Configure<AppSetting>(Configuration.GetSection("AppSetting"));
services.AddControllers(option => services.AddControllers(option => { option.Filters.Add<OpenAuthFilter>(); }).AddNewtonsoftJson(options =>
{
option.Filters.Add< OpenAuthFilter>();
}).AddNewtonsoftJson(options =>
{ {
//忽略循环引用 //忽略循环引用
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
@ -152,7 +150,16 @@ namespace OpenAuth.WebApi
//设置定时启动的任务 //设置定时启动的任务
services.AddHostedService<QuartzService>(); services.AddHostedService<QuartzService>();
}
private List<Type> 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) public void ConfigureContainer(ContainerBuilder builder)
@ -191,10 +198,7 @@ namespace OpenAuth.WebApi
app.UseRouting(); app.UseRouting();
app.UseAuthentication(); app.UseAuthentication();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
{
endpoints.MapControllers();
});
//配置ServiceProvider //配置ServiceProvider
AutofacContainerModule.ConfigServiceProvider(app.ApplicationServices); AutofacContainerModule.ConfigServiceProvider(app.ApplicationServices);
@ -205,12 +209,16 @@ namespace OpenAuth.WebApi
// specifying the Swagger JSON endpoint. // specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c => 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.DocExpansion(DocExpansion.None);
c.OAuthClientId("OpenAuth.WebApi"); //oauth客户端名称 c.OAuthClientId("OpenAuth.WebApi"); //oauth客户端名称
c.OAuthAppName("开源版webapi认证"); // 描述 c.OAuthAppName("开源版webapi认证"); // 描述
}); });
} }
} }
} }

View File

@ -7,7 +7,7 @@
"AllowedHosts": "*", "AllowedHosts": "*",
"DataProtection": "temp-keys/", "DataProtection": "temp-keys/",
"ConnectionStrings": { "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 //"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 //"OpenAuthDBContext3": "server=127.0.0.1;user id=root;database=openauthpro;password=000000" //my sql
}, },