Skip to content

Commit 774da77

Browse files
authored
Restore updated documentation in validate.proto (#328)
To be merged once we're ready to ship all implementations conforming to #320. (Updates to the comments have been reverted in #327)
1 parent 761233d commit 774da77

File tree

2 files changed

+184
-91
lines changed

2 files changed

+184
-91
lines changed

proto/protovalidate/buf/validate/validate.proto

Lines changed: 92 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,10 +3276,16 @@ message StringRules {
32763276
}];
32773277

32783278
// `WellKnown` rules provide advanced constraints against common string
3279-
// patterns
3279+
// patterns.
32803280
oneof well_known {
3281-
// `email` specifies that the field value must be a valid email address
3282-
// (addr-spec only) as defined by [RFC 5322](https://datatracker.ietf.org/doc/html/rfc5322#section-3.4.1).
3281+
// `email` specifies that the field value must be a valid email address, for
3282+
// example "[email protected]".
3283+
//
3284+
// Conforms to the definition for a valid email address from the [HTML standard](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address).
3285+
// Note that this standard willfully deviates from [RFC 5322](https://datatracker.ietf.org/doc/html/rfc5322),
3286+
// which allows many unexpected forms of email addresses and will easily match
3287+
// a typographical error.
3288+
//
32833289
// If the field value isn't a valid email address, an error message will be generated.
32843290
//
32853291
// ```proto
@@ -3301,10 +3307,18 @@ message StringRules {
33013307
}
33023308
];
33033309

3304-
// `hostname` specifies that the field value must be a valid
3305-
// hostname as defined by [RFC 1034](https://datatracker.ietf.org/doc/html/rfc1034#section-3.5). This constraint doesn't support
3306-
// internationalized domain names (IDNs). If the field value isn't a
3307-
// valid hostname, an error message will be generated.
3310+
// `hostname` specifies that the field value must be a valid hostname, for
3311+
// example "foo.example.com".
3312+
//
3313+
// A valid hostname follows the rules below:
3314+
// - The name consists of one or more labels, separated by a dot (".").
3315+
// - Each label can be 1 to 63 alphanumeric characters.
3316+
// - A label can contain hyphens ("-"), but must not start or end with a hyphen.
3317+
// - The right-most label must not be digits only.
3318+
// - The name can have a trailing dot—for example, "foo.example.com.".
3319+
// - The name can be 253 characters at most, excluding the optional trailing dot.
3320+
//
3321+
// If the field value isn't a valid hostname, an error message will be generated.
33083322
//
33093323
// ```proto
33103324
// message MyString {
@@ -3325,8 +3339,15 @@ message StringRules {
33253339
}
33263340
];
33273341

3328-
// `ip` specifies that the field value must be a valid IP
3329-
// (v4 or v6) address, without surrounding square brackets for IPv6 addresses.
3342+
// `ip` specifies that the field value must be a valid IP (v4 or v6) address.
3343+
//
3344+
// IPv4 addresses are expected in the dotted decimal format—for example, "192.168.5.21".
3345+
// IPv6 addresses are expected in their text representation—for example, "::1",
3346+
// or "2001:0DB8:ABCD:0012::0".
3347+
//
3348+
// Both formats are well-defined in the internet standard [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986).
3349+
// Zone identifiers for IPv6 addresses (for example, "fe80::a%en1") are supported.
3350+
//
33303351
// If the field value isn't a valid IP address, an error message will be
33313352
// generated.
33323353
//
@@ -3349,9 +3370,9 @@ message StringRules {
33493370
}
33503371
];
33513372

3352-
// `ipv4` specifies that the field value must be a valid IPv4
3353-
// address. If the field value isn't a valid IPv4 address, an error message
3354-
// will be generated.
3373+
// `ipv4` specifies that the field value must be a valid IPv4 address—for
3374+
// example "192.168.5.21". If the field value isn't a valid IPv4 address, an
3375+
// error message will be generated.
33553376
//
33563377
// ```proto
33573378
// message MyString {
@@ -3372,9 +3393,9 @@ message StringRules {
33723393
}
33733394
];
33743395

