grpc-spring icon indicating copy to clipboard operation
grpc-spring copied to clipboard

Do you have a plan to implement any protobuf message validation?

Open pc-avasilev opened this issue 3 years ago • 4 comments

Or maybe you have any recommendations how to do the message validation in more generic, configurable way?

pc-avasilev avatar May 17 '22 00:05 pc-avasilev

I don't plan to implement validation myself, but I consider adding support for one of the existing grpc/protobuf validation frameworks so you can just add the library.

Here is a PR for that: https://github.com/yidongnan/grpc-spring-boot-starter/pull/487/files

And a working library can be found here: https://github.com/envoyproxy/protoc-gen-validate Just add a ReflectiveValidatorIndex and @GrpcGlobalServerInterceptor ValidatingServerInterceptor bean to your config

ST-DDT avatar May 17 '22 07:05 ST-DDT

Thank you, for the information!

pc-avasilev avatar May 18 '22 00:05 pc-avasilev

Hello @ST-DDT,

i reviewed this PR https://github.com/yidongnan/grpc-spring-boot-starter/pull/487/files and found that is exactly what I'm looking for, since it will provide an option to create our custom validation logic using GrpcConstraintValidator.

I'm still novice in gRPC and trying to find the way how to validate for null values. For example we have a message:

message PersonProto {
  google.protobuf.Int64Value  id = 1;
  google.protobuf.Int64Value  userId = 2;
 } 

we don't want to use a primitive uint64 type since the default value would be 0 which is misleading and that's why we are using Int64Value. At the same time we want to have a null check validation logic on client and service side. Correct my if i wrong, but the [protoc-gen-validate] library doesn't provide this validation option. So, i think for now only one option would be to create a custom validator using the GrpcConstraintValidator.

pc-avasilev avatar May 24 '22 01:05 pc-avasilev

Correct my if i wrong, but the [protoc-gen-validate] library doesn't provide this validation option.

I think its called required. https://github.com/envoyproxy/protoc-gen-validate#messages

PS: grpc Message = Java DTO/POJO

ST-DDT avatar May 24 '22 06:05 ST-DDT