Modifications to Swagger UI header

后端 未结 5 2214
青春惊慌失措
青春惊慌失措 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条回答
  •  -上瘾入骨i
    2021-01-02 18:34

    1. First step is to add a new css file in your project, with your custom rules. For example :

      .swagger-section #header { background-color: #fadc00; }
      
    2. Right click on the new file and go Properties. In "Build Actions" select "Embedded Ressources".

    3. Inside the SwaggerConfig file, inject the stylesheet. The resource name should be the "Logical Name" for the resource. That is where I got stuck, but thanks to this Swashbuckle doc I could infer the logical name following the rule :

      Default Namespace for your project "dot" folder containing the resource "dot" file name with extension.

    It's based on the Project's default namespace, file location and file extension. For example, given a default namespace of "YourWebApiProject" and a file located at "/SwaggerExtensions/index.html", then the resource will be assigned the name - "YourWebApiProject.SwaggerExtensions.index.html"

    For example :

    .EnableSwaggerUi(c =>
    {
        c.InjectStylesheet(thisAssembly, "Some.Default.Namespace.App_Start.swagger.css");
    });
    

提交回复
热议问题