Barış Kısır

Senior Software Developer

Navigation
 » Home
 » RSS

Adding Swagger UI to .NET Web API

26 Jan 2019 » csharp

swagger-ui-logo

What is Swagger UI?

Swagger UI provides a display framework that reads an OpenAPI specification document and generates an interactive documentation website.


Why Swagger UI?

ASP.NET Web API Help Page does not allow users to try API on browser. With Swagger UI, users can try all api methods on their browser.

Thus, testers can test api without any user interface also.

Classic ASP.NET Web API Help Page

help-page-1

help-page-2


Installation with NuGet

Install-Package Swashbuckle


Adding SwaggerConfig

[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "RegisterSwaggerConfig")]
namespace OAuthNotesApp.App_Start
{
    public class SwaggerConfig
    {
        public static void RegisterSwaggerConfig()
        {
            GlobalConfiguration.Configuration.EnableSwagger(x => x.SingleApiVersion("v1", "NotesAPI")).EnableSwaggerUi();
        }
    }
}


User Interface

Navigate /swagger for interface.

swagger-ui-1

Testing register method

swagger-ui-2


You can download source code, db script and postman requests from here –> Download