Swagger (Swashbuckle) 隐藏页眉 [英] Swagger (Swashbuckle) hide header

查看:26
本文介绍了Swagger (Swashbuckle) 隐藏页眉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Swashbuckle 将 Swagger 文档添加到我的 ASP.NET Web API 项目中.如何在不注入 CSS 的情况下从文档页面隐藏默认标题(带有 swagger 标志)?

I use Swashbuckle to add Swagger documentation to my ASP.NET Web API project. How can I hide default header (with swagger logo) from documentation page without injecting CSS?

推荐答案

不幸的是,我认为你现在可以通过 javascript 完成.

Unfortunately I think you can do it olny by javascript right now.

在您的 SwaggerConfig.cs 中,您可以像这样注入一个 .js 文件:

In your SwaggerConfig.cs you can inject a .js file like this:

.EnableSwaggerUi(c =>
{                        
    c.InjectJavaScript(thisAssembly, "yournamespace.yourscript.js");
});

所以在这个脚本中你可以做任何你想做的事情,比如隐藏标题:

So in this script you can do whatever you want, like hide the header:

document.querySelector("#header").style.display = "none";

帖子展示了如何自定义标头在上面放两个文本框.

This post shows how to customize the header putting two text boxes on it.

@dimaKudr 的回答中建议的方法更好.注入一个 CSS 样式就足以隐藏菜单(JS 不是必须的).

The approach suggested in @dimaKudr's answer is better. Inject a CSS style is enough to hide the menu (JS is not necessary).

这篇关于Swagger (Swashbuckle) 隐藏页眉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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