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

Implement predefined field constraints #178

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jchadwick-buf
Copy link
Member

@jchadwick-buf jchadwick-buf commented Sep 12, 2024

  • Adds the ability to specify an ExtensionRegistry and a TypeRegistry for resolving protobuf messages. Ordinarily, only a TypeRegistry would necessarily be needed. However, we need to be able to resolve extensions defined in file descriptor sets we don't control, which means we need to be able to reparse to and from the user's descriptors in the worst case: to the user's descriptors to get the extended rule message (whose message type descriptors may have a different hashcode and thus may not resolve using just an ExtensionRegistry alone) and back from the user's descriptors in order to parse the priv/shared field.
  • Refactors some of the code around reparsing and extensions in general:
    • Reparsing options for protovalidate built-ins will always use a static extension registry.
  • Adds the rule variable.
    • Some refactoring is done around the individual rule compilation, since the code was getting a bit unwieldy.
  • Updates the conformance runner to generate an ExtensionRegistry and a TypeRegistry. This enables the conformance runner to pass both the old conformance test suite and the new one, regardless of whether the proto descriptors match up.

TODO:

  • Update to new version of protovalidate protos when they are merged.

This will depend on bufbuild/protovalidate#246.

@jchadwick-buf jchadwick-buf marked this pull request as draft September 12, 2024 14:14
@jchadwick-buf jchadwick-buf marked this pull request as draft September 12, 2024 14:14
@jchadwick-buf jchadwick-buf marked this pull request as ready for review September 19, 2024 17:51
@jchadwick-buf
Copy link
Member Author

We still need to synchronize this to the latest version of protovalidate, but that is held up for now. This can be reviewed/merged earlier if desired; it should pass all relevant conformance tests, except for the boolean rules fixes, because those would require the internal set of proto descriptors to be up-to-date. I'm going to push for reviews now so we can get this closed up as soon as possible.

@jchadwick-buf
Copy link
Member Author

OK, it is now synchronized to Protovalidate v0.8.1 and should be ready to go.

@jchadwick-buf jchadwick-buf removed the request for review from pkwarren September 24, 2024 14:15
@jchadwick-buf
Copy link
Member Author

I decided to go over this PR today and made some adjustments.

Updated to add an allowUnknownFields option and have unknown fields behavior match other runtimes closer. Added a test that tests predefined fields with dynamic descriptor sets. Made a slight adjustment to TypeRegistry behavior so that it's possible to fall back to the built-in descriptors when appropriate (e.g. when using an ExtensionRegistry with generated code.)

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.

1 participant