Modifications to Swagger UI header

后端 未结 5 2226
青春惊慌失措
青春惊慌失措 2021-01-02 18:12

I have created a personal WEB API using Swashbuckle and Swagger API.

While I am able to integrate this successfully, I would like to modify the default UI for Swagge

5条回答
  •  庸人自扰
    2021-01-02 18:31

    These are the steps I took:

    1. Create a new file SwaggerHeader.css
    2. Right click on SwaggerHeader.css, select Properties. Set Build action to Embedded Resource.
    3. In SwaggerConfig.cs, add the below line of code:
          EnableSwaggerUi("Document/{*assetPath}", c =>
          {
              c.InjectStylesheet(typeof(SwaggerConfig).Assembly,
              "ProjectName.FolderName.SwaggerHeader.css");
          }
    
    1. SwaggerHeader.css looks like the below:

    /* 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;
    }

提交回复
热议问题