当前位置:网站首页>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
边栏推荐
- 2022t elevator repair test simulation 100 questions and online simulation test
- Queue storage and circular queue
- 研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台
- Eight elder brothers chronicle [4]
- 《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
- Can you answer the questions that cannot be answered with a monthly salary of 10k-20k?
- MySQL grouping query rules
- Aspnetcore configuration multi environment log4net configuration file
- Student achievement management
- oracle 查询外键含有逗号分隔的数据
猜你喜欢
Eight elder brothers chronicle [4]
The most understandable life cycle of dependency injection
“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
Log4net is in Net core usage
[Mysql] LEFT函數 | RIGHT函數
Charles uses three ways to modify requests and responses
Top 9 task management system in 2022
[vs Code] solve the problem that the jupyter file displays exceptions in vs code
Top ten project management software similar to JIRA
关于idea调试模式下启动特别慢的优化
随机推荐
场景题:A系统如何使用B系统的页面
Mysql database, inconsistent index character set, slow SQL query, interface timeout
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
你真的懂hashCode和equals吗???
Source generator actual combat
Eight elder brothers chronicle [4]
C syntax sugar empty merge operator [?] And null merge assignment operator [? =]
Drawing polygons with < polygon / > circular array in SVG tag
编码电机PID调试(速度环|位置环|跟随)
C syntax pattern matching [switch expression]
ASP. Net and ASP NETCORE multi environment configuration comparison
为什么BI对企业这么重要?
WinForm allows the form form to switch between the front and active states
2022 P cylinder filling training test questions and simulation test
. net core current limiting control - aspnetcoreratelimit
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
Comprehensive calculation of employee information
Impact of AOT and single file release on program performance