当前位置:网站首页>Using swagger in. Net5
Using swagger in. Net5
2022-04-23 03:18:00 【Pingshan CP3】
background :Swagger There are many benefits , It can be used as a communication bridge between the front and back ends , It can also be used as the entry of debugging interface , Convenient and quick , Improve development efficiency , Below will be recorded in .NetCore Use in Swagger
1. quote Nuget package --Swashbuckle.AspNetCore.Swagger

2. stay Startup.cs in ConfigureServices Add Swagger service
services.AddSwaggerGen(s =>
{
Dictionary<string, string> swaggerDic = new Dictionary<string, string>() {
{"Common"," Common interface " },
{"User"," User management interface " }
};
foreach (KeyValuePair<string, string> kv in swaggerDic)
{
// The first parameter , Must be with api Of GroupName The values used are consistent .
s.SwaggerDoc(kv.Key, new OpenApiInfo()
{
Version = "v1",// The top right corner of the title shows
Title = $"{kv.Value} API",
Description = $" {kv.Value} api file "
});
}
s.IncludeXmlComments("WebApp.xml");
// Enable add token Verify input place
s.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description = "JWT to grant authorization ( Data will be transmitted in the request header ) Type... Directly in the box below {token}\"",
Name = "token",//jwt Default parameter name
In = ParameterLocation.Header,//jwt Default storage Authorization Location of information ( Request header )
Type = SecuritySchemeType.ApiKey
});
s.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{new OpenApiSecurityScheme
{
Reference=new OpenApiReference()
{
Id="Bearer",
Type=ReferenceType.SecurityScheme
}
},Array.Empty<string>() }
});
});
The configuration enables token verification
3. stay Configure Add swagger The Conduit
app.UseSwagger();
app.UseSwaggerUI(s =>
{
Dictionary<string, string> swaggerDic = new Dictionary<string, string>() {
{"Common"," Common interface " },
{"User"," User management interface " }
};
// Configure the address of each controller
foreach (KeyValuePair<string, string> kv in CommonUtils.swaggerDic)
{
s.SwaggerEndpoint($"/swagger/{kv.Key}/swagger.json", kv.Value);// The first parameter must be the same as SwaggerDoc The parameters of the first method of the method are consistent , The last parameter is the filter condition
}
});


版权声明
本文为[Pingshan CP3]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220627117126.html
边栏推荐
- 《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
- JS recursive tree structure calculates the number of leaf nodes of each node and outputs it
- Configure automatic implementation of curd projects
- 队列的存储和循环队列
- A set of combination boxing to create an idea eye protection scheme
- ThreadLocal 测试多线程变量实例
- Establishing and traversing binary tree
- Use of ADB command [1]
- Fundamentals of software testing and development
- 可以接收多种数据类型参数——可变参数
猜你喜欢

ASP. Net 6 middleware series - Custom middleware classes

数据挖掘系列(3)_Excel的数据挖掘插件_估计分析

Why is bi so important to enterprises?

Chapter 7 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of modular programming exercises with functions

“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享

The most easy to understand dependency injection and control inversion

Huawei mobile ADB devices connection device is empty

Utgard connection opcserver reported an error caused by: org jinterop. dcom. common. JIRuntimeException: Access is denied. [0x800
![[MySQL] left function | right function](/img/26/82e0f2280de011636c26931a74e749.png)
[MySQL] left function | right function

Xamarin effect Chapter 22 recording effect
随机推荐
MySQL keyword group_ Concat, combined connection query
Fiddler use
Charles uses three ways to modify requests and responses
MySql关键字GROUP_CONCAT,组合连接查询
二进制文件版本控制工具选择难?看完这篇你会找到答案
Queue storage and circular queue
2022年P气瓶充装培训试题及模拟考试
Xutils3 corrected a bug I reported. Happy
New ORM framework -- Introduction to beetlsql
Establishing and traversing binary tree
《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案
socket编程 send()与 recv()函数详解
JS recursive tree structure calculates the number of leaf nodes of each node and outputs it
Log4net is in Net core usage
It can receive multiple data type parameters - variable parameters
Explication détaillée des fonctions send () et recv () du programme Socket
Preview of converting doc and PDF to SWF file
PID debugging of coding motor (speed loop | position loop | follow)
[authentication / authorization] customize an authentication handler
JS inheritance