【发布时间】:2021-11-06 01:20:43
【问题描述】:
如何在 asp.net core 3.1 中绑定开放 API 文档中存在的深层对象?
我要解析的请求是:
GET https://localhost:5001/Product/?product[name]=mac&product[type]=computer
见下方控制器以及产品型号
[ApiController]
[Route("[controller]")]
public class DevicesController : ControllerBase
{
[HttpGet]
public async Task<IActionResult> Get([FromQuery]ProductQuery productQuery)
{
var response = await _mediator.Send(productQuery);
return Ok(response);
}
}
public class ProductQuery: IRequest<IEnumerable<ProductDto>>
{
public string Name {get; set;}
public string Type {get; set;}
}
【问题讨论】:
-
对于这个端点,URL 看起来是
https://.../Product?name=mac&type=computer。 -
@vernou 这是 deepObject 在这里查看查询参数swagger.io/docs/specification/serialization
标签: c# asp.net-core asp.net-core-mvc swagger openapi