ASP.Net Web API Help Pages: Ignore certain properties for Request and/or Response

Topics: ASP.NET Web API
Feb 27, 2013 at 4:14 PM
Edited Feb 27, 2013 at 4:15 PM
Is it possible to have the Help Page sample generator ignore certain properties of a particular type?

For example, we use the same DTO for object Request and Response messages, for both POST and PUT requests. When user is POSTing a model (creating a new record) they don't need to provide the ID field.

But once its created and we serialize the new record into the response body, the ID field is included and returned to the client.

So in the POST request sample, I don't want the ID field to be displayed because for post request it doesn't make sense.

But the POST response sample, I do want the ID field displayed...

I am aware that there is the ApiExplorerSettings Attribute which can be applied to a Class or Method...but is there anything similar for a Property?

Something like this would be great:
public class MyDTO
    [ApiExplorerSettings(IgnoreForRequestApi = true, IgnoreForResponseApi = false)]
    public int Id { get; set; }

    // Other properties omitted for Brevity...
Feb 27, 2013 at 5:45 PM
Mar 1, 2013 at 12:52 AM
Hi ljenner01,

I wonder if you can just use a different DTO for the request with no ID (see sample below). That way, the help page can just show what it takes as parameter instead of hiding something. I think it would be a cleaner solution because the deserializer then doesn't need to populate the property that you don't want for the request. It's also a better security practice to prevent any unexpected behaviors when someone do try to set the ID in the request.
public MyDto Post(MyRequestDto request);

public class MyRequestDto
   // some properties

public class MyDto : MyRequestDto
   public int Id { get; set; }