发布时间:2020-02-18 21:03:15来源:本站阅读(877)
先引包 :Swashbuckle.AspNetCore
撸代码
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
//help
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = "接口文档",
Description = "RESTful API for Hicard",
TermsOfService = "None",
Contact = new Contact { Name = "-", Email = "-", Url = "" }
});
//Set the comments path for the swagger json and ui.
c.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Doc.xml")); //文档路径
// c.OperationFilter<HttpHeaderOperation>(); // 添加httpHeader参数
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory logFac)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); });
}
文档生成需要在项目属性里设置
好了。运行项目,请求 http://127.0.0.1/swagger/index.html 看效果
上一篇: core mvc 分页
下一篇: core api小技巧
793
1521
1363
1733
1046
1488
1553
1149
962
768
9593
5996
5523
5116
4567
4274
3415
3336
3335
3269