Swashbuckle, a simple and effective UI for your web api based on Swagger

Swashbuckle  is a very nice project that will generate a UI for your web api. It has support for xml documentation, authentication and just every feature that comes with swagger-ui.

Installation is relatively simple, all you need to do is install the package

Install-Package Swashbuckle.Core

 

The SwaggerConfig.cs file will be added to your solution. From there everything should work, but you may want to replace this line with your actual web api name :

c.SingleApiVersion(“v1”, “MyWebApi”);

 

If you are using XmlDocumentation for your web api, swagger can generate ui using this documentation.

 

Go in your wep.api project properties under Build and select XML documentation file

untitled

In the swaggerConfig.cs file, add the following method

        private static string GetXmlCommentsPath()
        {
            return string.Format(@"{0}\bin\MyXmlDoc.XML",
                System.AppDomain.CurrentDomain.BaseDirectory);
        }

 

And make sure your EnableSwagger configuration include the IncludeXmlComments call

GlobalConfiguration.Configuration 
                .EnableSwagger(c =>
                    {
                        c.IncludeXmlComments(GetXmlCommentsPath());

Start your web app, navigate to localhost/swagger , and enjoy your new web api ui !

untitled

Submit a Comment

Your email address will not be published. Required fields are marked *

Share This