Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Validation rules on methods #72

Open
elliotmjackson opened this issue Aug 10, 2023 · 1 comment
Open

[Feature Request] Validation rules on methods #72

elliotmjackson opened this issue Aug 10, 2023 · 1 comment
Labels
Feature New feature or request

Comments

@elliotmjackson
Copy link
Contributor

Feature description:
Extend the functionality of the protovalidate library to include support for defining and enforcing validation rules on methods within Protocol Buffers service definitions.

Problem it solves or use case:
Currently, the protovalidate library focuses on validating individual message fields, but lacks the ability to validate the parameters and return values of methods defined within Protocol Buffers services. By introducing validation rules on methods, developers can ensure that the inputs and outputs of service methods adhere to specified constraints, enhancing data integrity and API consistency.

Proposed implementation or solution:
The proposed solution involves enhancing the protovalidate library to support validation rules specific to service methods. This includes introducing annotations or configuration options that allow developers to specify validation rules for method parameters and return values within Protocol Buffers service definitions. The library would then enforce these rules during runtime method calls.

Benefits of Method-Level Validation:
Method-level validation provides several benefits, including enhanced data validation, improved API documentation by making validation expectations explicit, and reduced likelihood of malformed data causing errors downstream. This feature also aligns with best practices for ensuring data integrity and robustness in service-oriented architectures.

Examples or references:
Other API frameworks, like gRPC, often include features for specifying validation rules on method parameters and responses. These can serve as references for how such functionality can be integrated into the protovalidate library.

Additional context:
The inclusion of validation rules on methods within the protovalidate library will significantly enhance the data validation capabilities of Protocol Buffers services. Developers will be able to define and enforce constraints on the inputs and outputs of methods, leading to more reliable and robust service interactions. This feature aligns with the evolving demands of API design and data integrity.

@derekperkins
Copy link

I'm not sure if this fits under this issue or if it's something separate, but I'm interested in having separate validation for multiple methods using the same proto message. We generally follow Google's AIP recommendations, and for Create/Update calls, they specifically use the same message in both request objects. That generally works great, but often validation for create has different constraints than for an update. To solve this, it seems like it can be approached in a few ways:

  1. Per this issue, have separate validation rules on the method
  2. Add validation rules to the separate request messages
  3. Make the calling method available as a CEL argument

2 seems like the most maintainable, though it would really benefit from shared / reusable rules. Thoughts?

igor-tsiglyar pushed a commit to igor-tsiglyar/protovalidate that referenced this issue Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants