swagger 预备修改调整
continuous-integration/drone/push Build is passing Details

IRC_NewDev
hang 2024-10-15 00:14:34 +08:00
parent 8e2904c541
commit a81f05dcc7
6 changed files with 294 additions and 149 deletions

View File

@ -108,7 +108,7 @@ builder.Services.AddEFSetup(_configuration, enviromentName);
//Http 响应压缩
builder.Services.AddResponseCompressionSetup();
//Swagger Api 文档
builder.Services.AddSwaggerSetup();
builder.Services.AddSwaggerSetupOld();
//JWT Token 验证
builder.Services.AddJWTAuthSetup(_configuration);
@ -243,7 +243,7 @@ app.UseLogDashboard("/LogDashboard");
app.UseHangfireConfig(env);
// Swagger
SwaggerSetup.Configure(app, env);
SwaggerSetup.ConfigureOld(app, env);
//serilog 记录请求的用户信息
app.UseSerilogConfig(env);

View File

@ -1,140 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.Filters;
using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
namespace IRaCIS.Core.API
{
public static class SwaggerSetup
{
public static void AddSwaggerSetup(this IServiceCollection services)
{
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options =>
{
//此处的Name 是控制器上分组的名称 Title是界面的大标题
//分组
options.SwaggerDoc("Reviewer", new OpenApiInfo { Title = "医生模块", Version = "Reviewer", });
options.SwaggerDoc("Trial", new OpenApiInfo { Title = "项目模块", Version = "Trial" });
options.SwaggerDoc("Enroll", new OpenApiInfo { Title = "入组模块", Version = "Enroll" });
options.SwaggerDoc("Workload", new OpenApiInfo { Title = "工作量模块", Version = "Workload" });
options.SwaggerDoc("Common", new OpenApiInfo { Title = "通用信息获取", Version = "Common" });
options.SwaggerDoc("Institution", new OpenApiInfo { Title = "机构信息模块", Version = "Institution" });
options.SwaggerDoc("Dashboard&Statistics", new OpenApiInfo { Title = "统计模块", Version = "Dashboard&Statistics" });
options.SwaggerDoc("Financial", new OpenApiInfo { Title = "财务模块", Version = "Financial" });
options.SwaggerDoc("Management", new OpenApiInfo { Title = "管理模块", Version = "Management" });
options.SwaggerDoc("Image", new OpenApiInfo { Title = "影像模块", Version = "Image" });
options.SwaggerDoc("Reading", new OpenApiInfo { Title = "读片模块", Version = "Reading" });
// Add "General" fallback group for ungrouped APIs
//options.SwaggerDoc("General", new OpenApiInfo { Title = "未分类模块", Version = "General" });
// 接口排序
options.OrderActionsBy(o => o.GroupName);
options.DocInclusionPredicate((docName, apiDes) =>
{
if (!apiDes.TryGetMethodInfo(out MethodInfo methodInfo)) return false;
var versions = methodInfo.DeclaringType.GetCustomAttributes(true)
.OfType<ApiExplorerSettingsAttribute>()
.Select(attr => attr.GroupName);
//return versions.Any(v => v == docName) || (docName == "General" && !versions.Any());
return versions.Any(v => v.ToString() == docName);
});
var xmlPath = Path.Combine(AppContext.BaseDirectory, "IRaCIS.Core.API.xml");//这个就是刚刚配置的xml文件名
options.IncludeXmlComments(xmlPath, true);
var xmlPath2 = Path.Combine(AppContext.BaseDirectory, "IRaCIS.Core.Application.xml");//这个就是刚刚配置的xml文件名
options.IncludeXmlComments(xmlPath2, true);
//默认的第二个参数是false这个是controller的注释记得修改
// 在header中添加token传递到后台
options.OperationFilter<SecurityRequirementsOperationFilter>();
// 添加登录按钮
options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme()
{
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
Name = "Authorization",
//In = "header",
//Type = "apiKey"
});
//// Bearer
//options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
//{
// Description = "JWT Authorization header using the Bearer scheme.",
// Name = "Authorization",
// In = ParameterLocation.Header,
// Scheme = "bearer",
// Type = SecuritySchemeType.Http,
// BearerFormat = "JWT"
//});
});
}
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(options =>
{
//此处的Name 是页面 选择文档下拉框 显示的名称
options.SwaggerEndpoint($"swagger/Reviewer/swagger.json", "医生模块");
options.SwaggerEndpoint($"swagger/Trial/swagger.json", "项目模块");
options.SwaggerEndpoint($"swagger/Enroll/swagger.json", "入组模块");
options.SwaggerEndpoint($"swagger/Workload/swagger.json", "工作量模块");
options.SwaggerEndpoint($"swagger/Dashboard&Statistics/swagger.json", "统计模块");
options.SwaggerEndpoint($"swagger/Common/swagger.json", "通用模块");
options.SwaggerEndpoint($"swagger/Financial/swagger.json", "财务模块");
options.SwaggerEndpoint($"swagger/Institution/swagger.json", "机构信息模块");
options.SwaggerEndpoint($"swagger/Management/swagger.json", "管理模块");
options.SwaggerEndpoint($"swagger/Image/swagger.json", "影像模块");
options.SwaggerEndpoint($"swagger/Reading/swagger.json", "读片模块");
//路径配置设置为空表示直接在根域名localhost:8001访问该文件,
//注意localhost:8001/swagger是访问不到的去launchSettings.json把launchUrl去掉如果你想换一个路径直接写名字即可比如直接写c.Route = "doc";
//options.RoutePrefix = string.Empty;
var data = Assembly.GetExecutingAssembly().Location;
options.IndexStream = () => Assembly.GetExecutingAssembly()
.GetManifestResourceStream("IRaCIS.Core.API.wwwroot.swagger.ui.Index.html");
options.RoutePrefix = string.Empty;
//DocExpansion设置为none可折叠所有方法
options.DocExpansion(DocExpansion.None);
//DefaultModelsExpandDepth设置为 - 1 可不显示models
options.DefaultModelsExpandDepth(-1);
// 引入静态文件添加登录功能
// 清除静态文件缓存
// options.IndexStream = () => null;
});
}
}
}

