grpc / grpc-dotnet

gRPC for .NET
Apache License 2.0
4.15k stars 764 forks source link

Validate messages #741

Open JamesNK opened 4 years ago

JamesNK commented 4 years ago

Provide a way to validate messages, similar to ASP.NET Core MVC's model validation - https://docs.microsoft.com/aspnet/core/mvc/models/validation

Potential solution: https://github.com/envoyproxy/protoc-gen-validate. Either code generation of validation, or runtime validation.

AnthonyGiretti commented 4 years ago

I have a temporary solution for now.

I forked a repo and improved it to make efficient validation. It's based on FluentValidation that injects Validator in the DI and the validation is processed within an interceptor. The client can get the error list from a strongly-typed model. Works only with gRPC, Have to improve this for gRPC-web.

Hope it could help!

https://github.com/AnthonyGiretti/grpc-aspnetcore-validator

ansarizafar commented 4 years ago

@JamesNK Is there any update on this issue? Code generated validation with https://github.com/envoyproxy/protoc-gen-validate is badly needed.

JamesNK commented 4 years ago

No. This isn't a high priority at the moment.

There is nothing stopping anyone from writing a library that inspects validation options defined in a proto file and uses them to validate Protobuf messages.

Xaeco commented 3 years ago

I’m keen to assist with this issue.

In my Blazor WebAssembly projects I need to be able to validate user input against my proto3 models at runtime. Preferably using the EditForm component and DataAnnotationValidator.

Currently none of the projects I’ve seen work to that degree or they are missing dotnet support.

I haven’t contributed to GitHub repos before so will require some assistance on getting started and would appreciate help planning out what work would be involved.

AnthonyGiretti commented 3 years ago

Hi,

I’m writing a client library which has the same behavior as my server validation library based on fluentValidation: https://github.com/AnthonyGiretti/grpc-aspnetcore-validator

Keep posted!

Anthony

Le jeu. 17 déc. 2020 à 13:43, Xaeco notifications@github.com a écrit :

I’m keen to assist with this issue.

In my Blazor WebAssembly projects I need to be able to validate user input against my proto3 models at runtime. Preferably using the EditForm component and DataAnnotationValidator.

Currently none of the projects I’ve seen work to that degree or they are missing dotnet support.

I haven’t contributed to GitHub repos before so will require some assistance on getting started and would appreciate help planning out what work would be involved.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/grpc/grpc-dotnet/issues/741#issuecomment-747625453, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFBX2JZVPO4IMPHC3TYLEQTSVJGOHANCNFSM4KM5TUIQ .

-- Anthony Giretti Blogger, Speaker | MVP, MCSD m: +1 514 557 1380 <+1+514+557+1380> s: anthonygiretti.com e: anthony.giretti@gmail.com

Xaeco commented 3 years ago

Thanks @AnthonyGiretti for your response. I think decorating proto message declarations with validation conditions is a good way forward. Is this your approach?

AnthonyGiretti commented 3 years ago

I define rules on messages with fluentValidation. It’s unit testable.

There is no data annotation on messages.

Le jeu. 17 déc. 2020 à 19:12, Matthew Hill notifications@github.com a écrit :

Thanks @AnthonyGiretti https://github.com/AnthonyGiretti for your response. I think decorating proto message declarations with validation conditions is a good way forward. Is this your approach?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/grpc/grpc-dotnet/issues/741#issuecomment-747785354, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFBX2J2LRUYURKL6LYCXS5LSVKNATANCNFSM4KM5TUIQ .

-- Anthony Giretti Blogger, Speaker | MVP, MCSD m: +1 514 557 1380 <+1+514+557+1380> s: anthonygiretti.com e: anthony.giretti@gmail.com

leblancmeneses commented 3 years ago

One of the benefits of decorating proto message with validation annotations is the metadata will be available to other languages. There is probably already a set of open source annotations where we just need to implement some glue code for .net.

Xaeco commented 3 years ago

As mentioned by @ansarizafar the https://github.com/envoyproxy/protoc-gen-validate repo is a great start. Just need to see if/how it can be extended for asp.net core and this repo.

ziaulhasanhamim commented 2 years ago

any updates on validation support?

SIGAN commented 2 years ago

any update on validation support (8 months later, to keep the issue open)

dystopiandev commented 3 weeks ago

This really could use standardization.