废话不多说直接来看
第一步:
安装nuget包:Swashbuckle.AspNetCore.Swagger
Swashbuckle.AspNetCore.SwaggerGen
Swashbuckle.AspNetCore.SwaggerUI
安装好后就可以看到啦
第二步:找到Startup开始在ConfigureServices 配置
1 public void ConfigureServices(IServiceCollection services) 2 { 3 services.AddControllers(); 4 //swagger注册 5 services.AddSwaggerGen(m => { 6 m.SwaggerDoc("v1",new Microsoft.OpenApi.Models.OpenApiInfo { Title="code_first",Version="v1"}); 7 }); 8 }
第三步:继续在Startup的Configure配置
1 public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 2 { 3 if (env.IsDevelopment()) 4 { 5 app.UseDeveloperExceptionPage(); 6 } 7 8 app.UseRouting(); 9 //swagger 10 app.UseSwagger(); 11 app.UseSwaggerUI(s => { 12 s.SwaggerEndpoint("/swagger/v1/swagger.json","v1"); 13 }); 14 app.UseAuthorization(); 15 16 app.UseEndpoints(endpoints => 17 { 18 endpoints.MapControllers(); 19 }); 20 21 22 }