Most of my api routes are segmented like so:
/api/{segment}/MyEntity
(i.e. "/api/SegmentA/MyEntity")
Where I've defined a ModelBinder that converts from the string to a Segment
object like so:
class SegmentModelBinder : IModelBinder
{
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
if (value == null || String.IsNullOrEmpty(value.AttemptedValue))
return false;
bindingContext.Model = **logic to find segment object from value.AttemptedValue**;
return true;
}
}
Configured as:
GlobalConfiguration.Configuration.BindParameter(typeof(Segment), new SegmentModelBinder());
So my routes end up looking like this:
public class MyEntityController : BaseController
{
[HttpGet, Route("api/{segment}/MyEntity")]
public IEnumerable<MyEntity> Get(Segment segment)
{
...
}
}
The problem is, I'm now attempting to generate documentation for these Api calls, and ApiExplorer
is completely confused by these routes and ignores them.
How do I tell it that for these routes, when it sees a parameter of type Segment
, it's really just a string from the route?