3375-
// `ipv6` specifies that the field value must be a valid
3376-
// IPv6 address, without surrounding square brackets. If the field value is
3377-
// not a valid IPv6 address, an error message will be generated.
3396+
// `ipv6` specifies that the field value must be a valid IPv6 address—for
3397+
// example "::1", or "d7a:115c:a1e0:ab12:4843:cd96:626b:430b". If the field
3398+
// value is not a valid IPv6 address, an error message will be generated.
33783399
//
33793400
// ```proto
33803401
// message MyString {
@@ -3395,8 +3416,11 @@ message StringRules {
33953416
}
33963417
];
33973418

3398-
// `uri` specifies that the field value must be a valid URI as defined by
3399-
// [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-3).
3419+
// `uri` specifies that the field value must be a valid URI, for example
3420+
// "https://example.com/foo/bar?baz=quux#frag".
3421+
//
3422+
// URI is defined in the internet standard [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986).
3423+
// Zone Identifiers in IPv6 address literals are supported ([RFC 6874](https://datatracker.ietf.org/doc/html/rfc6874)).
34003424
//
34013425
// If the field value isn't a valid URI, an error message will be generated.
34023426
//
@@ -3419,11 +3443,13 @@ message StringRules {
34193443
}
34203444
];
34213445

3422-
// `uri_ref` specifies that the field value must be a valid URI Reference as
3423-
// defined by [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-4.1).
3446+
// `uri_ref` specifies that the field value must be a valid URI Reference—either
3447+
// a URI such as "https://example.com/foo/bar?baz=quux#frag", or a Relative
3448+
// Reference such as "./foo/bar?query".
34243449
//
3425-
// A URI Reference is either a [URI](https://datatracker.ietf.org/doc/html/rfc3986#section-3),
3426-
// or a [Relative Reference](https://datatracker.ietf.org/doc/html/rfc3986#section-4.2).
3450+
// URI, URI Reference, and Relative Reference are defined in the internet
3451+
// standard [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986). Zone
3452+
// Identifiers in IPv6 address literals are supported ([RFC 6874](https://datatracker.ietf.org/doc/html/rfc6874)).
34273453
//
34283454
// If the field value isn't a valid URI Reference, an error message will be
34293455
// generated.
@@ -3441,10 +3467,9 @@ message StringRules {
34413467
}];
34423468

34433469
// `address` specifies that the field value must be either a valid hostname
3444-
// as defined by [RFC 1034](https://datatracker.ietf.org/doc/html/rfc1034#section-3.5)
3445-
// (which doesn't support internationalized domain names or IDNs) or a valid
3446-
// IP (v4 or v6). If the field value isn't a valid hostname or IP, an error
3447-
// message will be generated.
3470+
// (for example, "example.com"), or a valid IP (v4 or v6) address (for example,
3471+
// "192.168.0.1", or "::1"). If the field value isn't a valid hostname or IP,
3472+
// an error message will be generated.
34483473
//
34493474
// ```proto
34503475
// message MyString {
@@ -3512,10 +3537,10 @@ message StringRules {
35123537
}
35133538
];
35143539

3515-
// `ip_with_prefixlen` specifies that the field value must be a valid IP (v4 or v6)
3516-
// address with prefix length. If the field value isn't a valid IP with prefix
3517-
// length, an error message will be generated.
3518-
//
3540+
// `ip_with_prefixlen` specifies that the field value must be a valid IP
3541+
// (v4 or v6) address with prefix length—for example, "192.168.5.21/16" or
3542+
// "2001:0DB8:ABCD:0012::F1/64". If the field value isn't a valid IP with
3543+
// prefix length, an error message will be generated.
35193544
//
35203545
// ```proto
35213546
// message MyString {
@@ -3537,9 +3562,9 @@ message StringRules {
35373562
];
35383563

35393564
// `ipv4_with_prefixlen` specifies that the field value must be a valid
3540-
// IPv4 address with prefix.
3541-
// If the field value isn't a valid IPv4 address with prefix length,
3542-
// an error message will be generated.
3565+
// IPv4 address with prefix length—for example, "192.168.5.21/16". If the
3566+
// field value isn't a valid IPv4 address with prefix length, an error
3567+
// message will be generated.
35433568
//
35443569
// ```proto
35453570
// message MyString {
@@ -3561,7 +3586,7 @@ message StringRules {
35613586
];
35623587

