You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FastEndpoints配置的Swagger摘要不显示,需排查缺失配置

问题解决:FastEndpoints Swagger不显示端点摘要内容

你遗漏了FastEndpoints与Swagger集成的关键配置步骤,具体如下:

1. 安装FastEndpoints官方Swagger集成包

FastEndpoints的摘要信息不会自动被原生Swagger识别,必须安装官方提供的集成包:

dotnet add package FastEndpoints.Swagger

2. 在Swagger配置中启用FastEndpoints支持

修改Program.cs中的AddSwaggerGen配置,添加EnableFastEndpoints()调用,这是让Swagger读取FastEndpoints端点摘要的核心配置:

.AddSwaggerGen(opt =>
{
    opt.SwaggerDoc("v1", new OpenApiInfo { Title = "thing.Forum.Api", Version = "v1" });
    opt.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
    {
        In = ParameterLocation.Header,
        Description = "Please enter token",
        Name = "Authorization",
        Type = SecuritySchemeType.Http,
        BearerFormat = "JWT",
        Scheme = "bearer"
    });

    opt.AddSecurityRequirement(new OpenApiSecurityRequirement
    {
        {
            new OpenApiSecurityScheme
            {
                Reference = new OpenApiReference
                {
                    Type=ReferenceType.SecurityScheme,
                    Id="Bearer"
                }
            },
            Array.Empty<string>()
        }
    });

    // 新增这一行,启用FastEndpoints的Swagger集成
    opt.EnableFastEndpoints();
})

3. 额外检查项

  • 确保你的POCRequest和POCResponse类是public访问修饰符,否则Swagger无法读取类型信息生成示例和描述
  • 确认项目中已正确添加builder.Services.AddFastEndpoints()(而非仅用原生MVC服务),这是FastEndpoints正常工作的基础

内容的提问来源于stack exchange,提问作者WynDiesel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 18:27:13