Skip to content

Commit

Permalink
update cel expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversun9 committed Sep 11, 2024
1 parent 28d4aa9 commit d5569d4
Show file tree
Hide file tree
Showing 2 changed files with 2,547 additions and 2,493 deletions.
88 changes: 44 additions & 44 deletions proto/protovalidate/buf/validate/validate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ message FloatRules {
// infinite or NaN, an error message is generated.
bool finite = 8 [(priv.field).cel = {
id: "float.finite"
expression: "this.isNan() || this.isInf() ? 'value must be finite' : ''"
expression: "rules.finite ? (this.isNan() || this.isInf() ? 'value must be finite' : '') : ''"
}];

// `example` specifies values that the field may have. These values SHOULD
Expand Down Expand Up @@ -753,7 +753,7 @@ message DoubleRules {
// infinite or NaN, an error message is generated.
bool finite = 8 [(priv.field).cel = {
id: "double.finite"
expression: "this.isNan() || this.isInf() ? 'value must be finite' : ''"
expression: "rules.finite ? (this.isNan() || this.isInf() ? 'value must be finite' : '') : ''"
}];

// `example` specifies values that the field may have. These values SHOULD
Expand Down Expand Up @@ -3066,12 +3066,12 @@ message StringRules {
(priv.field).cel = {
id: "string.email"
message: "value must be a valid email address"
expression: "this == '' || this.isEmail()"
expression: "!rules.email || this == '' || this.isEmail()"
},
(priv.field).cel = {
id: "string.email_empty"
message: "value is empty, which is not a valid email address"
expression: "this != ''"
expression: "!rules.email || this != ''"
}
];

Expand All @@ -3090,12 +3090,12 @@ message StringRules {
(priv.field).cel = {
id: "string.hostname"
message: "value must be a valid hostname"
expression: "this == '' || this.isHostname()"
expression: "!rules.hostname || this == '' || this.isHostname()"
},
(priv.field).cel = {
id: "string.hostname_empty"
message: "value is empty, which is not a valid hostname"
expression: "this != ''"
expression: "!rules.hostname || this != ''"
}
];

Expand All @@ -3114,12 +3114,12 @@ message StringRules {
(priv.field).cel = {
id: "string.ip"
message: "value must be a valid IP address"
expression: "this == '' || this.isIp()"
expression: "!rules.ip || this == '' || this.isIp()"
},
(priv.field).cel = {
id: "string.ip_empty"
message: "value is empty, which is not a valid IP address"
expression: "this != ''"
expression: "!rules.ip || this != ''"
}
];

Expand All @@ -3137,12 +3137,12 @@ message StringRules {
(priv.field).cel = {
id: "string.ipv4"
message: "value must be a valid IPv4 address"
expression: "this == '' || this.isIp(4)"
expression: "!rules.ipv4 || this == '' || this.isIp(4)"
},
(priv.field).cel = {
id: "string.ipv4_empty"
message: "value is empty, which is not a valid IPv4 address"
expression: "this != ''"
expression: "!rules.ipv4 || this != ''"
}
];

Expand All @@ -3160,12 +3160,12 @@ message StringRules {
(priv.field).cel = {
id: "string.ipv6"
message: "value must be a valid IPv6 address"
expression: "this == '' || this.isIp(6)"
expression: "!rules.ipv6 || this == '' || this.isIp(6)"
},
(priv.field).cel = {
id: "string.ipv6_empty"
message: "value is empty, which is not a valid IPv6 address"
expression: "this != ''"
expression: "!rules.ipv6 || this != ''"
}
];

Expand All @@ -3183,12 +3183,12 @@ message StringRules {
(priv.field).cel = {
id: "string.uri"
message: "value must be a valid URI"
expression: "this == '' || this.isUri()"
expression: "!rules.uri || this == '' || this.isUri()"
},
(priv.field).cel = {
id: "string.uri_empty"
message: "value is empty, which is not a valid URI"
expression: "this != ''"
expression: "!rules.uri || this != ''"
}
];

Expand All @@ -3205,7 +3205,7 @@ message StringRules {
bool uri_ref = 18 [(priv.field).cel = {
id: "string.uri_ref"
message: "value must be a valid URI"
expression: "this.isUriRef()"
expression: "!rules.uri_ref || this.isUriRef()"
}];

// `address` specifies that the field value must be either a valid hostname
Expand All @@ -3224,12 +3224,12 @@ message StringRules {
(priv.field).cel = {
id: "string.address"
message: "value must be a valid hostname, or ip address"
expression: "this == '' || this.isHostname() || this.isIp()"
expression: "!rules.address || this == '' || this.isHostname() || this.isIp()"
},
(priv.field).cel = {
id: "string.address_empty"
message: "value is empty, which is not a valid hostname, or ip address"
expression: "this != ''"
expression: "!rules.address || this != ''"
}
];

Expand All @@ -3247,12 +3247,12 @@ message StringRules {
(priv.field).cel = {
id: "string.uuid"
message: "value must be a valid UUID"
expression: "this == '' || this.matches('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$')"
expression: "!rules.uuid || this == '' || this.matches('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$')"
},
(priv.field).cel = {
id: "string.uuid_empty"
message: "value is empty, which is not a valid UUID"
expression: "this != ''"
expression: "!rules.uuid || this != ''"
}
];

Expand All @@ -3271,12 +3271,12 @@ message StringRules {
(priv.field).cel = {
id: "string.tuuid"
message: "value must be a valid trimmed UUID"
expression: "this == '' || this.matches('^[0-9a-fA-F]{32}$')"
expression: "!rules.tuuid || this == '' || this.matches('^[0-9a-fA-F]{32}$')"
},
(priv.field).cel = {
id: "string.tuuid_empty"
message: "value is empty, which is not a valid trimmed UUID"
expression: "this != ''"
expression: "!rules.tuuid || this != ''"
}
];

Expand All @@ -3295,12 +3295,12 @@ message StringRules {
(priv.field).cel = {
id: "string.ip_with_prefixlen"
message: "value must be a valid IP prefix"
expression: "this == '' || this.isIpPrefix()"
expression: "!rules.ip_with_prefixlen || this == '' || this.isIpPrefix()"
},
(priv.field).cel = {
id: "string.ip_with_prefixlen_empty"
message: "value is empty, which is not a valid IP prefix"
expression: "this != ''"
expression: "!rules.ip_with_prefixlen || this != ''"
}
];

Expand All @@ -3319,12 +3319,12 @@ message StringRules {
(priv.field).cel = {
id: "string.ipv4_with_prefixlen"
message: "value must be a valid IPv4 address with prefix length"
expression: "this == '' || this.isIpPrefix(4)"
expression: "!rules.ipv4_with_prefixlen || this == '' || this.isIpPrefix(4)"
},
(priv.field).cel = {
id: "string.ipv4_with_prefixlen_empty"
message: "value is empty, which is not a valid IPv4 address with prefix length"
expression: "this != ''"
expression: "!rules.ipv4_with_prefixlen || this != ''"
}
];

Expand All @@ -3343,12 +3343,12 @@ message StringRules {
(priv.field).cel = {
id: "string.ipv6_with_prefixlen"
message: "value must be a valid IPv6 address with prefix length"
expression: "this == '' || this.isIpPrefix(6)"
expression: "!rules.ipv6_with_prefixlen || this == '' || this.isIpPrefix(6)"
},
(priv.field).cel = {
id: "string.ipv6_with_prefixlen_empty"
message: "value is empty, which is not a valid IPv6 address with prefix length"
expression: "this != ''"
expression: "!rules.ipv6_with_prefixlen || this != ''"
}
];

Expand All @@ -3367,12 +3367,12 @@ message StringRules {
(priv.field).cel = {
id: "string.ip_prefix"
message: "value must be a valid IP prefix"
expression: "this == '' || this.isIpPrefix(true)"
expression: "!rules.ip_prefix || ip_prefix || cthis == '' || this.isIpPrefix(true)"
},
(priv.field).cel = {
id: "string.ip_prefix_empty"
message: "value is empty, which is not a valid IP prefix"
expression: "this != ''"
expression: "!rules.ip_prefic || this != ''"
}
];

Expand All @@ -3391,12 +3391,12 @@ message StringRules {
(priv.field).cel = {
id: "string.ipv4_prefix"
message: "value must be a valid IPv4 prefix"
expression: "this == '' || this.isIpPrefix(4, true)"
expression: "!rules.ipv4_prefix || this == '' || this.isIpPrefix(4, true)"
},
(priv.field).cel = {
id: "string.ipv4_prefix_empty"
message: "value is empty, which is not a valid IPv4 prefix"
expression: "this != ''"
expression: "!rules.ipv4_prefix || this != ''"
}
];

Expand All @@ -3415,12 +3415,12 @@ message StringRules {
(priv.field).cel = {
id: "string.ipv6_prefix"
message: "value must be a valid IPv6 prefix"
expression: "this == '' || this.isIpPrefix(6, true)"
expression: "!rules.ipv6_prefix || this == '' || this.isIpPrefix(6, true)"
},
(priv.field).cel = {
id: "string.ipv6_prefix_empty"
message: "value is empty, which is not a valid IPv6 prefix"
expression: "this != ''"
expression: "!rules.ipv6_prefix || this != ''"
}
];

Expand All @@ -3432,12 +3432,12 @@ message StringRules {
(priv.field).cel = {
id: "string.host_and_port"
message: "value must be a valid host (hostname or IP address) and port pair"
expression: "this == '' || this.isHostAndPort(true)"
expression: "!rules.host_and_port || this == '' || this.isHostAndPort(true)"
},
(priv.field).cel = {
id: "string.host_and_port_empty"
message: "value is empty, which is not a valid host and port pair"
expression: "this != ''"
expression: "!rules.host_and_port || this != ''"
}
];

Expand Down Expand Up @@ -3699,12 +3699,12 @@ message BytesRules {
(priv.field).cel = {
id: "bytes.ip"
message: "value must be a valid IP address"
expression: "this.size() == 0 || this.size() == 4 || this.size() == 16"
expression: "!rules.ip || this.size() == 0 || this.size() == 4 || this.size() == 16"
},
(priv.field).cel = {
id: "bytes.ip_empty"
message: "value is empty, which is not a valid IP address"
expression: "this.size() != 0"
expression: "!rules.ip || this.size() != 0"
}
];

Expand All @@ -3721,12 +3721,12 @@ message BytesRules {
(priv.field).cel = {
id: "bytes.ipv4"
message: "value must be a valid IPv4 address"
expression: "this.size() == 0 || this.size() == 4"
expression: "!rules.ipv4 || this.size() == 0 || this.size() == 4"
},
(priv.field).cel = {
id: "bytes.ipv4_empty"
message: "value is empty, which is not a valid IPv4 address"
expression: "this.size() != 0"
expression: "!this.ipv4 || this.size() != 0"
}
];

Expand All @@ -3742,12 +3742,12 @@ message BytesRules {
(priv.field).cel = {
id: "bytes.ipv6"
message: "value must be a valid IPv6 address"
expression: "this.size() == 0 || this.size() == 16"
expression: "!this.ipv6 || this.size() == 0 || this.size() == 16"
},
(priv.field).cel = {
id: "bytes.ipv6_empty"
message: "value is empty, which is not a valid IPv6 address"
expression: "this.size() != 0"
expression: "!this.ipv6 || this.size() != 0"
}
];
}
Expand Down Expand Up @@ -3920,7 +3920,7 @@ message RepeatedRules {
optional bool unique = 3 [(priv.field).cel = {
id: "repeated.unique"
message: "repeated value must contain unique items"
expression: "this.unique()"
expression: "!rules.unqiue || this.unique()"
}];

// `items` details the constraints to be applied to each item
Expand Down Expand Up @@ -4288,7 +4288,7 @@ message TimestampRules {
// ```
bool lt_now = 7 [(priv.field).cel = {
id: "timestamp.lt_now"
expression: "this > now ? 'value must be less than now' : ''"
expression: "rules.lt_now ? (this > now ? 'value must be less than now' : '') : ''"
}];
}
oneof greater_than {
Expand Down Expand Up @@ -4404,7 +4404,7 @@ message TimestampRules {
// ```
bool gt_now = 8 [(priv.field).cel = {
id: "timestamp.gt_now"
expression: "this < now ? 'value must be greater than now' : ''"
expression: "rules.gt_now ? (this < now ? 'value must be greater than now' : '') : ''"
}];
}

Expand Down
Loading

0 comments on commit d5569d4

Please sign in to comment.