Skip to content

Commit

Permalink
Update examples, conformance harness, & migrator to use new ignore/sk…
Browse files Browse the repository at this point in the history
…ipped annotations (#173)
  • Loading branch information
rodaine authored Feb 21, 2024
1 parent 7d3d1a1 commit 2c6fd61
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
go-version: stable
cache-dependency-path: go.work.sum
- name: Install buf
uses: bufbuild/buf-setup-action@v1
uses: bufbuild/buf-setup-action@v1.29.0
with:
github_token: ${{ github.token }}
- name: Buf format
Expand Down
4 changes: 2 additions & 2 deletions examples/option_field_skip_validation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ service HealthService {

message UpdateHealthInfoRequest {
fixed64 user_id = 1;
// `skipped` skips evaluating validation rules for a certain field. This
// IGNORE_ALWAYS skips evaluating validation rules for a certain field. This
// includes skipping validation rules defined within that message's definition
// if the field is a message.
// In this case, when the validator validates a `UpdateHealthInfoRequest`
// message, it will not validate field `health_info`. i.e. it will not validate
// that health_info.height > 0 and health_info.weight > 0.
HealthInfo health_info = 2 [(buf.validate.field).skipped = true];
HealthInfo health_info = 2 [(buf.validate.field).ignore = IGNORE_ALWAYS];
google.protobuf.FieldMask field_mask = 3;
}

Expand Down
4 changes: 2 additions & 2 deletions proto/protovalidate-testing/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ deps:
- remote: buf.build
owner: bufbuild
repository: protovalidate
commit: 3014d81c3a48461dbcc5b57536699f9e
digest: shake256:6b40454a0754bf624c8fc965f3576bd26bf72a480c554514672d2fac887f420c82d68cf50d40f5a77d8b6e96dda87e395aeedae84d513dde7c4bfd4d95f5657a
commit: f05a6f4403ce4327bae4f50f281c3ed0
digest: shake256:668a0661b8df44d41839194896329330965fc215f3d2f88057fd60eeb759c2daf6cc6edfdd13b2a653d49fe2896ebedcb1a33c4c5b2dd10919f03ffb7fc52ae6
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@ message Proto2ScalarOptionalIgnoreUnspecifiedWithDefault {

message Proto2ScalarOptionalIgnoreEmpty {
optional int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}

message Proto2ScalarOptionalIgnoreEmptyWithDefault {
optional int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0,
default = -42
];
}

message Proto2ScalarOptionalIgnoreDefault {
optional int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).int32.gt = 0
];
}

message Proto2ScalarOptionalIgnoreDefaultWithDefault {
optional int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).int32.gt = 0,
default = -42
];
Expand All @@ -72,29 +72,29 @@ message Proto2ScalarRequiredIgnoreUnspecifiedWithDefault {

message Proto2ScalarRequiredIgnoreEmpty {
required int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}

message Proto2ScalarRequiredIgnoreEmptyWithDefault {
required int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0,
default = -42
];
}

message Proto2ScalarRequiredIgnoreDefault {
required int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).int32.gt = 0
];
}

