Skip to content

fnldesign/WebApiDocSamples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build status

Web API - Documentation - Samples

Tests with Web API - API Documentation Tools - API Help Pages and Swagger

Swagger - API Documentation

Swagger is a API Documentation Tool, intagrated on Visual Studio by Nuget Packages

See more at Swagger website.

I´m using Swashbuckle Visual Studio Nuget Package

To see a tutorial using .NET Web API and Swagger see more at Swashbuckle GitHub Repo

See Swagger UI in action bellow Swagger UI

.NET Web API - Help Pages

.NET Web API - Help Pages is a collection of Views to Genarate API Help Pages

I´m using WebApiTestClient too, to add a Test Client on API Help Pages. If you want, you see how to add WebApiTestClient into this tutorial Adding a simple Test Client to ASP.NET Web API Help Page

See more at HelpPages on Microsoft Website. This MS Blog Post is usefull too Introducing the ASP.NET Web API Help Page.

See Web API Test Client bellow Web Api Test Client

On the Code

Swashbuckle Configurations

To enable Swagger to use XmlDoc, use c.IncludeXmlComments(GetXmlCommentsPath());

I suggested to place XmlDoc in App_Data Folder above a sample of GetXmlCommentsPath() method

   private static string GetXmlCommentsPath()
   {            
            var basePath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/");
            var xmlDocPath = System.IO.Path.Combine(basePath, "XmlDocument.xml");
            return xmlDocPath;
   }

Sample Web API v2 Controller to documentation

Sample code - XmlDoc to Genarate API Doc

        /// <summary>
        /// Obtêm todos os produtos
        /// </summary>
        /// <returns>Retorna uma lista com todos os produtos</returns>
        public List<Models.Produto> Get()
        {
            return produtos;
        }