mirror of
https://github.com/nsnail/IGeekFan.AspNetCore.Knife4jUI.git
synced 2025-12-27 14:45:48 +08:00
add knife4jui demo
This commit is contained in:
97
README.md
97
README.md
@@ -1,73 +1,86 @@
|
||||
# IGeekFan.AspNetCore.Knife4jUI
|
||||
一个支持.NET Core3.0,.NET Standard2.0的swagger ui 库:**knife4j UI**。
|
||||
|
||||
## 相关类库
|
||||
## 相关依赖项
|
||||
### [knife4j](https://gitee.com/xiaoym/knife4j)
|
||||
- knife4j-vue-v3(不是vue3,而是swagger-ui-v3版本)
|
||||
### [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore)
|
||||
|
||||
依赖项
|
||||
- Swashbuckle.AspNetCore.Swagger
|
||||
- Swashbuckle.AspNetCore.SwaggerGen
|
||||
```
|
||||
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="2.1.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="4.6.0" />
|
||||
```
|
||||
## demo
|
||||
-[https://github.com/luoyunchong/IGeekFan.AspNetCore.Knife4jUI/blob/master/test/Basic](https://github.com/luoyunchong/IGeekFan.AspNetCore.Knife4jUI/blob/master/test/Basic)
|
||||
|
||||
## Demo
|
||||
- [Basic](https://github.com/luoyunchong/IGeekFan.AspNetCore.Knife4jUI/blob/master/test/Basic)
|
||||
- [Knife4jUIDemo](https://github.com/luoyunchong/IGeekFan.AspNetCore.Knife4jUI/blob/master/test/Knife4jUIDemo)
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 安装包
|
||||
|
||||
1.Install the standard Nuget package into your ASP.NET Core application.
|
||||
|
||||
```
|
||||
Install-Package IGeekFan.AspNetCore.Knife4jUI
|
||||
```
|
||||
或
|
||||
```
|
||||
dotnet add package IGeekFan.AspNetCore.Knife4jUI
|
||||
Package Manager : Install-Package IGeekFan.AspNetCore.Knife4jUI
|
||||
CLI : 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 System.Reflection;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using IGeekFan.AspNetCore.Knife4jUI;
|
||||
```
|
||||
### ConfigureServices
|
||||
|
||||
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 =>
|
||||
{
|
||||
return apiDesc.TryGetMethodInfo(out MethodInfo methodInfo) ? methodInfo.Name : null;
|
||||
});
|
||||
});
|
||||
{
|
||||
c.SwaggerDoc("v1",new OpenApiInfo{Title = "API V1",Version = "v1"});
|
||||
c.AddServer(new OpenApiServer()
|
||||
{
|
||||
Url = "",
|
||||
Description = "vvv"
|
||||
});
|
||||
c.CustomOperationIds(apiDesc =>
|
||||
{
|
||||
return apiDesc.TryGetMethodInfo(out MethodInfo methodInfo) ? methodInfo.Name : null;
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Configure
|
||||
|
||||
```
|
||||
app.UseSwagger(c =>
|
||||
{
|
||||
|
||||
});
|
||||
app.UseSwagger();
|
||||
|
||||
app.UseKnife4UI(c =>
|
||||
{
|
||||
c.RoutePrefix = ""; // serve the UI at root
|
||||
c.SwaggerEndpoint("/v1/api-docs", "V1 Docs");
|
||||
});
|
||||
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");
|
||||
});
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
endpoints.MapSwagger("{documentName}/api-docs");
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### 效果图
|
||||
运行项目,打开 https://localhost:5001/index.html#/home
|
||||
|
||||

|
||||
|
||||
|
||||
### 更多配置请参考
|
||||
|
||||
- [https://github.com/domaindrivendev/Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore)
|
||||
|
||||
|
||||
### 更多项目
|
||||
|
||||
- [https://api.igeekfan.cn/swagger/index.html](https://api.igeekfan.cn/swagger/index.html)
|
||||
Reference in New Issue
Block a user