View File

@ -0,0 +1,255 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.Filters;
using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI;
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
namespace IRaCIS.Core.API;
public enum SwaggerVersion
{
[Description("医生模块")]
Reviewer = 1,
[Description("项目模块")]
Trial = 2,
[Description("入组模块")]
Enroll = 3,
[Description("工作量模块")]
Workload = 4,
[Description("通用信息获取")]
Common = 5,
[Description("机构信息模块")]
Institution = 6,
[Description("统计模块")]
DashboardStatistics = 7,
[Description("财务模块")]
Financial = 8,
[Description("管理模块")]
Management =9,
[Description("影像模块")]
Image =10,
[Description("读片模块")]
Reading =11
};
public static class SwaggerSetup
{
public static void AddSwaggerSetupOld(this IServiceCollection services)
{
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options =>
{
//此处的Name 是控制器上分组的名称 Title是界面的大标题
//分组
options.SwaggerDoc("Reviewer", new OpenApiInfo { Title = "医生模块", Version = "Reviewer", });
options.SwaggerDoc("Trial", new OpenApiInfo { Title = "项目模块", Version = "Trial" });
options.SwaggerDoc("Enroll", new OpenApiInfo { Title = "入组模块", Version = "Enroll" });
options.SwaggerDoc("Workload", new OpenApiInfo { Title = "工作量模块", Version = "Workload" });
options.SwaggerDoc("Common", new OpenApiInfo { Title = "通用信息获取", Version = "Common" });
options.SwaggerDoc("Institution", new OpenApiInfo { Title = "机构信息模块", Version = "Institution" });
options.SwaggerDoc("Dashboard&Statistics", new OpenApiInfo { Title = "统计模块", Version = "Dashboard&Statistics" });
options.SwaggerDoc("Financial", new OpenApiInfo { Title = "财务模块", Version = "Financial" });
options.SwaggerDoc("Management", new OpenApiInfo { Title = "管理模块", Version = "Management" });
options.SwaggerDoc("Image", new OpenApiInfo { Title = "影像模块", Version = "Image" });
options.SwaggerDoc("Reading", new OpenApiInfo { Title = "读片模块", Version = "Reading" });
// Add "General" fallback group for ungrouped APIs
//options.SwaggerDoc("General", new OpenApiInfo { Title = "未分类模块", Version = "General" });
// 接口排序
options.OrderActionsBy(o => o.GroupName);
options.DocInclusionPredicate((docName, apiDes) =>
{
if (!apiDes.TryGetMethodInfo(out MethodInfo methodInfo)) return false;
var versions = methodInfo.DeclaringType.GetCustomAttributes(true)
.OfType<ApiExplorerSettingsAttribute>()
.Select(attr => attr.GroupName);
//return versions.Any(v => v == docName) || (docName == "General" && !versions.Any());
return versions.Any(v => v.ToString() == docName);
});
var xmlPath = Path.Combine(AppContext.BaseDirectory, "IRaCIS.Core.API.xml");//这个就是刚刚配置的xml文件名
options.IncludeXmlComments(xmlPath, true);
var xmlPath2 = Path.Combine(AppContext.BaseDirectory, "IRaCIS.Core.Application.xml");//这个就是刚刚配置的xml文件名
options.IncludeXmlComments(xmlPath2, true);
//默认的第二个参数是false这个是controller的注释记得修改
// 在header中添加token传递到后台
options.OperationFilter<SecurityRequirementsOperationFilter>();
// 添加登录按钮
options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme()
{
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
Name = "Authorization",
//In = "header",
//Type = "apiKey"
});
//// Bearer
//options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
//{
// Description = "JWT Authorization header using the Bearer scheme.",
// Name = "Authorization",
// In = ParameterLocation.Header,
// Scheme = "bearer",
// Type = SecuritySchemeType.Http,
// BearerFormat = "JWT"
//});
});
}
public static void ConfigureOld(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(options =>
{
//此处的Name 是页面 选择文档下拉框 显示的名称
options.SwaggerEndpoint($"swagger/Reviewer/swagger.json", "医生模块");
options.SwaggerEndpoint($"swagger/Trial/swagger.json", "项目模块");
options.SwaggerEndpoint($"swagger/Enroll/swagger.json", "入组模块");
options.SwaggerEndpoint($"swagger/Workload/swagger.json", "工作量模块");
options.SwaggerEndpoint($"swagger/Dashboard&Statistics/swagger.json", "统计模块");
options.SwaggerEndpoint($"swagger/Common/swagger.json", "通用模块");
options.SwaggerEndpoint($"swagger/Financial/swagger.json", "财务模块");
options.SwaggerEndpoint($"swagger/Institution/swagger.json", "机构信息模块");
options.SwaggerEndpoint($"swagger/Management/swagger.json", "管理模块");
options.SwaggerEndpoint($"swagger/Image/swagger.json", "影像模块");
options.SwaggerEndpoint($"swagger/Reading/swagger.json", "读片模块");
//路径配置设置为空表示直接在根域名localhost:8001访问该文件,
//注意localhost:8001/swagger是访问不到的去launchSettings.json把launchUrl去掉如果你想换一个路径直接写名字即可比如直接写c.Route = "doc";
//options.RoutePrefix = string.Empty;
var data = Assembly.GetExecutingAssembly().Location;
options.IndexStream = () => Assembly.GetExecutingAssembly()
.GetManifestResourceStream("IRaCIS.Core.API.wwwroot.swagger.ui.Index.html");
options.RoutePrefix = string.Empty;
//DocExpansion设置为none可折叠所有方法
options.DocExpansion(DocExpansion.None);
//DefaultModelsExpandDepth设置为 - 1 可不显示models
options.DefaultModelsExpandDepth(-1);
// 引入静态文件添加登录功能
// 清除静态文件缓存
// options.IndexStream = () => null;
});
}
public static void AddSwaggerSetup(this IServiceCollection services)
{
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options =>
{
//多版本
#region old
//typeof(SwaggerVersion).GetEnumNames().ToList().ForEach(v =>
//{
// options.SwaggerDoc(v, new Microsoft.OpenApi.Models.OpenApiInfo
// {
// Version = v,
// Description = $"{v} API",
// Title = v,
// });
//});
#endregion
typeof(SwaggerVersion).GetFields(BindingFlags.Public | BindingFlags.Static).ToList()
.ForEach(field =>
{
var description = field.GetCustomAttribute<DescriptionAttribute>()?.Description ?? field.Name;
options.SwaggerDoc(field.Name, new Microsoft.OpenApi.Models.OpenApiInfo
{
Version = field.Name,
Description = $"{field.Name} API",
Title = description // 使用Description作为Title
});
});
//添加注释
var basePath = AppContext.BaseDirectory;
var xmlPath1 = Path.Combine(basePath, "IRaCIS.Core.Application.xml");
var xmlPath2 = Path.Combine(basePath, "IRaCIS.Core.API.xml");
options.IncludeXmlComments(xmlPath1, true);
options.IncludeXmlComments(xmlPath2, true);
// 在header中添加token传递到后台
options.OperationFilter<SecurityRequirementsOperationFilter>();
//// 添加登录按钮
//options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme()
//{
// Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
// Name = "Authorization",
// //In = "header",
// //Type = "apiKey"
//});
});
}
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSwagger();
app.UseSwaggerUI(options =>
{
//typeof(SwaggerVersion).GetEnumNames().ToList().ForEach(v =>
//{
// options.SwaggerEndpoint($"swagger/{v}/swagger.json", $"{v}");
//});
typeof(SwaggerVersion).GetFields(BindingFlags.Public | BindingFlags.Static).ToList()
.ForEach(field =>
{
var description = field.GetCustomAttribute<DescriptionAttribute>()?.Description ?? field.Name;
options.SwaggerEndpoint($"swagger/{field.Name}/swagger.json", $"{description}");
});
options.RoutePrefix = string.Empty;
//var data = Assembly.GetExecutingAssembly().Location;
//options.IndexStream = () => Assembly.GetExecutingAssembly()
//.GetManifestResourceStream("IRaCIS.Core.API.wwwroot.swagger.ui.Index.html");
//DocExpansion设置为none可折叠所有方法
options.DocExpansion(DocExpansion.None);
//DefaultModelsExpandDepth设置为 - 1 可不显示models
options.DefaultModelsExpandDepth(-1);
});
}
}

