feat: 完成swagger分组功能
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
|
||||
namespace Yi.Framework.AspNetCore.Microsoft.AspNetCore.Builder
|
||||
{
|
||||
@@ -6,25 +9,26 @@ namespace Yi.Framework.AspNetCore.Microsoft.AspNetCore.Builder
|
||||
{
|
||||
public static IApplicationBuilder UseYiSwagger(this IApplicationBuilder app, params SwaggerModel[] swaggerModels)
|
||||
{
|
||||
var mvcOptions = app.ApplicationServices.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>().Value;
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
// 配置 Swagger UI 面板链接,添加的顺序,就是排序
|
||||
c.SwaggerEndpoint("/swagger/default/swagger.json", "default");
|
||||
c.SwaggerEndpoint("/swagger/rbac/swagger.json", "rbac");
|
||||
|
||||
//if (swaggerModels.Length == 0)
|
||||
//{
|
||||
// c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// foreach (var k in swaggerModels)
|
||||
// {
|
||||
|
||||
// c.SwaggerEndpoint(k.Url, k.Name);
|
||||
// }
|
||||
//}
|
||||
foreach (var setting in mvcOptions.ConventionalControllers.ConventionalControllerSettings)
|
||||
{
|
||||
c.SwaggerEndpoint($"/swagger/{setting.RemoteServiceName}/swagger.json", setting.RemoteServiceName);
|
||||
}
|
||||
if (mvcOptions.ConventionalControllers.ConventionalControllerSettings.Count==0&&swaggerModels.Length == 0)
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var k in swaggerModels)
|
||||
{
|
||||
c.SwaggerEndpoint(k.Url, k.Name);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
return app;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
@@ -9,7 +10,7 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class SwaggerAddExtensions
|
||||
{
|
||||
public static IServiceCollection AddYiSwaggerGen<Program>(this IServiceCollection services, Action<SwaggerGenOptions>? action)
|
||||
public static IServiceCollection AddYiSwaggerGen<Program>(this IServiceCollection services, Action<SwaggerGenOptions>? action=null)
|
||||
{
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var mvcOptions = serviceProvider.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>();
|
||||
@@ -20,11 +21,18 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
services.AddAbpSwaggerGen(
|
||||
options =>
|
||||
{
|
||||
|
||||
// 配置分组,还需要去重
|
||||
foreach (var setting in mvcSettings)
|
||||
if (action is not null)
|
||||
{
|
||||
options.SwaggerDoc(setting.RemoteServiceName, new OpenApiInfo { Title = setting.RemoteServiceName, Version = "v1" });
|
||||
action.Invoke(options);
|
||||
}
|
||||
|
||||
// 配置分组,还需要去重,支持重写,如果外部传入后,将以外部为准
|
||||
foreach (var setting in mvcSettings.OrderBy(x => x.RemoteServiceName))
|
||||
{
|
||||
if (!options.SwaggerGeneratorOptions.SwaggerDocs.ContainsKey(setting.RemoteServiceName))
|
||||
{
|
||||
options.SwaggerDoc(setting.RemoteServiceName, new OpenApiInfo { Title = setting.RemoteServiceName, Version = "v1" });
|
||||
}
|
||||
}
|
||||
|
||||
// 根据分组名称过滤 API 文档
|
||||
@@ -38,10 +46,9 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
return docName == settingOrNull.RemoteServiceName;
|
||||
}
|
||||
}
|
||||
return docName == "default";
|
||||
return false;
|
||||
});
|
||||
|
||||
//options.DocInclusionPredicate((docName, description) => true);
|
||||
options.CustomSchemaIds(type => type.FullName);
|
||||
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
|
||||
if (basePath is not null)
|
||||
@@ -68,12 +75,6 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
[scheme] = new string[0]
|
||||
});
|
||||
|
||||
|
||||
if (action is not null)
|
||||
{
|
||||
action.Invoke(options);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
|
||||
{
|
||||
|
||||
var db = (await _sugarDbContextProvider.GetDbContextAsync()).SqlSugarClient;
|
||||
await Console.Out.WriteLineAsync("获取的id:" + db.ContextID);
|
||||
//await Console.Out.WriteLineAsync("获取的id:" + db.ContextID);
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Yi.Framework.SqlSugarCore
|
||||
{
|
||||
public Task SaveAsync(AuditLogInfo auditInfo)
|
||||
{
|
||||
Console.WriteLine(auditInfo.ExecutionTime);
|
||||
//Console.WriteLine(auditInfo.ExecutionTime);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Yi.Framework.SqlSugarCore.Uow
|
||||
{
|
||||
|
||||
var dbContext = await CreateDbContextAsync(unitOfWork);
|
||||
Console.WriteLine("111111:" + dbContext.SqlSugarClient.ContextID);
|
||||
// Console.WriteLine("111111:" + dbContext.SqlSugarClient.ContextID);
|
||||
return dbContext;
|
||||
}
|
||||
|
||||
@@ -101,14 +101,14 @@ namespace Yi.Framework.SqlSugarCore.Uow
|
||||
unitOfWork.AddTransactionApi(transactionApiKey, transaction);
|
||||
|
||||
|
||||
await Console.Out.WriteLineAsync("开始新的事务");
|
||||
//await Console.Out.WriteLineAsync("开始新的事务");
|
||||
Console.WriteLine(dbContext.SqlSugarClient.ContextID);
|
||||
await dbContext.SqlSugarClient.Ado.BeginTranAsync();
|
||||
return dbContext;
|
||||
}
|
||||
else
|
||||
{
|
||||
await Console.Out.WriteLineAsync("继续老的事务");
|
||||
// await Console.Out.WriteLineAsync("继续老的事务");
|
||||
Console.WriteLine(activeTransaction.DbContext.SqlSugarClient);
|
||||
await activeTransaction.DbContext.SqlSugarClient.Ado.BeginTranAsync();
|
||||
return (TDbContext)activeTransaction.DbContext;
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Yi.Framework.SqlSugarCore
|
||||
{
|
||||
CodeFirst(service);
|
||||
}
|
||||
if (options.EnabledCodeFirst)
|
||||
if (options.EnabledDbSeed)
|
||||
{
|
||||
await DataSeedAsync(service);
|
||||
}
|
||||
@@ -70,9 +70,6 @@ namespace Yi.Framework.SqlSugarCore
|
||||
private void CodeFirst(IServiceProvider service)
|
||||
{
|
||||
|
||||
var options = service.GetRequiredService<IOptions<DbConnOptions>>().Value;
|
||||
if (options.EnabledCodeFirst)
|
||||
{
|
||||
var moduleContainer = service.GetRequiredService<IModuleContainer>();
|
||||
var db = service.GetRequiredService<ISqlSugarDbContext>().SqlSugarClient;
|
||||
|
||||
@@ -85,7 +82,7 @@ namespace Yi.Framework.SqlSugarCore
|
||||
{
|
||||
db.CodeFirst.InitTables(types.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task DataSeedAsync(IServiceProvider service)
|
||||
|
||||
Reference in New Issue
Block a user