.NET Core API 使用Swagger
2021-04-21 08:27
标签:src post net api http swagger 技术 star swa 1.项目右键-管理NuGet程序包添加Swashbuckle.AspNetCore 2.修改Startup.cs中的ConfigureServices方法 3.修改Startup.cs中的Configure方法 4.删除Properties/launchSettings.json中的 "launchUrl": "api/values", 5.此时可以使用Swagger .NET Core API 使用Swagger 标签:src post net api http swagger 技术 star swa 原文地址:https://www.cnblogs.com/Adger/p/8591848.html public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "My API", Version = "v1" });
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
app.UseSwagger(c =>
{
c.PreSerializeFilters.Add((swagger, httpReq) => swagger.Host = httpReq.Host.Value);
});
app.UseSwaggerUI(c =>
{
c.RoutePrefix = ""; // serve the UI at root
c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs");
});
}
文章标题:.NET Core API 使用Swagger
文章链接:http://soscw.com/index.php/essay/77520.html