message Proto2ScalarRequiredIgnoreDefaultWithDefault {
required int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).int32.gt = 0,
default = -42
];
Expand All @@ -113,7 +113,7 @@ message Proto2MessageOptionalIgnoreUnspecified {

message Proto2MessageOptionalIgnoreEmpty {
optional Msg val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).cel = {
id: "proto2.message.ignore.empty",
message: "foobar",
Expand All @@ -127,7 +127,7 @@ message Proto2MessageOptionalIgnoreEmpty {

message Proto2MessageOptionalIgnoreDefault {
optional Msg val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).cel = {
id: "proto2.message.ignore.empty",
message: "foobar",
Expand All @@ -152,7 +152,7 @@ message Proto2MessageRequiredIgnoreUnspecified {

message Proto2MessageRequiredIgnoreEmpty {
required Msg val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).cel = {
id: "proto2.message.ignore.empty",
message: "foobar",
Expand All @@ -166,7 +166,7 @@ message Proto2MessageRequiredIgnoreEmpty {

message Proto2MessageRequiredIgnoreDefault {
required Msg val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).cel = {
id: "proto2.message.ignore.empty",
message: "foobar",
Expand Down Expand Up @@ -196,7 +196,7 @@ message Proto2OneofIgnoreUnspecifiedWithDefault {
message Proto2OneofIgnoreEmpty {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}
Expand All @@ -205,7 +205,7 @@ message Proto2OneofIgnoreEmpty {
message Proto2OneofIgnoreEmptyWithDefault {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0,
default = -42
];
Expand All @@ -215,7 +215,7 @@ message Proto2OneofIgnoreEmptyWithDefault {
message Proto2OneofIgnoreDefault {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).int32.gt = 0
];
}
Expand All @@ -224,7 +224,7 @@ message Proto2OneofIgnoreDefault {
message Proto2OneofIgnoreDefaultWithDefault {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).int32.gt = 0,
default = -42
];
Expand All @@ -237,14 +237,14 @@ message Proto2RepeatedIgnoreUnspecified {

message Proto2RepeatedIgnoreEmpty {
repeated int32 val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).repeated.min_items = 3
];
}

message Proto2RepeatedIgnoreDefault {
repeated int32 val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).repeated.min_items = 3
];
}
Expand All @@ -255,14 +255,14 @@ message Proto2MapIgnoreUnspecified {

message Proto2MapIgnoreEmpty {
map<int32, int32> val = 1 [
(buf.validate.field).ignore = IGNORE_EMPTY,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).map.min_pairs = 3
];
}

message Proto2MapIgnoreDefault {
map<int32, int32> val = 1 [
(buf.validate.field).ignore = IGNORE_DEFAULT,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).map.min_pairs = 3
];
}
Expand All @@ -273,14 +273,14 @@ message Proto2RepeatedItemIgnoreUnspecified {

message Proto2RepeatedItemIgnoreEmpty {
repeated int32 val = 1 [
(buf.validate.field).repeated.items.ignore = IGNORE_EMPTY,
(buf.validate.field).repeated.items.ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).repeated.items.int32.gt = 0
];
}

message Proto2RepeatedItemIgnoreDefault {
repeated int32 val = 1 [
(buf.validate.field).repeated.items.ignore = IGNORE_DEFAULT,
(buf.validate.field).repeated.items.ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).repeated.items.int32.gt = 0
];
}
Expand All @@ -291,14 +291,14 @@ message Proto2MapKeyIgnoreUnspecified {

message Proto2MapKeyIgnoreEmpty {
map<int32, int32> val = 1 [
(buf.validate.field).map.keys.ignore = IGNORE_EMPTY,
(buf.validate.field).map.keys.ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).map.keys.int32.gt = 0
];
}

message Proto2MapKeyIgnoreDefault {
map<int32, int32> val = 1 [
(buf.validate.field).map.keys.ignore = IGNORE_DEFAULT,
(buf.validate.field).map.keys.ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).map.keys.int32.gt = 0
];
}
Expand All @@ -309,14 +309,14 @@ message Proto2MapValueIgnoreUnspecified {

message Proto2MapValueIgnoreEmpty {
map<int32, int32> val = 1 [
(buf.validate.field).map.values.ignore = IGNORE_EMPTY,
(buf.validate.field).map.values.ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).map.values.int32.gt = 0
];
}

message Proto2MapValueIgnoreDefault {
map<int32, int32> val = 1 [
(buf.validate.field).map.values.ignore = IGNORE_DEFAULT,
(buf.validate.field).map.values.ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).map.values.int32.gt = 0
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ message MessageCrossPackage {
other_package.Embed val = 1;
}
message MessageSkip {
TestMsg val = 1 [(buf.validate.field).skipped = true];
TestMsg val = 1 [(buf.validate.field).ignore = IGNORE_ALWAYS];
}
message MessageRequired {
TestMsg val = 1 [(buf.validate.field).required = true];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ message RepeatedItemPattern {
repeated string val = 1 [(buf.validate.field).repeated.items.string.pattern = "(?i)^[a-z0-9]+$"];
}
message RepeatedEmbedSkip {
repeated Embed val = 1 [(buf.validate.field).repeated.items.skipped = true];
repeated Embed val = 1 [(buf.validate.field).repeated.items.ignore = IGNORE_ALWAYS];
}
message RepeatedItemIn {
repeated string val = 1 [(buf.validate.field).repeated.items.string = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ import "validate/validate.proto";
import "buf/validate/validate.proto";

message FieldIgnoreEmpty {
int32 x = 1 [(validate.rules).int32.ignore_empty = true,(buf.validate.field).ignore_empty = true];
int32 x = 1 [(validate.rules).int32.ignore_empty = true,(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED];
string y = 2 [
(validate.rules).int32 = { ignore_empty: false },
(buf.validate.field).int32 = { }
, (buf.validate.field).ignore_empty = false
];
repeated int32 z = 3 [
(validate.rules).repeated.items = {
int32: { ignore_empty: true, gt: 10 };
},
(buf.validate.field).repeated.items = {
int32: { gt: 10 }
, ignore_empty: true;
, ignore: IGNORE_IF_UNPOPULATED;
}
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ message FieldIgnoreEmpty {
int32: { ignore_empty: true, gt: 10 };
}
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import "validate/validate.proto";
import "buf/validate/validate.proto";

message FieldSkipped {
FieldSkipped x = 1 [(validate.rules).message.skip = true,(buf.validate.field).skipped = true];
FieldSkipped x = 1 [(validate.rules).message.skip = true,(buf.validate.field).ignore = IGNORE_ALWAYS];
FieldSkipped y = 2 [
(validate.rules).message = { skip: false },
(buf.validate.field) = { skipped: false }
(buf.validate.field) = { }
];
repeated FieldSkipped z = 3 [
(validate.rules).repeated.items = {
Expand All @@ -35,7 +35,7 @@ message FieldSkipped {
},
(buf.validate.field).repeated.items = {
required: true;
skipped: true,
ignore: IGNORE_ALWAYS,
}
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package tests.migrate;
import "buf/validate/validate.proto";

message FieldSkipped {
FieldSkipped x = 1 [(buf.validate.field).skipped = true];
FieldSkipped x = 1 [(buf.validate.field).ignore = IGNORE_ALWAYS];
FieldSkipped y = 2 [
(buf.validate.field) = { skipped: false }
(buf.validate.field) = { }
];
repeated FieldSkipped z = 3 [
(buf.validate.field).repeated.items = {
required: true;
skipped: true,
ignore: IGNORE_ALWAYS,
}
];
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2c6fd61

Please sign in to comment.