.Net Core 3.1 删除 Swagger UI 上的架构架构、Core、Net、UI

2023-09-07 14:27:03 作者:我爱他,最后爱疯了自己

我有 .Net 3.1 Web Api,我想删除这部分架构";在 Swagger 用户界面上.怎么做?

I have .Net 3.1 Web Api, I would like to remove this sections "Schemas" on Swagger UI. How to do it?

推荐答案

不需要模式过滤器.经过几天的努力,我发现:

No need for a schema filter. After busting on it for days I have found out:

所有需要做的都在

app.UseSwaggerUI(options =>
{
    options.DefaultModelsExpandDepth(-1);
});

注意:它是 DefaultModels(复数)而不是 DefaultModel(单数).区别在于 DefaultModels 是模型示例部分的模型的默认扩展深度,而 DefaultModels 是模型的扩展深度.

Note: It is DefaultModels (plural) not DefaultModel (singular). Difference is DefaultModels is the default expansion depth for the model on the model-example section, whereas DefaultModels is the expansion depth for models.