1, 引用第三方包, Swashbuckle.AspNetCore Swashbuckle.AspNetCore.Swagger Swashbuckle.AspNetCore.SwaggerUI 最簡單方法複製: 2. startup.cs 3 4. Controllers 對外action 加上請 ...
1, 引用第三方包,
Swashbuckle.AspNetCore
Swashbuckle.AspNetCore.Swagger
Swashbuckle.AspNetCore.SwaggerUI
最簡單方法複製:
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" /> <PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="4.0.1" /> <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="4.0.1" />
2. startup.cs
//swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = typeof(Startup).GetTypeInfo().Assembly.GetName().Name }); });
3
app.UseSwagger().UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", typeof(Startup).GetTypeInfo().Assembly.GetName().Name + "-v1"); });
4. Controllers
對外action 加上請求方式
[HttpPost] [HttpGet]...
訪問地址:http://localhost:{埠}/swagger/index.html