Skip to content

[Feature Request] field level CEL constraints with parent scope #422

@rauanmayemir

Description

@rauanmayemir

Feature description:

Protovalidate supports arbitrary message level CEL rules that can validate fields based on other fields within the message scope.

However, the result validation will be tied to the field that references the message. What I'm suggesting is to support adding cel constraints on field level that allows referencing the parent message scope.

That way, when your validator interceptor collects google.rpc.BadRequest.FieldViolations, it will provide more detailed information on field paths.

Problem it solves or use case:

Fairly often used pattern for payloads is to have something like this:

{
  "command": "COMMAND_A",
  // Action payload corresponding to `COMMAND_A`
  "action_a": {},
  "?action_b": null,
  "?action_c": null
}

(This is not to say it is the right approach, but often the case when a system is modeled as an RPC and protobuf is only used for payload schema, without gRPC best practices. I.e without oneof, but more like several optional/nullable fields that are required only for certain values as command)

Proposed implementation or solution:

Here's an improvised protobuf example, that would allow to have a violation that references a particular field path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions