I'm using ASP.NET Web API and it conveniently automatically generates documentation for my API, but some of it doesn't make sense.
Take the below screenshot as an example.
This is an endpoint to GET
a user by their ID, and in the Resource Description
section it's showing a table which shows the user model's properties because my controller action has the [ResponseType(typeof(User))]
annotation.
Firstly, in my actual controller action, I'm stripping out the Password
property before displaying results to the user in order to not expose sensitive information. So the table given in the Resource Description
section is incorrect, it's saying my API returns fields that it doesn't.
Secondly, under the Additional Information
column it's showing the validation rules that go along with the User
model. Handy, but not at all relevant in this case as this endpoint is for GET
ing a user, not POST
ing one.
So, my question is how can I customize this Resource Description
table to specify myself what fields get returned, and hide the EF validations?
I've currently commented my controller action like this:
/// <summary>
/// Get a single user identified by ID.
/// </summary>
/// <param name="userId">The ID of the user.</param>
/// <returns>A data collection about the user.</returns>
[ResponseType(typeof(User))]
[Route("api/v1/users/{userId}", Name="GetUser")]
[HttpGet]
public IHttpActionResult GetUser(int userId)
{
// ...
}
and I've configured the help pages to read the documentation from an XML file which gets built from these ///
comments when I build the project.
Thanks!