35633588
// `ipv6_with_prefixlen` specifies that the field value must be a valid
3564-
// IPv6 address with prefix length.
3589+
// IPv6 address with prefix length—for example, "2001:0DB8:ABCD:0012::F1/64".
35653590
// If the field value is not a valid IPv6 address with prefix length,
35663591
// an error message will be generated.
35673592
//
@@ -3584,10 +3609,15 @@ message StringRules {
35843609
}
35853610
];
35863611

3587-
// `ip_prefix` specifies that the field value must be a valid IP (v4 or v6) prefix.
3612+
// `ip_prefix` specifies that the field value must be a valid IP (v4 or v6)
3613+
// prefix—for example, "192.168.0.0/16" or "2001:0DB8:ABCD:0012::0/64".
3614+
//
3615+
// The prefix must have all zeros for the unmasked bits. For example,
3616+
// "2001:0DB8:ABCD:0012::0/64" designates the left-most 64 bits for the
3617+
// prefix, and the remaining 64 bits must be zero.
3618+
//
35883619
// If the field value isn't a valid IP prefix, an error message will be
3589-
// generated. The prefix must have all zeros for the masked bits of the prefix (e.g.,
3590-
// `127.0.0.0/16`, not `127.0.0.1/16`).
3620+
// generated.
35913621
//
35923622
// ```proto
35933623
// message MyString {
@@ -3609,9 +3639,14 @@ message StringRules {
36093639
];
36103640

36113641
// `ipv4_prefix` specifies that the field value must be a valid IPv4
3612-
// prefix. If the field value isn't a valid IPv4 prefix, an error message
3613-
// will be generated. The prefix must have all zeros for the masked bits of
3614-
// the prefix (e.g., `127.0.0.0/16`, not `127.0.0.1/16`).
3642+
// prefix, for example "192.168.0.0/16".
3643+
//
3644+
// The prefix must have all zeros for the unmasked bits. For example,
3645+
// "192.168.0.0/16" designates the left-most 16 bits for the prefix,
3646+
// and the remaining 16 bits must be zero.
3647+
//
3648+
// If the field value isn't a valid IPv4 prefix, an error message
3649+
// will be generated.
36153650
//
36163651
// ```proto
36173652
// message MyString {
@@ -3632,10 +3667,15 @@ message StringRules {
36323667
}
36333668
];
36343669

3635-
// `ipv6_prefix` specifies that the field value must be a valid IPv6 prefix.
3670+
// `ipv6_prefix` specifies that the field value must be a valid IPv6 prefix—for
3671+
// example, "2001:0DB8:ABCD:0012::0/64".
3672+
//
3673+
// The prefix must have all zeros for the unmasked bits. For example,
3674+
// "2001:0DB8:ABCD:0012::0/64" designates the left-most 64 bits for the
3675+
// prefix, and the remaining 64 bits must be zero.
3676+
//
36363677
// If the field value is not a valid IPv6 prefix, an error message will be
3637-
// generated. The prefix must have all zeros for the masked bits of the prefix
3638-
// (e.g., `2001:db8::/48`, not `2001:db8::1/48`).
3678+
// generated.
36393679
//
36403680
// ```proto
36413681
// message MyString {
@@ -3656,10 +3696,16 @@ message StringRules {
36563696
}
36573697
];
36583698

3659-
// `host_and_port` specifies the field value must be a valid host and port
3660-
// pair. The host must be a valid hostname or IP address while the port
3661-
// must be in the range of 0-65535, inclusive. IPv6 addresses must be delimited
3662-
// with square brackets (e.g., `[::1]:1234`).
3699+
// `host_and_port` specifies that the field value must be valid host/port
3700+
// pair—for example, "example.com:8080".
3701+
//
3702+
// The host can be one of:
3703+
//- An IPv4 address in dotted decimal format—for example, "192.168.5.21".
3704+
//- An IPv6 address enclosed in square brackets—for example, "[2001:0DB8:ABCD:0012::F1]".
3705+
//- A hostname—for example, "example.com".
3706+
//
3707+
// The port is separated by a colon. It must be non-empty, with a decimal number
3708+
// in the range of 0-65535, inclusive.
36633709
bool host_and_port = 32 [
36643710
(predefined).cel = {
36653711
id: "string.host_and_port"

0 commit comments

Comments
 (0)