Introduction

Swashbuckle is an open source project for generating Swagger documents for Web APIs that are built with ASP.NET Core.
There are three core components:
Step 1
Open Visual Studio 2017. Click -> File -> new -> Project.
Step 2
Select .NET Core -> ASP.NET Core Web Application.
Swashbuckle And ASP.NET Core
Step 3
Create a new ASP.NET Core web application project.
Step 4
In Solution Explorer -> solution (Right click) -> Manage Nuget Packages (select)
Swashbuckle And ASP.NET Core
Step 5
Search the word ->Swashbuckle.AspNetCore under the browse text box.
Swashbuckle And ASP.NET Core
Step 6
Click the install button to install the Swashbuckle.AspNetCore
Swashbuckle And ASP.NET Core
Step 7
We are going to install and update the following things. Click the OK button.
Swashbuckle And ASP.NET Core
Step 8
Accept their license term -> click ok.
Swashbuckle And ASP.NET Core
Step 9
Installed the Swashbuckle.AspNetCore successfully. You can see the output window.
Swashbuckle And ASP.NET Core
Step 10
Configure the startup.cs file
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.OpenApi.Models;
  6. using System;
  7. namespace migradoc_arictle {
  8. public class Startup {
  9. public Startup(IConfiguration configuration) {
  10. Configuration = configuration;
  11. }
  12. public IConfiguration Configuration {
  13. get;
  14. }
  15. // This method gets called by the runtime. Use this method to add services to the container.
  16. public void ConfigureServices(IServiceCollection services) {
  17. services.AddMvc();
  18. services.AddSwaggerGen(c => {
  19. c.SwaggerDoc("v1", newOpenApiInfo {
  20. Version = "v1",
  21. Title = "Test API",
  22. Description = "ASP.NET Core Web API",
  23. TermsOfService = new Uri("https://example.com/termslinks"),
  24. Contact = newOpenApiContact {
  25. Name = "Ronika Jency",
  26. Email = string.Empty,
  27. Url = new Uri("https://twitter.com/ronikajency"),
  28. },
  29. });
  30. });
  31. }
  32. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  33. public void Configure(IApplicationBuilder app, IHostingEnvironmentenv) {
  34. if (env.IsDevelopment()) {
  35. app.UseDeveloperExceptionPage();
  36. }
  37. app.UseMvc();
  38. app.UseSwagger();
  39. app.UseSwaggerUI(c => {
  40. c.SwaggerEndpoint("/swagger/v1/swagger.json", "Test API V1");
  41. });
  42. }
  43. }
  44. }
Step 11
Solution name (right-click)
Swashbuckle And ASP.NET Core
Step 12
Click -> Properties
Swashbuckle And ASP.NET Core
Step 13
Debug -> Change the browser URL to swagger.
Swashbuckle And ASP.NET Core
Step 14
After running the application you can able to check the API via Swagger.
Swashbuckle And ASP.NET Core