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

1、問題web

  使用Swashbuckle.AspNetCore生成.NetCore WEBAPI的接口文檔的方法json

2、解決方案api

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

  一、Install-Package Swashbuckle.AspNetCorevisual-studio

  二、在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"
               });
      });
}

  三、在Configure中添加spa

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

3、運行測試:code

  輸入 http://127.0.0.1:8080/swagger/  或者 http://127.0.0.1:8080/swagger/v1/swagger.jsonblog

  

相關文章
相關標籤/搜索