.netcore Swagger 生成 api接口文档
程序员文章站
2022-07-28 10:46:22
1, 引用第三方包, Swashbuckle.AspNetCore Swashbuckle.AspNetCore.Swagger Swashbuckle.AspNetCore.SwaggerUI 最简单方法复制: 2. startup.cs 3 4. Controllers 对外action 加上请 ......
1, 引用第三方包,
swashbuckle.aspnetcore
swashbuckle.aspnetcore.swagger
swashbuckle.aspnetcore.swaggerui
最简单方法复制:
<packagereference include="swashbuckle.aspnetcore" version="4.0.1" /> <packagereference include="swashbuckle.aspnetcore.swagger" version="4.0.1" /> <packagereference include="swashbuckle.aspnetcore.swaggerui" version="4.0.1" />
2. startup.cs
//swagger services.addswaggergen(c => { c.swaggerdoc("v1", new info { version = "v1", title = typeof(startup).gettypeinfo().assembly.getname().name }); });
3
app.useswagger().useswaggerui(c => { c.swaggerendpoint("/swagger/v1/swagger.json", typeof(startup).gettypeinfo().assembly.getname().name + "-v1"); });
4. controllers
对外action 加上请求方式
[httppost] [httpget]...
访问地址:http://localhost:{端口}/swagger/index.html
上一篇: 想进我屁股里玩玩不?汗~