Большинство моих маршрутов API сегментированы следующим образом:
/api/{segment}/MyEntity
(например, "/api/SegmentA/MyEntity")
Где я определил ModelBinder, который преобразует строку в объект Segment
следующим образом:
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;
}
}
Настроен как:
GlobalConfiguration.Configuration.BindParameter(typeof(Segment), new SegmentModelBinder());
Итак, мои маршруты в конечном итоге выглядят так:
public class MyEntityController : BaseController
{
[HttpGet, Route("api/{segment}/MyEntity")]
public IEnumerable<MyEntity> Get(Segment segment)
{
...
}
}
Проблема в том, что сейчас я пытаюсь создать документацию для этих вызовов API, а ApiExplorer
полностью запутался в этих маршрутах и игнорирует их.
Как мне сказать ему, что для этих маршрутов, когда он видит параметр типа Segment
, это действительно просто строка из маршрута?