我想像这样将Filter对象传递给Controller-Method:
[HttpGet("{filter:Filter}")]
[SwaggerResponse(HttpStatusCode.OK, typeof(BatchesResponse))]
[SwaggerResponse(HttpStatusCode.BadRequest, typeof(ModelStateDictionary))]
public async Task<ActionResult> List(Filter filter)
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
var result = _repository.GetAll();
return Ok(new BatchesResponse(result));
}
我使用NSwag生成客户端类。使用HttpGet-Annotation可以让我在生成的客户端上创建适当的“ Filter”对象,但是永远不会调用controller方法。服务器调试控制台告诉我:
System.InvalidOperationException: The constraint entry 'filter' - 'Filter' on the route 'api/{ver:apiVersion}/Batches/{filter:Filter}' could not be resolved by the constraint resolver of type 'DefaultInlineConstraintResolver'.