IGeekFan.AspNetCore.Knife4jUI 0.0.11

.NET 5.0 .NET Core 3.1 .NET Standard 2.0
Install-Package IGeekFan.AspNetCore.Knife4jUI -Version 0.0.11
dotnet add package IGeekFan.AspNetCore.Knife4jUI --version 0.0.11
<PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IGeekFan.AspNetCore.Knife4jUI --version 0.0.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: IGeekFan.AspNetCore.Knife4jUI, 0.0.11"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install IGeekFan.AspNetCore.Knife4jUI as a Cake Addin
#addin nuget:?package=IGeekFan.AspNetCore.Knife4jUI&version=0.0.11

// Install IGeekFan.AspNetCore.Knife4jUI as a Cake Tool
#tool nuget:?package=IGeekFan.AspNetCore.Knife4jUI&version=0.0.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

IGeekFan.AspNetCore.Knife4jUI

一个swagger ui 库:knife4j UI,支持 .NET Core3.0+或.NET Standard2.0。

nuget stats GitHub license

相关依赖项

knife4j

  • knife4j-vue

Swashbuckle.AspNetCore

  • Swashbuckle.AspNetCore.Swagger
  • Swashbuckle.AspNetCore.SwaggerGen

Demo

📚 快速开始

🚀安装包

以下为使用Swashbuckle.AspNetCore.Swagger底层组件

1.Install the standard Nuget package into your ASP.NET Core application.

Package Manager : 

Install-Package Swashbuckle.AspNetCore.Swagger
Install-Package Swashbuckle.AspNetCore.SwaggerGen
Install-Package IGeekFan.AspNetCore.Knife4jUI

OR

CLI :

dotnet add package Swashbuckle.AspNetCore.Swagger
dotnet add package Swashbuckle.AspNetCore.SwaggerGen
dotnet add package IGeekFan.AspNetCore.Knife4jUI

2.In the ConfigureServices method of Startup.cs, register the Swagger generator, defining one or more Swagger documents.

using Microsoft.AspNetCore.Mvc.Controllers
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using IGeekFan.AspNetCore.Knife4jUI;

🚁 ConfigureServices

3.服务配置,CustomOperationIds和AddServer是必须的。

   services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1",new OpenApiInfo{Title = "API V1",Version = "v1"});
        c.AddServer(new OpenApiServer()
        {
            Url = "",
            Description = "vvv"
        });
        c.CustomOperationIds(apiDesc =>
        {
            var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
            return  controllerAction.ControllerName+"-"+controllerAction.ActionName;
        });
    });

💪 Configure

  1. 中间件配置
app.UseSwagger();

app.UseKnife4UI(c =>
{
    c.RoutePrefix = ""; // serve the UI at root
    c.SwaggerEndpoint("/v1/api-docs", "V1 Docs");
});

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

5.更多功能

为文档添加注释 在项目上右键--属性--生成

在AddSwaggerGen方法中添加如下代码

c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "SwaggerDemo.xml"),true);

最后一个参数设置为true,代表启用控制器上的注释

运行后如看不到控制器上注释显示,请点开文档管理->个性化设置,开启分组tag显示description说明属性

NSwag.AspNetCore

(请参考目录test/WebSites/NSwag.Swagger.Knife4jUI)

public void ConfigureServices(IServiceCollection services)
 {
    // 其它Service
     services.AddOpenApiDocument();
 }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
            // 其它 Use
          app.UseOpenApi();
          app.UseKnife4UI(c =>
         {
               c.RoutePrefix = "";
               c.SwaggerEndpoint("/swagger/v1/swagger.json");
          });
}

即可使用 Knife4jUI

🔎 效果图

运行项目,打开 https://localhost:5001/index.html#/home

docs/home.jpg

更多配置请参考

更多项目

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on IGeekFan.AspNetCore.Knife4jUI:

Package Downloads
Coder.Extension

Coder扩展程序,包含:AutoMapper,Log,CsRedis,Swagger(Knife4j),Cors,Autofac,Hangfire,TimedJob,CAP,SqlSugar,Polly(超时,重试,熔断,降级)等扩展服务和中间件。

MSFactory.ToolKits

Package Description

PrimaxMes.Extensions.AspNetCore

Package Description

Paas.Pioneer.Knife4jUI.Swagger

Paas.Pioneer.Knife4jUI.Swagger

KnifeZ.CoolVayne.Mvc

KnifeZ's .NET5 Frameowrk

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on IGeekFan.AspNetCore.Knife4jUI:

Repository Stars
luoyunchong/lin-cms-dotnetcore
😃A simple and practical CMS implemented by .NET 6 + FreeSql;前后端分离、Docker部署、OAtuh2授权登录、自动化部署DevOps、自动同步至Gitee、代码生成器、仿掘金专栏
Version Downloads Last updated
0.0.11 10,952 11/11/2021
0.0.10 1,187 10/22/2021
0.0.9 1,745 9/2/2021
0.0.8 116,865 10/23/2020
0.0.7 5,157 8/24/2020
0.0.6 291 8/24/2020
0.0.4 846 8/12/2020
0.0.2 328 8/11/2020
0.0.1 413 8/9/2020