Skip to content

Don't attempt to validate referenced message types without validators #1116

@ctoomey

Description

@ctoomey

Per https://github.com/envoyproxy/protoc-gen-validate#messages

If a field contains a message and the message has been generated with PGV, validation will be performed recursively. Message's not generated with PGV are skipped.

However ScalaPB's generated message validators assume all message types other than google.protobuf.* have validators and thus fails to compile when referencing message types without validators.

E.g. when using scalapb-validate-codegen and compiling this message

message Outer {
    com.example.types.Foo foo = 1;
}

it will generate a validator like

object OuterValidator extends scalapb.validate.Validator[Outer] {
  def validate(input: Outer): scalapb.validate.Result =
    scalapb.validate.Result.optional(input.foo) { _value =>
      com.example.types.FooValidator.validate(_value)
    }
}

To avoid this problem, PGV's java implementation uses reflection to find message validators (caching result after first time) and uses a fallback always-valid validator for message types without validators:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions