swagger in asp.net core web api code example
Example: integrate swagger in .net core api
/*
To use swagger in an existing .net core api ALL functions must be annotated.
examples of annotations:
[HttpGet], [HttpPost], [NonAction] (for non HTTP actions)
*/
// in View>Other Windows>Package Manager Console add package:
Install-Package Swashbuckle.AspNetCore
// in startup.cs add:
using Microsoft.OpenApi.Models;
// in startup.cs edit functions:
// ConfigureServices():
services.AddMvc();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "<title>", Version = "v1" });
});
// Configure():
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "<title> v1"));
// in launchSettings.json add to all profiles:
"launchUrl": "swagger"