Validation does not work for Services which returns stream
WSebo opened this issue · comments
WSebo commented
Hello, everything works fine, but when I am testing getting many items from service using stream, the validator does not work.
Service looks like:
rpc GetManyItems (ItemsGetManyQuery) returns (stream ItemResponse);
WSebo commented
Hello. I fixed it by overriding ServerStreamingServerHandler in ValidationInterceptor.
public override async Task ServerStreamingServerHandler<TRequest, TResponse>(
TRequest request,
IServerStreamWriter<TResponse> responseStream,
ServerCallContext context,
ServerStreamingServerMethod<TRequest, TResponse> continuation)
{
if (_locator.TryGetValidator<TRequest>(out var validator))
{
var results = await validator.ValidateAsync(request);
if (!results.IsValid)
{
var message = await _handler.HandleAsync(results.Errors);
throw new RpcException(new Status(StatusCode.InvalidArgument, message));
}
}
await continuation(request, responseStream, context);
}