ASP.NET Core WebAPI HttpGet传递复杂类型

时间:2018-07-19 13:05:09

标签: asp.net-web-api asp.net-core nswag

我想像这样将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'.

0 个答案:

没有答案