I've configured Web API help page documentation.
I am having below class which would be inherited in other model classes.
public class ResponseBase
{
public string ErrorReason { get; set; }
[IgnoreDataMember]
public bool IsRejected { get; set; }
}
I don't want IsRejected to be serialized and available in response so I decorated it with IgnoreDataMember attribute.
Example of model class that inherits ResponseBase.
public class Reading : ResponseBase
{
//Other properties
}
I've below method in my Web API Controller:
[HttpPost]
[ValidationResponseFilter]
[Route("")]
[ResponseType(typeof(Reading))]
public IHttpActionResult Add(List<Reading> readingList)
{
//Logic here
}
Now for the documentation of request parameter which is list of Reading objects, it will list down all the properties of Reading along with ResponseBase class(inheritance). I want help page documentation to list down ErrorReason as one of the parameter in Response only.
Is there any configuration I can do other than setting attribute [ApiExplorerSettings(IgnoreApi = true)]
on ErrorReason? If I do that, ErrorReason will
not be available in both Request and Response Parameters. I want to display it in Response Parameters list only.
Generally, the best practice is to create a custom object that matches exactly what you want to accept. One of the reasons for this is security. See 'over-posting' and 'under-posting' : http://www.asp.net/web-api/overview/formats-and-model-binding/model-validation-in-aspnet-web-api To do this you would create a new object with only the properties you need.
Then you would take in List of ReadingVM but the response type would still be typeof(reading)
--- Work Around ---
Again, I think you should follow the method above. You asked for a work around and here it is. Find your 'GenerateApiModel' method in the HelpPageConfigurationExtensions.cs class and repalce it with this:
Now as you can see 'IsRejected' exists in the Response, but not the Reqest.