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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,6 +14,7 @@ namespace OpenAuth.WebApi.Controllers
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
[ApiExplorerSettings(GroupName = "WmsInboundOrderTbls")]
public class WmsInboundOrderTblsController : ControllerBase
{
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.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<ApiBehaviorOptions>(options =>
{
options.SuppressModelStateInvalidFilter = true;
});
services.Configure<ApiBehaviorOptions>(options => { options.SuppressModelStateInvalidFilter = true; });
services.AddSingleton(provider =>
{
var service = provider.GetRequiredService<ILogger<StartupLogger>>();
return new StartupLogger(service);
});
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))
{
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<string, string>
{
{ "openauthapi", "同意openauth.webapi 的访问权限" }//指定客户端请求的api作用域。 如果为空,则客户端无法访问
{"openauthapi", "同意openauth.webapi 的访问权限"} //指定客户端请求的api作用域。 如果为空,则客户端无法访问
}
}
}
});
option.OperationFilter<AuthResponsesOperationFilter>();
}
});
services.Configure<AppSetting>(Configuration.GetSection("AppSetting"));
services.AddControllers(option =>
{
option.Filters.Add< OpenAuthFilter>();
}).AddNewtonsoftJson(options =>
services.AddControllers(option => { option.Filters.Add<OpenAuthFilter>(); }).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<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)
{
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认证"); // 描述
});
}
}
}
}

View File

@ -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
},