Swagger UI 隐藏 AspNetCore.Mvc.ProblemDetails 架构 .net 5 和 6

Swagger UI hide AspNetCore.Mvc.ProblemDetails schema .net 5 and 6

如何在 .net 5 和 .net 6 中隐藏 ProblemDetails 架构(见下文)。

解决方法是SuppressMapClientErrorsStartup.cs中加上ConfigureApiBehaviorOptions,如下图:

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers().ConfigureApiBehaviorOptions(x => { x.SuppressMapClientErrors = true; });
    ...
}