I am trying to integrate Swagger UI into my ASP.Net MVC project using Swashbuckle and I am having problems with Swashbuckle not recognizing any of my controllers/endpoints.
For simplicity I created a brand new project with a single controller that is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace TestAPI.Controllers
{
public class HomeController : Controller
{
[Route("Home")]
[HttpGet]
public ActionResult Index()
{
return View();
}
[Route("Home/About")]
[HttpGet]
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
[Route("Home/Contact")]
[HttpGet]
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
}
I used Nuget to add Swashbuckle using the following command:
Install-Package Swashbuckle
I kept all of the default configuration for both the overall project as well as for Swashbuckle itself (Using the generated file SwaggerConfig.cs)
When I navigate to the Swagger endpoint I am greeted by an empty Swagger definition and none of my controllers/endpoints are showing up.
I am at a loss for how to get my Controllers/Endpoints to show up. All of the Swashbuckle demo's make it seem like this base configuration will at the very least make the endpoints display.
Thanks!
EDIT: The following is my SwaggerConfig.cs
using System.Web.Http;
using WebActivatorEx;
using TestAPI;
using Swashbuckle.Application;
[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
namespace TestAPI
{
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "TestAPI");
})
.EnableSwaggerUi();
}
}
}