其他分享
首页 > 其他分享> > NetCore 添加Swagger

NetCore 添加Swagger

作者:互联网

  1. Nuget 添加 Swashbuckle.AspNetCore
  2. StartUp.cs 文件添加内容
public void ConfigureServices(IServiceCollection services)
        {
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version = "v1",
                    Title = "Core API"
                });
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(basePath, xmlFile);
                options.IncludeXmlComments(xmlPath);
            });
        }
************
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "CoreApi Docs");
            });
        }
  1. API属性 生成页签 xml生成添加路径

标签:NetCore,app,v1,添加,xmlPath,var,Swagger,options
来源: https://www.cnblogs.com/omiprise/p/16415997.html