protovalidate icon indicating copy to clipboard operation
protovalidate copied to clipboard

[Feature Request] C# Support

Open elliotmjackson opened this issue 2 years ago • 15 comments

Original Post in PGV: bufbuild/protoc-gen-validate#480

Feature description: Extend the capabilities of the protovalidate library to include support for performing runtime validation of Protocol Buffers messages in C# projects. Additionally, integrate a CEL (Common Expression Language) interpreter, currently under development at https://github.com/rofrankel/cel-csharp, to facilitate advanced validation expressions.

Problem it solves or use case: The absence of C# support in the protovalidate library limits developers working with Protocol Buffers and C#. By adding C# support, developers can perform runtime validation of Protocol Buffers messages directly within their C# applications. Furthermore, integrating the CEL interpreter enables complex validation expressions, enhancing data validation capabilities.

Proposed implementation or solution: The proposed solution involves extending the protovalidate library to include C# bindings and compatibility, which will involve defining C# classes or structures that correspond to Protocol Buffers message structures. Additionally, integrating the CEL interpreter from https://github.com/rofrankel/cel-csharp will facilitate advanced validation expressions within the protovalidate library.

Contribution: I'm excited about contributing to this feature by participating in discussions around C# bindings, assisting in the integration of the CEL interpreter, and collaborating on the implementation of runtime validation functions within the protovalidate library. If necessary, I can also assist in writing tests and documentation to ensure comprehensive coverage and guidance.

Examples or references: While the protovalidate library currently does not support C#, reference points such as protobuf-net can be valuable when considering how Protocol Buffers and C# can be integrated. The ongoing development of the CEL interpreter for C# (https://github.com/rofrankel/cel-csharp) can serve as a foundation for enabling complex validation expressions.

Additional context: Enabling C# support in the protovalidate library aligns with the needs of developers who work with C# and Protocol Buffers. The integration of the CEL interpreter further enhances the library's capabilities, allowing developers to define sophisticated validation expressions. This feature contributes to more robust and accurate data validation, aligning with modern software development practices in the C# ecosystem.

elliotmjackson avatar Aug 10 '23 19:08 elliotmjackson

I need a C# implementation of protovalidate for a project I'm working on at work.

I've recently built a fully working and tested C# CEL interpreter and I plan on implementing a fully-conformed protovalidate-csharp library in the coming weeks.

When I'm done, I need to discuss with my employer about open sourcing both projects. I don't know what answer to expect but I'm hopeful they'll be receptive to sharing.

I'll follow up on this comment over the next month with any updates I have.

LamarLugli avatar Aug 24 '23 22:08 LamarLugli

I have finished writing a conformed protovalidate-csharp library. I'm still working through open-sourcing the project (and the CEL interpreter project) with my employer.

LamarLugli avatar Sep 05 '23 21:09 LamarLugli

@LamarLugli Any success with that?

Evengard avatar Oct 04 '23 13:10 Evengard

It's still in legal at my company. I'm working though the approvals and expect it to be OK to release to the public soon. It's just taking more time than I would like.

LamarLugli avatar Oct 05 '23 02:10 LamarLugli

I guess the legal department is not prioritizing this? =)

Evengard avatar Nov 15 '23 15:11 Evengard

Just got approval on Friday.

The repositories are: https://github.com/telus-oss/protovalidate-net https://github.com/telus-oss/cel-net

The Nuget packages are: https://www.nuget.org/packages/ProtoValidate/0.1.0 https://www.nuget.org/packages/Cel/0.1.3

If anyone from the Buf team sees this, I would eventually like to pass off the maintenance and ownership of protovalidate-net over to your organization. @elliotmjackson

LamarLugli avatar Nov 20 '23 22:11 LamarLugli

Wow, awesome work, @LamarLugli! Can you confirm that both libraries pass their conformance tests? The repos would benefit from having GitHub Action CI run the tests for the project and any other static analysis used. In terms of reviewing the projects, I can do a deeper review and open issues in those repos, respectively.

We're internally discussing how we want to handle protovalidate implementations going forward, so we'll get back to you on details on maintenance/ownership.

rodaine avatar Nov 21 '23 17:11 rodaine

Both libraries fully pass the latest conformance tests. I would like to eventually add Github CI and have it run the tests and create nuget packages automatically. I'll wait for your team to get back to me on maintenance.

On Tue, Nov 21, 2023 at 12:17 PM Chris Roche @.***> wrote:

Wow, awesome work, @LamarLugli https://github.com/LamarLugli! Can you confirm that both libraries pass their conformance tests? The repos would benefit from having GitHub Action CI https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net run the tests for the project and any other static analysis used. In terms of reviewing the projects, I can do a deeper review and open issues in those repos, respectively.

We're internally discussing how we want to handle protovalidate implementations going forward, so we'll get back to you on details on maintenance/ownership.

— Reply to this email directly, view it on GitHub https://github.com/bufbuild/protovalidate/issues/70#issuecomment-1821339007, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACAFUFHUBSQ7OQNQDMDHD7LYFTO37AVCNFSM6AAAAAA3L5VVEKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRGMZTSMBQG4 . You are receiving this because you were mentioned.Message ID: @.***>

LamarLugli avatar Nov 22 '23 04:11 LamarLugli

This is amazing, just one small question - are there any plans to add support for the legacy but still widely used protoc-gen-validate rules?

Evengard avatar Nov 23 '23 10:11 Evengard

This is amazing, just one small question - are there any plans to add support for the legacy but still widely used protoc-gen-validate rules?

That is a massive undertaking as the implementations are completely different. I have no plans to add support for it.

I have seen some unofficial forks of the protoc-gen-validate repository that have .Net support that you could perhaps find and use. I can't remember where they are though.

It think it would probably be easier and quicker to update your proto files to be compatible with protovalidate.

LamarLugli avatar Nov 23 '23 12:11 LamarLugli

It think it would probably be easier and quicker to update your proto files to be compatible with protovalidate.

@Evengard, we've provided a migration tool to make this as straight-forward as possible.

I'll wait for your team to get back to me on maintenance.

@LamarLugli, sending you an email so we can setup a call to chat about your implementations.

rodaine avatar Nov 27 '23 17:11 rodaine

@rodaine @Evengard @LamarLugli

I see some activity on telus-oss/protovalidate-net which is promising. I'll be road testing it shortly, and will provide feedback on that repo if required.

I was wondering there are any plans is to get protovalidate-net recognised officially by this project? Having the dotnet implementation referenced by this project would go a long way for adopters to justify to their superiors the use of this package.

Amazing work, and thanks :)

fromz avatar Aug 21 '24 05:08 fromz