How to configure swagger in .Net core (asp.net core) webapi

1. Assumption - You have started the Asp.net core web API project

2. Now you need to add Swagger asp.net core package

using Package Manager Console
Install-Package Swashbuckle.AspNetCore

Using Nuget Package Manager 




3. Now You need to configure Swagger Manually, Like Asp.net web api this one does not generate Swagger Configuration class


4. Open Startup.cs class in your project


5. Goto ConfigureServices function and add Swagger Configuration details

services.AddSwaggerGen(c =>
{
      c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
});

We use this to add swagger service to the container 


6. Goto Configure function and add Swagger runner details

app.UseSwagger();

app.UseSwaggerUI(c =>

{
      c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});

This function is to provide run time configuration 



7. Now Your ready to run


Comments

Popular posts from this blog

How to Set Default path for the Asp.Net Core Web Api

Work with EntityFrameworkCore and asp.net core