4
votes

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.

Empty Swagger Definition

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();
        }
    }
}
1
@NevilleNazerane These were the steps I followed to get things up and running. For some reason it seems like the routes are not being recognized by Swashbuckle or something along those lines.Charles Bisbee
@CharlesBisbee what version of .NET MVC are you using?TiagoBrenck
@TiagoBrenck I am using .NET MVC 5Charles Bisbee
Did you try turning it off then turning it back on again?eragon2262

1 Answers

1
votes

The answer to this question is that Swashbuckle does not work with ASP.Net MVC. It is unfortunate but Swashbuckle is not the appropriate solution for this problem. I ended up creating a custom solution using a combination of Reflection and XML comments.