in src/Middleware/Grpc/Server/ProtoValidate.cs [52:80]
public bool ValidateMsg<TRequest>(TRequest request, out string error)
{
if (request is not IMessage message)
{
throw new ArgumentException("Unsupported message type");
}
var descriptor = message.Descriptor.File;
var validatorOptions = new ProtoValidate.ValidatorOptions()
{
PreLoadDescriptors = false,
DisableLazy = false,
FileDescriptors = new List<FileDescriptor>{descriptor}
};
// link to validator:
// https://github.com/telus-oss/protovalidate-net/blob/main/src/ProtoValidate/Validator.cs
var validator = new ProtoValidate.Validator(validatorOptions);
var violations = validator.Validate(message, _failFast);
if (violations.Violations.Count > 0)
{
error = string.Join(", ", violations.Violations);
return false;
}
error = string.Empty; // Assign an empty string instead of null
return true;
}