Skip to content

Conversation

@doriable
Copy link
Member

@doriable doriable commented May 9, 2025

Currently when a user attempts to set protovalidate examples
without constraints, buf lint returns a violation:

{"path":"...,"start_line":#,"start_column":#,"end_line"#:,"end_column":#,"type":"PROTOVALIDATE","message":"example value is specified by there are no constraints defined"}

However, it should be valid to set examples without constraints.
This removes the constraints check when validating examples.
If a user sets a valid example with no constraints, no violation is surfaced.
If a user sets an invalid example type, then this is caught in the constraint
type check.

Fixes #3830

@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2025

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMay 12, 2025, 4:36 PM

return true
})
}
if !hasRules {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: if there are no rules, could we return early here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah -- given that we already check that the appropriate example type is set, all other errors would be compilation errors when building the image (e.g. if I set something like string id = 1 [(buf.validate.field).string.example = 42];). So yeah, this makes sense, pushed an update!

@doriable doriable merged commit cbdbf63 into main May 12, 2025
10 checks passed
@doriable doriable deleted the buf-3830-example-no-constraints branch May 12, 2025 17:08
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.

Still check example values set with protovalidate even if there are no constraints to validate

5 participants