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生成添加路径
posted @ 2022-06-27 14:30  元坚  阅读(76)  评论(0编辑  收藏  举报