项目类型:asp.net core webapi
1.NuGet安装:Swashbuckle.AspNetCore
2.Startup.cs下的:ConfigureServices()加入:
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = "Swagger测试接口文档",
Description = "this is just a test"
});
var basePath = PlatformServices.Default.Application.ApplicationBasePath;var xmlPath = Path.Combine(basePath, "SwaggerTest.xml");
c.IncludeXmlComments(xmlPath);
// c.OperationFilter<HttpHeaderOperation>(); // 添加httpHeader参数
});
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "其实,我是一个演员。");
c.ShowRequestHeaders();
});
3.打开Swagger-UI:http://localhost:64969/swagger/
将LunchUrl改为“swagger”