.netcore2.2使用Swagger
1.swagger的引用
引用Swashbuckle.AspNetCore和Swashbuckle.AspNetCore.Swagger
2.项目属性更改。勾选xml文档文件
3.在ConfigureServices中注册
#region swagger //注册Swagger生成器,定义一个和多个Swagger 文档 services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", //版本 Title = "hl's API", //标题 Description = "API描述",//描述 TermsOfService = "None", Contact = new Contact //联系人信息 { Name = "**", Email = string.Empty, } }); // 为 Swagger JSON and UI设置xml文档注释路径 var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location); var xmlPath = Path.Combine(basePath, "Test.xml");//xml路径名称 c.IncludeXmlComments(xmlPath); }); #endregion
4.在Configure中添加中间件
//启用中间件服务生成Swagger作为JSON终结点 app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.RoutePrefix = string.Empty; });
5.项目启动
相关推荐
SAMXIE 2020-11-04
XuDanT 2020-09-16
permanent00 2020-09-15
哈嘿Blog 2020-09-08
Qizonghui 2020-08-02
莫问前程 2020-08-02
SAMXIE 2020-07-26
XuDanT 2020-07-24
莫问前程 2020-07-18
Qizonghui 2020-07-18
coolhty 2020-07-05
Qizonghui 2020-06-28
Qizonghui 2020-06-25
莫问前程 2020-06-22
SAMXIE 2020-06-14
莫问前程 2020-06-14
XuDanT 2020-06-07
qingjiuquan 2020-06-07
TimeMagician 2020-06-03