I had ASP MVC 5 project, to which I've added Web Api. Now I'm trying to install Swashbuckle (from bootstrap) - but it just shows an empty document without any controllers.
My controller:
[RoutePrefix("api/v1/Test/Check")]
public class TestController : ApiController
{
// GET: api/Test
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET: api/Test/5
[HttpGet]
public string Get(int id)
{
return "value";
}
// POST: api/Test
[HttpPost]
public void Post([FromBody]string value)
{
}
// PUT: api/Test/5
[HttpPut]
public void Put(int id, [FromBody]string value)
{
}
// DELETE: api/Test/5
[HttpDelete]
public void Delete(int id)
{
}
// GET: api/Test
[Route("GetMetadata")]
[HttpGet]
public IEnumerable<string> GetMetadata()
{
return new string[] { "value2221", "value2" };
}
}
My Web Api Config:
configuration.MapHttpAttributeRoutes();
configuration.Routes.MapHttpRoute("Public API V1", "api/v1/{controller}/{id}",
new { id = RouteParameter.Optional });
My Global.asax.cs
:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
//WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
Swashbuckle
configuration is default.
The generated swagger document looks like this:
{
swagger: "2.0",
info: {
version: "v1",
title: "WebServer"
},
host: "localhost:55309",
schemes: [
"http"
],
paths: { },
definitions: { }
}
I can access my controller on http://localhost:55309/api/v1/Test
I'm not sure do I need to change anything in the generated SwaggerConfig.cs
but looking through it and on swashbuckle
docs it looks like it should work without any modifications