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

[Feature Request] Go API for fetching predefined constraints #147

Closed
sudorandom opened this issue Sep 30, 2024 · 1 comment · Fixed by #151
Closed

[Feature Request] Go API for fetching predefined constraints #147

sudorandom opened this issue Sep 30, 2024 · 1 comment · Fixed by #151
Assignees
Labels
Feature New feature or request

Comments

@sudorandom
Copy link

Feature description:
protovalidate-go has an API for easily fetching field/message/oneof constraints in the resolver package. I propose that we add a similar API for getting predefined constraints in a similar way.

I see that there is code in the cache to fetch them but it seems like there’s not an exposed way to do something similar.

Problem it solves or use case:
It's useful for me to get protovalidate constraints in order to annotate generated OpenAPI specifications from protobuf. I suppose it may be useful for others as well.

Proposed implementation or solution:
ResolveFieldConstraints, ResolveMessageConstraints and ResolveOneofConstraints could be augmented to resolve the predefined constraints from extensions containing validate.E_Predefined.

Contribution:
protobuf extensions are pretty crazy to me, but I can help if there's no movement on this after a while.

Examples or references:
https://pkg.go.dev/github.com/bufbuild/[email protected]/resolver

Additional context:

@jchadwick-buf
Copy link
Member

Thinking about it a bit, at the moment, there's no particular reason for the StandardConstraintResolver interface to actually have a method for resolving the predefined constraint fields. However, maybe in spite of that, we could just provide a ResolvePredefinedConstraints method on DefaultResolver anyhow, just for convenience. If there's no objections, that's probably what I'll wind up doing.

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

Successfully merging a pull request may close this issue.

2 participants