
If you are a developer, tester, or manager, sometimes understanding the various methods of API can be a challenge when building and consuming the application.
Generating good documentation and help pages for your Web API, using Swagger with .NET Core is as easy as adding a couple of NuGet and modifying the Startup.cs
Let’s start downloading simple To-do projects from Github.
- Download and run TodoMvcSolution from the below link.
https://github.com/SmartITAz/TodoMvcSolution

- NuGet Packages
Install the below NuGet package
Install-Package Swashbuckle.AspNetCore
Configure Swagger in the Startup.cs
Add the Swagger generator to the service collection after services.AddMvc();
Enable the middleware for serving the generated JSON document after the app.UseStaticFiles();
Add the below background yellow lines in your Startup file.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;
namespace Todo.Mvc.Ui
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// Register the Swagger generator, defining one or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
// 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");
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Todo}/{action=Index}/{id?}");
});
}
}
}



md ameenPosted Dec 18, 2018, 9:13 AM
Hi, Which version of .Net Core is used in this article ?
Mumin quadriPosted Apr 24, 2018, 9:19 AM
How to check if a service has swagger implemented in it? In other words, if we have 100 services and we need to find which ones have swagger implementation, how do we accomplish that?
Ravi PatelPosted Sep 25, 2017, 5:01 AM
Nice article thanks