I've been trying to figure out why Swagger-Net does not show the endpoint methods in a controller.
The C# project is using a Web API template based on .Net framework 4.6.1.
I get the same result when I use SwashBuckler, so it's not Swagger-Net that's the issue, but something that is not configured or missing.
The SwaggerConfig looks like this
public class SwaggerConfig
{
/// <summary>
///
/// </summary>
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", nameof(ConsentResponseApp));
c.AccessControlAllowOrigin("*");
c.IncludeAllXmlComments(thisAssembly, AppDomain.CurrentDomain.BaseDirectory);
})
.EnableSwaggerUi(c =>
{
c.UImaxDisplayedTags(100);
c.UIfilter("''");
});
}
}
I'm at a dead end at the moment since I have no idea why Swagger cannot read the methods action names.
The answer:
The WebApiConfig route is not by default configured to route with action
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
it has to be changed to
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);