1

I'm using ASP.NET Web API Help Page for my web API, but unfortunately controller method's that uses ParameterBindingAttribute are not being listed on GetApiExplorer(). Example bellow GetOutPut is listed and GetEntrance not.

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

        public HelpController(HttpConfiguration config)
        {
            Configuration = config;
        }

        public ActionResult Index()
        {
            ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
            return View(Configuration.Services.GetApiExplorer().ApiDescriptions);
        }

Controller's methods

/// <summary>
        /// Entrance
        /// </summary>
        /// <param name="foo"></param>
        /// <param name="initialDate"></param>
        /// <param name="finalDate"></param>
        /// <returns></returns>
        [Route("entrance/{foo}/{initialDate}/{finalDate}")]
        [HttpGet]
        [ResponseType(typeof(BooModel))]
        public IHttpActionResult GetEntrance(string foo,
            [DateTimeParameter(DateFormat = DateTimeBindingFormats.yyyyMMddHHmm)] DateTime? initialDate,
            [DateTimeParameter(DateFormat = DateTimeBindingFormats.yyyyMMddHHmm)] DateTime? finalDate)
        {
            try
            {                
                return Ok();
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        /// <summary>
        /// Out Put
        /// </summary>
        /// <param name="foo"></param>
        /// <param name="initialDate"></param>
        /// <param name="finalDate"></param>
        /// <returns></returns>
        [Route("output/{foo}/{initialDate}/{finalDate}")]
        [HttpGet]
        [ResponseType(typeof(FooModel))]
        public IHttpActionResult GetOutPut(string foo, DateTime? initialDate, DateTime? finalDate)
        {
            try
            {                
                return Ok();
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

XMLDocument.xml

<member name="M:IntegrationServices.Controllers.FooController.GetEntrance(System.String,System.Nullable{System.DateTime},System.Nullable{System.DateTime})">
            <summary>
            Entrance
            </summary>
            <param name="foo"></param>
            <param name="initialDate"></param>
            <param name="finalDate"></param>
            <returns></returns>
        </member>
        <member name="M:IntegrationServices.Controllers.FooController.GetOutPut(System.String,System.Nullable{System.DateTime},System.Nullable{System.DateTime})">
            <summary>
            Out Put
            </summary>
            <param name="foo"></param>
            <param name="initialDate"></param>
            <param name="finalDate"></param>
            <returns></returns>
        </member>

ParameterBindingAttribute's class

 public class DateTimeParameterAttribute : ParameterBindingAttribute
    {
        public string DateFormat { get; set; }

        public bool ReadFromQueryString { get; set; }


        public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
        {
            if (parameter.ParameterType != typeof(DateTime?)) return parameter.BindAsError("Expected type DateTime?");
            var binding = new DateTimeParameterBinding(parameter)
            {
                DateFormat = DateFormat,
                ReadFromQueryString = ReadFromQueryString
            };

            return binding;
        }
    }

Any ideas?

TylerH
  • 20,799
  • 66
  • 75
  • 101
rcarvalhoxavier
  • 331
  • 5
  • 7

0 Answers0