.NET PROGRAMMING
Swagger Configuration for .Net Core API
This article demonstrates how to attach swagger UI.
Published in
2 min readJul 16, 2020
Prerequisites
How to create a .net core web API project in visual studio Link.
Getting Started
Step 1: Install below two nuget packages :
Swashbuckle.AspNetCore.Swagger
Swashbuckle.AspNetCore.Annotations
Step 2: Add swagger.json configuration file in project root directory.
Step 3: Add below code to startup.cs file, under ConfigureServices function (Refer Screenshot)
services.AddSwaggerGen(c =>
{
c.SwaggerDoc(“v1”, new Swashbuckle.AspNetCore.Swagger.Info { Title = “Swagger Configuration”, Version = “v1” });
});
Step 4: Add below code to startup.cs file, under Configure function (Refer Screenshot)
app.UseStaticFiles();
app.UseDefaultFiles();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint(“/swagger/v1/swagger.json”, “Swagger Configuration V1”);
});