bufbuild / protovalidate-go

Protocol Buffer Validation for Go
https://pkg.go.dev/github.com/bufbuild/protovalidate-go
Apache License 2.0
262 stars 19 forks source link

[BUG] Enum-related validation error messages contain numbers instead of value names #125

Closed mithRabbit closed 3 months ago

mithRabbit commented 3 months ago

Description

enum validation message is not correct

Steps to Reproduce

  1. write proto message enum IDType { ID_TYPE_UNSPECIFIED = 0; ID_TYPE_PASSPORT = 1; ID_TYPE_TAX_ID = 2; }

    // ID type. Must be ID_TYPE_PASSPORT or ID_TYPE_TAX_ID. // IDType id_type = 1 [(google.api.field_behavior) = REQUIRED, (buf.validate.field).enum = {in: [1,2]}];

  2. build the protobuf

  3. run the validator v, err := protovalidate.New() if err != nil { panic(err) }

    if err := v.Validate(req); err != nil { panic(err) }

Expected Behavior

id_type : value must be in list [ID_TYPE_PASSPORT , ID_TYPE_TAX_ID]

Actual Behavior

ID_TYPE_PASSPORT or ID_TYPE_TAX_ID

Screenshots/Logs

Screenshot 2567-05-23 at 16 39 51

Environment

Possible Solution

-

Additional Context

-

rodaine commented 3 months ago

Unfortunately, CEL does not preserve details about the enum itself (like value names) and is only capable of preserving the integer values of the enum types. For all enum related rules you'll see error messages presenting the integer value as this is a limitation of CEL.