使用Swashbuckle.AspNetCore生成.NetCore WEBAPI的接口文档

1、问题html

  使用Swashbuckle.AspNetCore生成.NetCore WEBAPI的接口文档的方法web

2、解决方案json

  参考文章:https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/web-api-help-pages-using-swagger?tabs=visual-studioapi

  一、Install-Package Swashbuckle.AspNetCoreapp

  二、在ConfigureServices中添加AddSwaggerGen。post

复制代码
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"
               });
      });
}
复制代码

  三、在Configure中添加visual-studio

            app.UseSwagger().UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

3、运行测试:测试

  输入 http://127.0.0.1:8080/swagger/  或者 http://127.0.0.1:8080/swagger/v1/swagger.jsonthis

  

 

 

出处:http://www.javashuo.com/article/p-bxmzdygx-n.htmlspa

相关文章
相关标签/搜索