Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Web API Help Documentation IHttpActionResult

I have a C# Web API and I am trying to get the auto created help documentation to work with IHttpActionResult. I stripped down the example below so its a little easier to read.

For the object, below is a simple example. BusinessObject is just a wrapper. The CollectionBase is CollectionBase : ObservableCollection<T>, ILoadable where T : BusinessObject. Its an older code base that is auto generated but reusing it for this.

    public class Value : BusinessObject
    {
        public int Id { get; set; }
    }
    public class Values : CollectionBase<Value>
    {
        public override Value LoadObject(System.Data.IDataRecord record)
        {
            return new Value();
        }
    }

For the API side of things. The following works.

public class Values : ApiController
{
    public IEnumerable<Value> GetThis()
    {
        Values values = new Values();
        return values;
    }
}

enter image description here

The issue comes when I try to do

    public IHttpActionResult GetThis()
    {
        Values values = new Values();
        return Ok(values);
    }

It doesn't recognize that it should use a different return type. The 'Resource Description' ends up being IHttpActionResult with no sample output. Now I can add

config.SetActualResponseType(typeof(IEnumerable<Value>), "Values", "GetThis");

and it will show a sample output but the 'Resource Description' will still be IHttpActionResult. That is the main issue I am having. I would like to use IHttpActionResult because its very easy to use and can return error codes if needed very easily. I would just like to be able to auto construct the documentation.

UPDATE: Upon some further research, I did fine this post. Resource Description on Web API Help page is showing "None."

Bascially, you add the response type attribute to the method.

[ResponseType(typeof(IEnumerable<Value>))]
public IHttpActionResult GetThis()
{
    Values values = new Values();
    return Ok(values);
}

Although this technically works and I have modified my existing code to use this. It would still be nice if there was a way to have it automatically figure it out somehow. Not sure if this is possible or not.

like image 715
Kalel Wade Avatar asked Apr 13 '15 16:04

Kalel Wade


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is C language basics?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


1 Answers

This works for what I am doing. Its a little tedious to have to include every time but it allows me to return error codes if necessary and retain the help documentation functionality.

[ResponseType(typeof(IEnumerable<Value>))]
public IHttpActionResult GetThis()
{
    Values values = new Values();
    return Ok(values);
}

Resource Description on Web API Help page is showing "None."

like image 158
Kalel Wade Avatar answered Sep 29 '22 21:09

Kalel Wade