.NET PROGRAMMING

Swagger Configuration for .Net Core API

This article demonstrates how to attach swagger UI.

Sukhpinder Singh | .Net Developer
C# Programming
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”);
});

--

--

Sukhpinder Singh | .Net Developer
C# Programming

Programmer by heart | C# | .Net 6 | .Net 8 | dotnet | dotnetcore | Kubernetes | Angular | AWS | Remember to 👏 Linktree: https://linktr.ee/sukhpindersingh