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

in proto2, the generated validator does not invoke the validator of the nested required message #21

Closed
gontard opened this issue Sep 25, 2020 · 4 comments

Comments

@gontard
Copy link
Contributor

gontard commented Sep 25, 2020

Given this proto:

syntax = "proto2";

import "validate/validate.proto";

message Person {
  message Location {
    required double lat = 1 [(validate.rules).double = { gte: -90,  lte: 90 }];
    required double lng = 2 [(validate.rules).double = { gte: -180, lte: 180 }];
  }

  required string email = 1 [(validate.rules).string.email = true];
  required Location home = 2;
  optional Location second_home = 3;
}

the generated PersonValidator does not invoke the LocationValidator for the home field

object PersonValidator extends scalapb.validate.Validator[Person] {
  def validate(input: Person): scalapb.validate.Result =
    scalapb.validate.Result.run(io.envoyproxy.pgv.StringValidation.email("email", input.email)) &&
    scalapb.validate.Result.optional(input.secondHome) { _value =>
      PersonValidator.LocationValidator.validate(_value)
    }
  
  object LocationValidator extends scalapb.validate.Validator[Person.Location] {
    def validate(input: Person.Location): scalapb.validate.Result =
      scalapb.validate.ComparativeValidation.rangeGteLte("lat", input.lat, -90.0, 90.0) &&
      scalapb.validate.ComparativeValidation.rangeGteLte("lng", input.lng, -180.0, 180.0)
  }
}
@thesamet
Copy link
Contributor

https://github.com/envoyproxy/protoc-gen-validate is Proto3 only, so none of the tests in the 900+ test case harness checks that required fields are handled correctly. I think we can still make required fields work in ScalaPB-validate - thanks for reporting.

@gontard
Copy link
Contributor Author

gontard commented Sep 26, 2020

Yes, that's a borderline feature...

Thanks a lot for this fix! May i ask you a new bump 🤞 ? I would be very please to test on our project and give you some feedbacks.

@thesamet
Copy link
Contributor

Sure, I just pushed 0.1.4

@gontard
Copy link
Contributor Author

gontard commented Nov 13, 2020

@thesamet we used scalapb-validate with proto2 for a while now without any issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants