How to add swagger - Nordes/HoNoSoFt.DotNet.Web.Spa.ProjectTemplates GitHub Wiki
Here are the steps
dotnet add package Swashbuckle.AspNetCore
- This will download and install all the deps.
- Open your
startup.cs
file.
- Add in the
ConfigureServices
method
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
});
- Into the
Configure
you will have to add
// Enable middleware to serve generated Swagger as a JSON endpoint.
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", "My API V1");
});
Now you should be good to do a dotnet run
and open the url https://localhost:5001/swagger/
More detailed guide can be found on the MSDN website and I recommend you to go and look.