使用Swashbuckle.AspNetCore生成.NetCore WEBAPI的接口文档
一、问题
使用Swashbuckle.AspNetCore生成.NetCore WEBAPI的接口文档的方法
二、解决方案
参考文章:https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/web-api-help-pages-using-swagger?tabs=visual-studio
1、Install-Package Swashbuckle.AspNetCore
2、在ConfigureServices中添加AddSwaggerGen。
public void ConfigureServices(IServiceCollection services) { services.AddDbContext<TodoContext>(opt => opt.UseInMemoryDatabase("TodoList")); services.AddMvc(); // Register the Swagger generator, defining one or more Swagger documents services.AddSwaggerGen(options => { //options.DescribeAllEnumsAsStrings(); options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "Azure Adapter Api - Catalog HTTP API", Version = "v1", Description = "The Catalog Microservice HTTP API. This is a Data-Driven/CRUD microservice sample", TermsOfService = "Terms Of Service" }); }); }
3、在Configure中添加
app.UseSwagger().UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); });
三、运行测试:
输入 http://127.0.0.1:8080/swagger/ 或者 http://127.0.0.1:8080/swagger/v1/swagger.json
关注我】。(●'◡'●)
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的【因为,我的写作热情也离不开您的肯定与支持,感谢您的阅读,我是【Jack_孟】!
本文来自博客园,作者:jack_Meng,转载请注明原文链接:https://www.cnblogs.com/mq0036/p/11138553.html
【免责声明】本文来自源于网络,如涉及版权或侵权问题,请及时联系我们,我们将第一时间删除或更改!
posted on 2019-07-05 15:24 jack_Meng 阅读(1215) 评论(0) 编辑 收藏 举报