How to perform a data annotation validation for the input as IAsyncEnumerable in ASP.NET Core 7 API controller POST action. I tried to use the following code, but validation didn't occur.
public record struct Car([Required][RegularExpression(@"^[0-9]{8}$")] string? Number);
public class MyController : ControllerBase
{
[HttpPost("cars")]
public async IAsyncEnumerable<Car> PostCarsAsync([FromBody] IAsyncEnumerable<Car> cars, CancellationToken ct)
{
await foreach (var car in cars)
{
yield return car;
}
}
}
I tried to pass the following request
[{},{"Number":""},{"Number":"87654321"}]
and got the following response without any validation errors:
[{"Number":null},{"Number":""},{"Number":"87654321"}]
So, the validation of input sequence didn't work.