diff --git a/IRaCIS.Core.API/Progranm.cs b/IRaCIS.Core.API/Progranm.cs index 5f3f2b534..c62168c0a 100644 --- a/IRaCIS.Core.API/Progranm.cs +++ b/IRaCIS.Core.API/Progranm.cs @@ -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); diff --git a/IRaCIS.Core.API/_ServiceExtensions/Swagger/SwaggerSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/Swagger/SwaggerSetup.cs deleted file mode 100644 index cb4c21029..000000000 --- a/IRaCIS.Core.API/_ServiceExtensions/Swagger/SwaggerSetup.cs +++ /dev/null @@ -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() - .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(); - - - // 添加登录按钮 - 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; - - - }); - - - } - } -} diff --git a/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs new file mode 100644 index 000000000..2e3361ee2 --- /dev/null +++ b/IRaCIS.Core.API/_ServiceExtensions/SwaggerSetup.cs @@ -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() + .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(); + + + // 添加登录按钮 + 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()?.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(); + + + //// 添加登录按钮 + //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()?.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); + }); + } +} diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 4f04971a8..5114fbdc4 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -12763,19 +12763,49 @@ 字典仓储 - + + + 是否是英文 + + + + + 字典 + + + + + 字典对象 + + + 字典Code - + 枚举值 - + - 是否是英文 + 字典Code + + + + + 枚举值 + + + + + 值 + + + + + 返回 @@ -12824,7 +12854,7 @@ 加急的医学反馈任务 通知MIM - + 加急的医学反馈任务 通知MIM diff --git a/IRaCIS.Core.Application/Service/Stat/StatisticsService.cs b/IRaCIS.Core.Application/Service/Stat/StatisticsService.cs index 087e92b17..2fbe880e8 100644 --- a/IRaCIS.Core.Application/Service/Stat/StatisticsService.cs +++ b/IRaCIS.Core.Application/Service/Stat/StatisticsService.cs @@ -9,7 +9,7 @@ namespace IRaCIS.Core.Application.Service /// Dashboard统计、全局工作量统计、入组两个维度统计(按照项目、按照人) /// - [ApiExplorerSettings(GroupName = "Dashboard&Statistics")] + [ApiExplorerSettings(GroupName = "DashboardStatistics")] public class StatisticsService(IRepository _doctorRepository, IRepository _trialRepository, IRepository _enrollRepository, diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 8207b2ee2..45d23323a 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -41,7 +41,7 @@ namespace IRaCIS.Core.Application.Service public TestMinimalApiService() { RouteHandlerBuilder = t => { - t.WithGroupName("TestMinimalApi").WithOpenApi().WithTags("Institution"); + t.WithOpenApi(); }; }