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

Add support for #validate=true to message refs #2633

Merged
merged 3 commits into from
Feb 8, 2024
Merged

Add support for #validate=true to message refs #2633

merged 3 commits into from
Feb 8, 2024

Conversation

Alfus
Copy link
Contributor

@Alfus Alfus commented Nov 30, 2023

So it can be used with the convert command, for example:
buf convert ../protoyaml-go/internal/proto --type buf.protoyaml.test.v1.ValidateTest --from ../protoyaml-go/internal/testdata/validate.validate.yaml#validate=true
outputs:

Failure: unable to unmarshal the message: ../protoyaml-go/internal/testdata/validate.validate.yaml:2:18 cases[0].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)
   2 |   - float_gt_lt: 0
   2 |                  ^...................... cases[0].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)

../protoyaml-go/internal/testdata/validate.validate.yaml:3:18 cases[1].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)
   3 |   - float_gt_lt: 10
   3 |                  ^...................... cases[1].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)

../protoyaml-go/internal/testdata/validate.validate.yaml:4:18 cases[2].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)
   4 |   - float_gt_lt: 10.5
   4 |                  ^...................... cases[2].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)

../protoyaml-go/internal/testdata/validate.validate.yaml:5:18 cases[3].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)
   5 |   - float_gt_lt: -0.5
   5 |                  ^...................... cases[3].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)

../protoyaml-go/internal/testdata/validate.validate.yaml:6:16 cases[4].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)
   6 |   - floatGtLt: 10.5
   6 |                ^........................ cases[4].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)

../protoyaml-go/internal/testdata/validate.validate.yaml:7:8 cases[5].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)
   7 |   - 2: -Infinity
   7 |        ^................................ cases[5].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)

../protoyaml-go/internal/testdata/validate.validate.yaml:11:7 cases[6].string_map["c1"]: value does not match regex pattern `^[a-z]+$` (string.pattern)
  11 |       c1: B
  11 |       ^................................. cases[6].string_map["c1"]: value does not match regex pattern `^[a-z]+$` (string.pattern)

../protoyaml-go/internal/testdata/validate.validate.yaml:12:5 cases[7].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)
  12 |   - string_map:
  12 |     ^................................... cases[7].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)

../protoyaml-go/internal/testdata/validate.validate.yaml:13:10 cases[7].string_map["b"]: value does not match regex pattern `^[A-Z]+$` (string.pattern)
  13 |       b: B1
  13 |          ^.............................. cases[7].string_map["b"]: value does not match regex pattern `^[A-Z]+$` (string.pattern)

@Alfus
Copy link
Contributor Author

Alfus commented Nov 30, 2023

Not quite sure where/how to write tests that depend on protovalidate. I see

func testLintWithValidate(
, maybe this could be generalized?

@Alfus Alfus marked this pull request as ready for review November 30, 2023 20:56
@Alfus Alfus requested a review from bufdev November 30, 2023 20:56
internal.WithSingleFormat(formatBinpb),
internal.WithSingleFormat(
formatBin,
internal.WithSingleCustomOptionKey(validateKey),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate shouldn't be on anything except yaml right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can validate any message, after it has been decoded. protoyaml just provide better errors if you give it the validator directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

@bufdev bufdev merged commit c909328 into main Feb 8, 2024
8 checks passed
@bufdev bufdev deleted the alfus/validate branch February 8, 2024 18:13
bufdev added a commit that referenced this pull request Feb 8, 2024
bufdev added a commit that referenced this pull request Feb 8, 2024
Reverts #2633. We want to limit this
to just `buf convert --from` - there's no usecase otherwise (no need to
validate `--to`, and `Images` do not use protovalidate).
bufdev added a commit that referenced this pull request Feb 8, 2024
Follow-up to #2633 and
#2755.

This adds a flag `buf convert --validate` to validate incoming messages
specified with `--from` using protovalidate.
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

Successfully merging this pull request may close these issues.

2 participants