我正在制作一个订购系统。有这样一种类型:
public sealed record SmthRequest
{
public Guid WorkshopId { get; set; }
public Guid SupplyId { get; set; }
public List<(Guid id, int count)> MaterialIds { get; set; } = new List<(Guid, int)>();
}
如何正确MaterialIds
使用Postman
or表达Swagger
?
UPD:建立了一个端点:
[HttpGet("get-tuple")]
public async Task<IActionResult> GetTuple() =>
Ok(new SmthRequest(
Guid.NewGuid(),
Guid.NewGuid(),
new List<(Guid id, int count)>()
{
(Guid.NewGuid(), 1),
(Guid.NewGuid(), 2),
(Guid.NewGuid(), 3),
(Guid.NewGuid(), 4),
(Guid.NewGuid(), 5),
}
));
当我提出请求时,我收到以下回复:
{
"x1": "4d97ab93-bdca-421d-8549-122d5e1d42b9",
"x2": "c0a956d1-908a-495b-add6-2aca2941286a",
"x3": [
{},
{},
{},
{},
{}
]
}
我尝试传递这个选项:
{
"WorkshopId": "5da98ac2-b589-4261-ad8c-8a0d21111dca",
"MaterialIds": [
{
"Item1": "41edd8f3-15c5-4259-bfab-c35b21a00d2f",
"Item2": 5
},
{
"Item1": "48c313c0-032a-4d59-9120-a17e98ab6ba9",
"Item2": 10
}
]
}
和这个:
{
"WorkshopId": "5da98ac2-b589-4261-ad8c-8a0d21111dca",
"MaterialIds": [
{
"id": "41edd8f3-15c5-4259-bfab-c35b21a00d2f",
"count": 5
},
{
"id": "48c313c0-032a-4d59-9120-a17e98ab6ba9",
"count": 10
}
]
}
并且它们都没有将元组的值传递给服务器。