0

I using nuget package Microsoft.AspNet.WebApi.HelpPage (5.2.3). I was faced with problem.

For example you can use sample:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.Serialization;
using System.Web.Http;

namespace WebApi.Controllers
{
    [Authorize]
    public class TestController : ApiController
    {
        /// <summary>
        /// TestGet
        /// </summary>
        /// <returns></returns>
        public Plan TestGet()
        {
            var Plan = new Plan();
            Plan.TestObjects = new List<TestClass>();
            return Plan;
        }
    }

    [DataContract(Namespace = "")]
    public class Plan
    {
        /// <summary>
        /// Name
        /// </summary>
        [DataMember]
        public string Name;

        /// <summary>
        /// The list of TestClass.
        /// </summary>
        [DataMember]
        public List<TestClass> TestObjects;
    }

    /// <summary>
    /// TestObject
    /// </summary>
    [DataContract(Namespace = "")]
    public class TestClass
    {
        /// <summary>
        /// identifier
        /// </summary>
        [DataMember]
        public int Id;
    }
}

How reproduce:

Reload IIS.

If a user clicks on a direct link to the description of the object of collection that he gets an error message.

http://localhost:59576/Help/ResourceModel?modelName=TestClass

If a user is moved to the page with the page the owner of the object or method, then there is no error.

http://localhost:59576/Help/Api/POST-api-Test

The cause of the problem is that in action HelpController.ResourceModel occurs incomplete context initialization.

IgorT
  • 1
  • What error message is displayed? – Chetan Jan 26 '17 at 13:29
  • modelDescriptionGenerator.GeneratedModels.TryGetValue(modelName, out modelDescription) return false and redirect to ErrorView. GeneratedModels does not contain the requested object. – IgorT Jan 26 '17 at 14:09
  • The desired object must be initialized by GenerateResourceDescription, but that method called in a another view. – IgorT Jan 26 '17 at 14:14
  • This http://stackoverflow.com/questions/18810936/web-api-auto-generating-request-samples-using-apiexplorer might help you – Chetan Jan 26 '17 at 14:24
  • Thanks for the link. If I understand correctly, you suggest to initialize all used objects in the method Register. It do not fit for me, because in my project of such objects are too many and number will continue to increase. I'm looking for a solution that will not require additional support. – IgorT Jan 26 '17 at 14:48
  • I have not much experience on this. But what I understand is if you want to show help about the model you need to initialize them so that help view can render information about them. Currently you might have lot of model classes but making them work is one time big job but after that you can make a practice of updating the things here as and when a new API is introduced. – Chetan Jan 26 '17 at 14:58
  • I am not sure if there is some tool available which can automate this process of you. You might want to look for that kind of solution. – Chetan Jan 26 '17 at 14:59

0 Answers0