Conversation
The uuid and tuuid rules only enforce the textual shape, which is deliberate so that future UUID versions are not rejected. These new rules restrict a value to the UUID types listed, checking the version and the RFC 9562 variant, with the Nil and Max UUIDs as special cases. The documentation of uuid and tuuid now says that they check the shape only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #530.
As discussed in that issue,
string.uuidandstring.tuuidkeep checking the shape only, so that UUID versions defined in the future are not rejected, and their documentation now says so. This addsstring.uuid_typesandstring.tuuid_typesfor callers who do want the stricter check.A listed version must also carry the RFC 9562 variant (
8,9,aorb), since a version without it is not a UUID of that version.UUID_NILandUUID_MAXare the two special cases that follow neither rule. An empty list means no restriction, andUUID_UNSPECIFIEDmatches nothing.No custom CEL function needed
The issue mentioned pushing this down into a custom CEL function. It turned out not to be necessary: the version is the only part of the pattern that varies, and it is the decimal digit of the enum value, so the expression builds the pattern from
string(t).That keeps this PR to the schema and the conformance suite, and means no runtime needs a new function to implement it. A dynamic argument to
matchesis already used bystring.well_known_regex.Changes
validate.proto: aUuidenum (UUID_V1throughUUID_V8,UUID_NIL,UUID_MAX), theuuid_types(39) andtuuid_types(40) rules with their*_emptycompanions, and reworded documentation foruuidandtuuid.strings.protoand 21 cases covering both rules, including the variant check, the Nil and Max UUIDs, an unspecified list, and a dashed value given totuuid_types.tools/internal/gen: regenerated.Checks
buf lint,buf format,make lint-protovalidate,go build ./tools/...,go vet ./tools/...andgo test ./tools/protovalidate-conformance/...pass. (TestMigratorfails for me onmainas well, before this change: it compares golden files and I am on Windows.)To confirm the expressions themselves, I evaluated them exactly as written in
validate.proto, with the rule list substituted, against every value in the new conformance cases. All 24 evaluations matched the expected outcome under both CEL implementations, protovalidate-es and protovalidate-go.Open questions
UuidwithUUID_V4follows the sketch in the issue and satisfiesENUM_VALUE_PREFIX. If you would rather haveUuidTypewithUUID_TYPE_V4, say the word.c/d) or the reserved variant (e/f), I can add values for them.