添加swagger 文档不显示配置

This commit is contained in:
zenghongyao 2025-06-19 11:36:07 +08:00
parent 23e5dab2d0
commit 1e5d8508e7
4 changed files with 21 additions and 7 deletions

View File

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

View File

@ -159,18 +159,22 @@ public partial class IoTHttpApiHostModule
var configuration = context.Services.GetConfiguration();
var groupNames = EnumExtensions.GetEnumTypeValueNameList<SwaggerGroupEnum>();
var excludeSwaggerGroups = configuration.GetSection("ExcludeSwaggerGroup").Get<List<string>>() ?? new List<string>();
groupNames.ForEach(group =>
{
options.SwaggerDoc(group.Key,
new OpenApiInfo { Title = group.Value, Version = "v1"});
if (!excludeSwaggerGroups.Where(e => e == group.Key).Any())
{
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.SchemaFilter<EnumSchemaFilter>();
// 加载所有xml注释这里会导致swagger加载有点缓慢

View File

@ -73,11 +73,15 @@ namespace JiShe.IoT
app.UseAbpSwaggerUI(options =>
{
var groupNames = EnumExtensions.GetEnumTypeValueNameList<SwaggerGroupEnum>();
var excludeSwaggerGroups = configuration.GetSection("ExcludeSwaggerGroup").Get<List<string>>() ?? new List<string>();
groupNames.ForEach(attr => {
options.SwaggerEndpoint($"/swagger/{attr.Key}/swagger.json", attr.Value);
if (!excludeSwaggerGroups.Where(e => e == attr.Key).Any())
{
options.SwaggerEndpoint($"/swagger/{attr.Key}/swagger.json", attr.Value);
}
});
//options.SwaggerEndpoint("/swagger/AbpPro/swagger.json", "AbpPro API");
options.DocExpansion(DocExpansion.None);

View File

@ -32,5 +32,11 @@
"App": {
"SelfUrl": "http://localhost:44315",
"CorsOrigins": "https://*.IoT.com,http://localhost:4200,http://localhost:3100"
}
},
"ExcludeSwaggerGroup": [
"FileManagement",
"NotificationManagement",
"CodeManagement",
"TemplateManagement"
] // Swagger
}