修改Swagger UI标头 [英] Modifications to Swagger UI header
本文介绍了修改Swagger UI标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用Swashbuckle和Swagger API创建了个人WEB API.
I have created a personal WEB API using Swashbuckle and Swagger API.
虽然我能够成功集成此功能,但我想修改Swagger的默认UI.更改页眉的颜色并替换摇摇欲坠的图像.
While I am able to integrate this successfully, I would like to modify the default UI for Swagger. Changing the color of the header and replacing the swagger image.
是否可以通过修改现有文件来实现?
Is this possible by modifying existing files?
推荐答案
这些是我采取的步骤:
- 创建一个新文件SwaggerHeader.css
- 右键单击
SwaggerHeader.css
,选择属性.将 Build 操作设置为 Embedded Resource . - 在
SwaggerConfig.cs
中,添加以下代码行:
- Create a new file SwaggerHeader.css
- Right click on
SwaggerHeader.css
, select Properties. Set Build action to Embedded Resource. - In
SwaggerConfig.cs
, add the below line of code:
EnableSwaggerUi("Document/{*assetPath}", c =>
{
c.InjectStylesheet(typeof(SwaggerConfig).Assembly,
"ProjectName.FolderName.SwaggerHeader.css");
}
-
SwaggerHeader.css
如下所示:
/* swagger ui customization */
body.swagger-section #header {
background-color: white;
background: url(your-new-logo.png) no-repeat;
background-position-x: 250px;
height: 50px;
}
body.swagger-section #header .swagger-ui-wrap #logo {
display: none;
}
这篇关于修改Swagger UI标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文