调整swagger 分组

This commit is contained in:
zenghongyao 2025-06-18 16:04:41 +08:00
parent 3d3e89ee43
commit f4bab2b711
8 changed files with 55 additions and 8 deletions

View File

@ -2,7 +2,7 @@
<!-- 定义项目加载属性 --> <!-- 定义项目加载属性 -->
<PropertyGroup> <PropertyGroup>
<!--JiShe.ServicePro版本--> <!--JiShe.ServicePro版本-->
<ServiceProVersion>1.0.5.29</ServiceProVersion> <ServiceProVersion>1.0.5.33</ServiceProVersion>
<!--Volo Abp 版本--> <!--Volo Abp 版本-->
<VoloAbpVersion>9.1.1</VoloAbpVersion> <VoloAbpVersion>9.1.1</VoloAbpVersion>

View File

@ -1,8 +1,12 @@
using Hangfire.Redis.StackExchange; using Hangfire.Redis.StackExchange;
using JiShe.ServicePro.Core; using JiShe.ServicePro.Core;
using JiShe.ServicePro.FreeRedisProvider; using JiShe.ServicePro.FreeRedisProvider;
using JiShe.ServicePro.SwaggerConfigs;
using Medallion.Threading; using Medallion.Threading;
using Medallion.Threading.Redis; using Medallion.Threading.Redis;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.CodeAnalysis;
using System.Reflection;
using Volo.Abp.BlobStoring; using Volo.Abp.BlobStoring;
using Volo.Abp.BlobStoring.FileSystem; using Volo.Abp.BlobStoring.FileSystem;
@ -150,9 +154,22 @@ public partial class IoTHttpApiHostModule
// 文件下载类型 // 文件下载类型
options.MapType<FileContentResult>(() => new OpenApiSchema() { Type = "file" }); options.MapType<FileContentResult>(() => new OpenApiSchema() { Type = "file" });
options.SwaggerDoc("AbpPro", //options.SwaggerDoc("AbpPro",
new OpenApiInfo { Title = "AbpPro API", Version = "v1" }); // new OpenApiInfo { Title = "AbpPro API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
var configuration = context.Services.GetConfiguration();
var groupNames = EnumExtensions.GetStringKeyValueList<SwaggerGroupEnum>();
groupNames.ForEach(group =>
{
options.SwaggerDoc(group.Key,
new OpenApiInfo { Title = group.Value, Version = "v1"});
});
options.DocInclusionPredicate((docName, description) => {
return description.GroupName == docName;
});
options.EnableAnnotations(); // 启用注解 options.EnableAnnotations(); // 启用注解
options.DocumentFilter<HiddenAbpDefaultApiFilter>(); options.DocumentFilter<HiddenAbpDefaultApiFilter>();
options.SchemaFilter<EnumSchemaFilter>(); options.SchemaFilter<EnumSchemaFilter>();
@ -163,6 +180,18 @@ public partial class IoTHttpApiHostModule
options.IncludeXmlComments(xml, true); options.IncludeXmlComments(xml, true);
} }
// 加载 模块引入的xml注释
// 加载所有xml注释这里会导致swagger加载有点缓慢
var modulePath = Path.Combine(AppContext.BaseDirectory, "moduleSwagger");
if (Directory.Exists(modulePath))
{
var xmlModulePaths = Directory.GetFiles(modulePath, "*.xml");
foreach (var xml in xmlModulePaths)
{
options.IncludeXmlComments(xml, true);
}
}
options.AddSecurityDefinition(JwtBearerDefaults.AuthenticationScheme, options.AddSecurityDefinition(JwtBearerDefaults.AuthenticationScheme,
new OpenApiSecurityScheme() new OpenApiSecurityScheme()
{ {

View File

@ -1,3 +1,5 @@
using JiShe.ServicePro.SwaggerConfigs;
using System.Reflection;
using Volo.Abp.BlobStoring.FileSystem; using Volo.Abp.BlobStoring.FileSystem;
namespace JiShe.IoT namespace JiShe.IoT
@ -70,7 +72,14 @@ namespace JiShe.IoT
app.UseSwagger(); app.UseSwagger();
app.UseAbpSwaggerUI(options => app.UseAbpSwaggerUI(options =>
{ {
options.SwaggerEndpoint("/swagger/AbpPro/swagger.json", "AbpPro API"); var groupNames = EnumExtensions.GetStringKeyValueList<SwaggerGroupEnum>();
groupNames.ForEach(attr => {
options.SwaggerEndpoint($"/swagger/{attr.Key}/swagger.json", attr.Value);
});
//options.SwaggerEndpoint("/swagger/AbpPro/swagger.json", "AbpPro API");
options.DocExpansion(DocExpansion.None); options.DocExpansion(DocExpansion.None);
options.DefaultModelsExpandDepth(-1); options.DefaultModelsExpandDepth(-1);
}); });

View File

@ -66,4 +66,8 @@
<Content Remove="$(UserProfile)\.nuget\packages\*\*\contentFiles\any\*\*.abppkg*.json" /> <Content Remove="$(UserProfile)\.nuget\packages\*\*\contentFiles\any\*\*.abppkg*.json" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="moduleSwagger\" />
</ItemGroup>
</Project> </Project>

View File

@ -19,11 +19,12 @@
<form class="form-horizontal" method="post"> <form class="form-horizontal" method="post">
@Html.AntiForgeryToken() @Html.AntiForgeryToken()
<span class="heading">后台服务登录</span> <span class="heading">后台服务登录</span>
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" name="userName" placeholder="用户名"> <input type="text" class="form-control" name="userName" value="admin" placeholder="用户名">
</div> </div>
<div class="form-group help"> <div class="form-group help">
<input type="password" class="form-control" name="password" placeholder="密码"> <input type="password" class="form-control" name="password" value="1q2w3E*" placeholder="密码">
</div> </div>
<div class="form-group"> <div class="form-group">
<button type="submit" class="btn btn-default">登录</button> <button type="submit" class="btn btn-default">登录</button>

View File

@ -3,6 +3,8 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>$(DotnetTargetFrameworkVersion)</TargetFramework> <TargetFramework>$(DotnetTargetFrameworkVersion)</TargetFramework>
<RootNamespace>JiShe.IoT</RootNamespace> <RootNamespace>JiShe.IoT</RootNamespace>
<NoWarn>$(NoWarn);1591;1570</NoWarn>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -41,7 +41,7 @@ namespace JiShe.IoT
public override void PostConfigureServices(ServiceConfigurationContext context) public override void PostConfigureServices(ServiceConfigurationContext context)
{ {
// 定时任务 // 定时任务
ConfigureBackgroundJob(context); //ConfigureBackgroundJob(context);
} }
private static void ConfigureBackgroundJob(ServiceConfigurationContext context) private static void ConfigureBackgroundJob(ServiceConfigurationContext context)

View File

@ -2,6 +2,8 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>$(DotnetTargetFrameworkVersion)</TargetFramework> <TargetFramework>$(DotnetTargetFrameworkVersion)</TargetFramework>
<RootNamespace>JiShe.IoT</RootNamespace> <RootNamespace>JiShe.IoT</RootNamespace>
<NoWarn>$(NoWarn);1591;1570</NoWarn>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>