View File

@ -12763,19 +12763,49 @@
字典仓储
</summary>
</member>
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.TranslationDictionaryDto.DictionaryCode">
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.TranslationDictionaryDto.IsEn_US">
<summary>
是否是英文
</summary>
</member>
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.TranslationDictionaryDto.DictionaryList">
<summary>
字典
</summary>
</member>
<member name="T:IRaCIS.Core.Application.MassTransit.Consumer.DictionaryDto">
<summary>
字典对象
</summary>
</member>
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.DictionaryDto.DictionaryCode">
<summary>
字典Code
</summary>
</member>
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.TranslationDictionaryDto.EnumValue">
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.DictionaryDto.EnumValue">
<summary>
枚举值
</summary>
</member>
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.TranslationDictionaryDto.IsEn_US">
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.DictionaryData.DictionaryCode">
<summary>
是否是英文
字典Code
</summary>
</member>
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.DictionaryData.EnumValue">
<summary>
枚举值
</summary>
</member>
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.DictionaryData.Value">
<summary>
</summary>
</member>
<member name="P:IRaCIS.Core.Application.MassTransit.Consumer.DictionaryData.ValueCN">
<summary>
返回
</summary>
</member>
<member name="M:IRaCIS.Core.Application.MassTransit.Consumer.ConsistencyCheckConsumer.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.DicomStudy},IRaCIS.Core.Domain.Share.IUserInfo,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Subject},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.SubjectVisit},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSite},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.NoneDicomStudy},AutoMapper.IMapper,Microsoft.Extensions.Localization.IStringLocalizer)">
@ -12824,7 +12854,7 @@
加急的医学反馈任务 通知MIM
</summary>
</member>
<member name="M:IRaCIS.Core.Application.MassTransit.Consumer.UrgentMedicalReviewAddedEventConsumer.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.User},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TaskMedicalReview},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingQuestionCriterionTrial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSiteSurvey},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailNoticeConfig},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig})">
<member name="M:IRaCIS.Core.Application.MassTransit.Consumer.UrgentMedicalReviewAddedEventConsumer.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.User},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TaskMedicalReview},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Trial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingQuestionCriterionTrial},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.VisitTask},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.Dictionary},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailNoticeConfig},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig})">
<summary>
加急的医学反馈任务 通知MIM
</summary>

View File

@ -9,7 +9,7 @@ namespace IRaCIS.Core.Application.Service
/// Dashboard统计、全局工作量统计、入组两个维度统计按照项目、按照人
/// </summary>
[ApiExplorerSettings(GroupName = "Dashboard&Statistics")]
[ApiExplorerSettings(GroupName = "DashboardStatistics")]
public class StatisticsService(IRepository<Doctor> _doctorRepository,
IRepository<Trial> _trialRepository,
IRepository<Enroll> _enrollRepository,

View File

@ -41,7 +41,7 @@ namespace IRaCIS.Core.Application.Service
public TestMinimalApiService()
{
RouteHandlerBuilder = t => {
t.WithGroupName("TestMinimalApi").WithOpenApi().WithTags("Institution");
t.WithOpenApi();
};
}