.net Core使用Knife4jUI更換Swagger皮膚


Knife4j的前身是swagger-bootstrap-ui,前身swagger-bootstrap-ui是一個純swagger-ui的ui皮膚項目

官網實戰指南:https://doc.xiaominfo.com/knife4j/action/dotnetcore-knife4j-guid.html

1.安裝IGeekFan.AspNetCore.Knife4jUI包

Install-Package IGeekFan.AspNetCore.Knife4jUI

2.服務配置

services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "LT.PropertyManage.WebApi", Version = "v1" });
                c.AddServer(new OpenApiServer()
                {
                    Url = "",
                    Description = "vvv"
                });
                c.CustomOperationIds(apiDesc =>
                {
                    var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
                    return controllerAction.ControllerName + "-" + controllerAction.ActionName;
                });
                var filePath = Path.Combine(AppContext.BaseDirectory, "LT.PropertyManage.WebApi.xml");
                c.IncludeXmlComments(filePath, true);
            });

3.中間件配置

app.UseKnife4UI(c =>
            {
                c.RoutePrefix = string.Empty; ; // serve the UI at root
                c.SwaggerEndpoint("/v1/api-docs", "LT.PropertyManage.WebApi v1");
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapSwagger("{documentName}/api-docs");
            });

4.修改launchSettings.json文件

將"launchUrl": "swagger"改為

"launchUrl": ""

5.效果圖

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM