Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web API Help Pages always empty

I've added Help pages Nuget package to create documentation for my Web API but it doesn't work for me, no API methods are shown.

I uncommented line :

config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));

I checked box XML documentation file and set path to App_Data/XmlDocument.xml

I don't use Glimpse as many solutions here write about it.

I even installed nuget package for help pages with authorization but it doesn't help

What is wrong with this? If I start empty project than it is working fine, but this API is too big to start all over again.

like image 982
goran85 Avatar asked Jul 02 '15 10:07

goran85


1 Answers

In case you are using OWIN as middleware (just like me), you may be initializing a new HttpConfiguration inside it´s startup method. The problem is that the HelpController and the HelpPageConfig are using GlobalConfiguration.Configuration, which seems to be wrong. What helped me:

Step 1: make the startup HttpConfiguration a static field

[assembly: OwinStartup(typeof(MyProject.API.Startup))]
namespace MyProject.API
{
    public class Startup
    {
        //new
        public static HttpConfiguration HttpCfg;
        //

        public void Configuration(IAppBuilder app)
        {
            HttpCfg = new HttpConfiguration();
            WebApiConfig.Register(HttpCfg);
            app.UseWebApi(HttpCfg);

            AreaRegistration.RegisterAllAreas();
        }
    }
}

Step 2: go to HelpPageAreaRegistration and edit the RegisterArea method like this

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "HelpPage_Default",
        "Help/{action}/{apiId}",
        new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });

    //old
    //HelpPageConfig.Register(GlobalConfiguration.Configuration);

    //new
    HelpPageConfig.Register(Startup.HttpCfg);
}

Step 3: go to HelpController and edit the standard constructor like this

//old
//public HelpController() : this(GlobalConfiguration.Configuration){ }

//new
public HelpController() : this(Startup.HttpCfg){ }

I hope this helps and isn't too late ;)

like image 101
DoctorCox Avatar answered Oct 28 '22 04:10

DoctorCox