Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate model description in AspNet WebApi help pages

How do I generate a description for my model in Asp.Net Web Api help pages?

Example:

enter image description here

As you can see from the example, I can already generate Name, Type and Additional Information. But how do I generate Description?

I've tried nothing and I'm all out of ideas.

No, that's not true. I've tried adding comments to my TransactionDto class, but it does not work.

/// <summary>
/// A DTO (Data Transfer Object) for Transaction objects.
/// </summary>
public class TransactionDto
{
    /// <summary>
    /// The manager who registered the transaction.
    /// </summary>
    public string FromId { get; set; }

    /// <summary>
    /// The receiving manager.
    /// </summary>
    [Required]
    public string ToId { get; set; }

    /// <summary>
    /// Optional expiration date.
    /// </summary>
    public DateTime? Expires { get; set; }

    /// <summary>
    /// Date the transaction was created.
    /// </summary>
    public DateTime Created { get; set; }
}

I have configured HelpPageConfig.cs to use an XmlDocumentationProvider like so:

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

So how do I generate these descriptions for models?

like image 695
transporter_room_3 Avatar asked May 31 '15 20:05

transporter_room_3


People also ask

How do I create a help page in ASP NET Web API?

To make this task easier, ASP.NET Web API provides a library for auto-generating help pages at run time. Install ASP.NET and Web Tools 2012.2 Update. This update integrates help pages into the Web API project template. Next, create a new ASP.NET MVC 4 project and select the Web API project template.

How can I create all of the documentation manually in web API?

You could create all of the documentation manually, but it is better to autogenerate as much as possible. To make this task easier, ASP.NET Web API provides a library for auto-generating help pages at run time. Install ASP.NET and Web Tools 2012.2 Update. This update integrates help pages into the Web API project template.

How to create a web API application in Visual Studio 2012?

We create the Web API application using the following: Start the Visual Studio 2012. Click on New Project and select the MVC4 application. Now select the Web API application from the template. Now we see the Areas folder in Solution Explorer. The Areas folder contains the help page folder. Now we execute the application.

How do I integrate help pages into the web API project template?

This update integrates help pages into the Web API project template. Next, create a new ASP.NET MVC 4 project and select the Web API project template. The project template creates an example API controller named ValuesController. The template also creates the API help pages.


1 Answers

I believe you have models in the separate project other than the Web API project?

If that is the case, the web API project is not aware of the help XML file generated for the models. you need to set the XML output path for both web API project and the models project and then combine both XML files in the register method of HelpPageConfig.cs file.

public static void Register(HttpConfiguration config)
{
        XmlDocument apiDoc = new XmlDocument();
        apiDoc.Load(HttpContext.Current.Server.MapPath("~/App_Data/WebApi.Orders.xml"));
        XmlDocument contractsDoc = new XmlDocument();
        contractsDoc.Load(HttpContext.Current.Server.MapPath("~/App_Data/Contracts.xml"));
        if (contractsDoc.DocumentElement != null && apiDoc.DocumentElement!=null)
        {
            XmlNodeList nodes = contractsDoc.DocumentElement.ChildNodes;
            foreach (XmlNode node in nodes)
            {
                XmlNode copiedNode = apiDoc.ImportNode(node, true);
                apiDoc.DocumentElement.AppendChild(copiedNode);
            }
            apiDoc.Save(HttpContext.Current.Server.MapPath("~/App_Data/WebApi.Orders.xml"));
        }
        config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/WebApi.Orders.xml")));
    ......
}
like image 188
Siva Varma Bayyavarapu Avatar answered Sep 21 '22 02:09

Siva Varma Bayyavarapu