Swagger in ASP.Net Core 2.0

Swagger tooling for API’s built with ASP.NET Core. Generate beautiful API documentation, including a UI to explore and test operations, directly from your routes, controllers and models.

Full document can be found here

So let start. First we need to install this package

Install-Package Swashbuckle.AspNetCore

In order to wire up swagger we need to add these following line in Startup.cs

public void ConfigureServices(IServiceCollection services)
{
   services.AddSwaggerGen(c =>
   {
      c.SwaggerDoc("v1", new Info
         {
           Version = "v1",
           Title = "Awesome CMS Core API V1",
           Contact = new Contact { Name = "Tony Hudson", Email = "", Url = "https://github.com/ngohungphuc" }
         });
   });
}

public void Configure(IApplicationBuilder app)
{
     app.UseSwagger();
     app.UseSwaggerUI(c =>
     {
       c.SwaggerEndpoint($"/swagger/v1/swagger.json", "Awesome CMS Core API V1");
     });
}

We need to modify a litte bit for our app properties.

 

devenv_2018-04-26_23-32-55

Then run our app we will see the swagger ui

chrome_2018-04-26_23-16-08

In this post I will show you guy how to integrate Swagger with API versioning. Happy coding !!!

 

Leave a comment