删除 Swagger UI 上的架构 - 续 [英] Remove Schema on Swagger UI -continued

查看:16
本文介绍了删除 Swagger UI 上的架构 - 续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注了顶级文章:

以前没有解决的问题,我们一起解决吧!

解决方案

模式过滤器没用.

所有需要做的事情都在

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

注意:这是默认模型而不是默认模型.DIfference is DefaultModel 是模型示例部分中模型的默认扩展深度,而 DefaultModels 是模型的扩展深度.

I have followed the top article : .Net Core 3.1 Remove Schema on Swagger UI

I applied this filter:

public class RemoveSchemasFilter : IDocumentFilter
{
    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
    {
        
        IDictionary<string, OpenApiSchema> _remove = swaggerDoc.Components.Schemas;
        foreach (KeyValuePair<string, OpenApiSchema> _item in _remove)
        {
            swaggerDoc.Components.Schemas.Remove(_item.Key);
        }
    }
}

I have added it here:

services.AddSwaggerGen(options =>
            {
                options.OperationFilter<AddRequiredHeaderParameter>(Configuration.GetSection("DefaultConfig")["TenantId"]);
                options.DocumentFilter<RemoveSchemasFilter>();
             }

All good Schema is removed from the bottom of Swagger UI. However, when I click on a method it brings a dialogue of errors. It works but this windows stays on top and it is very annoying.

Let's solve this problem together as it was unsolved previously!

解决方案

The schema filter is useless.

All needs to be done is in

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

Note: It is Default Models not Default Model. DIfference is DefaultModel is the default expansion depth for the model on the model-example section, whereas DefaultModels is the expansion depth for models.

这篇关于删除 Swagger UI 上的架构 - 续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