Skip to content

Commit c078a54

Browse files
authored
Add (buf.validate.field).bytes.uuid (#435)
1 parent 2b82469 commit c078a54

File tree

5 files changed

+364
-9
lines changed

5 files changed

+364
-9
lines changed

proto/protovalidate-testing/buf/validate/conformance/cases/bytes.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ message BytesIPv6Ignore {
9797
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE
9898
];
9999
}
100+
message BytesUUID {
101+
bytes val = 1 [(buf.validate.field).bytes.uuid = true];
102+
}
103+
message BytesNotUUID {
104+
bytes val = 1 [(buf.validate.field).bytes.uuid = false];
105+
}
106+
message BytesUUIDIgnore {
107+
bytes val = 1 [
108+
(buf.validate.field).bytes.uuid = true,
109+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE
110+
];
111+
}
100112
message BytesExample {
101113
bytes val = 1 [(buf.validate.field).bytes.example = "\x99"];
102114
}

proto/protovalidate/buf/validate/validate.proto

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,6 +4052,31 @@ message BytesRules {
40524052
expression: "!rules.ipv6 || this.size() != 0"
40534053
}
40544054
];
4055+
4056+
// `uuid` ensures that the field `value` encodes the 128-bit UUID data as
4057+
// defined by [RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.2).
4058+
// The field must contain exactly 16 bytes
4059+
// representing the UUID. If the field value isn't a valid UUID, an error
4060+
// message will be generated.
4061+
//
4062+
// ```proto
4063+
// message MyBytes {
4064+
// // value must be a valid UUID
4065+
// optional bytes value = 1 [(buf.validate.field).bytes.uuid = true];
4066+
// }
4067+
// ```
4068+
bool uuid = 15 [
4069+
(predefined).cel = {
4070+
id: "bytes.uuid"
4071+
message: "value must be a valid UUID"
4072+
expression: "!rules.uuid || this.size() == 0 || this.size() == 16"
4073+
},
4074+
(predefined).cel = {
4075+
id: "bytes.uuid_empty"
4076+
message: "value is empty, which is not a valid UUID"
4077+
expression: "!rules.uuid || this.size() != 0"
4078+
}
4079+
];
40554080
}
40564081

40574082
// `example` specifies values that the field may have. These values SHOULD

tools/internal/gen/buf/validate/conformance/cases/bytes.pb.go

Lines changed: 149 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/internal/gen/buf/validate/validate.pb.go

Lines changed: 39 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)