1、安装:

NuGet:搜索Swagger,安装Swashbuckle.AspNetCore

Asp.net Core WebApi使用Swagger

 

 

 2、配置XML文件:右键项目--生成--XML文档,记录xml文档的位置并修改第3步中xml文档的名称

Asp.net Core WebApi使用Swagger

 

 3、配置swagger中间件

// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            //注册Swagger生成器,定义一个和多个Swagger 文档
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1.0", new Info { Title = "My Demo API", Version = "1.0" });
                c.IncludeXmlComments(System.IO.Path.Combine(System.AppContext.BaseDirectory, "SwaggerCoreApi.xml"));
            });
        }
View Code

相关文章:

  • 2021-08-09
  • 2022-12-23
  • 2019-06-13
  • 2022-12-23
猜你喜欢
  • 2021-11-25
  • 2021-06-28
  • 2021-07-14
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2018-12-13
相关资源
相似解决方案