-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrator: properly handle ignore generation on fields (#209)
`ignore` field migration (from `ignore_empty` and `skipped`) was preserving the field type (e.g., `string` or `repeated`) in the new format, which is erroneous. `required` was already handling this correctly, `ignore` just slipped through the cracks here. Fixes #202 Thanks again @pquerna & @jschaf for the reports!
- Loading branch information
Showing
4 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
proto/protovalidate-testing/tests/migrate/field_ignore_skip.migrated.proto
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2023 Buf Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto3"; | ||
|
||
package tests.migrate; | ||
|
||
import "validate/validate.proto"; | ||
|
||
import "buf/validate/validate.proto"; | ||
|
||
message IgnoreAndSkips { | ||
string x = 1 [ | ||
(validate.rules).string = { | ||
ignore_empty: true, | ||
pattern: '^a+$', | ||
}, | ||
(buf.validate.field).string = { | ||
pattern: '^a+$', | ||
} | ||
, (buf.validate.field).ignore = IGNORE_IF_UNPOPULATED | ||
]; | ||
repeated string y = 2 [ | ||
(validate.rules).repeated = { | ||
ignore_empty: true, | ||
unique: true, | ||
items: { string: { in: ['a', 'b'] } } | ||
}, | ||
(buf.validate.field).repeated = { | ||
unique: true, | ||
items: { string: { in: ['a', 'b'] } } | ||
} | ||
, (buf.validate.field).ignore = IGNORE_IF_UNPOPULATED | ||
]; | ||
IgnoreAndSkips z = 3 [ | ||
(validate.rules).message = { skip: true }, | ||
(buf.validate.field) = { } | ||
, (buf.validate.field).ignore = IGNORE_ALWAYS | ||
]; | ||
} |
38 changes: 38 additions & 0 deletions
38
proto/protovalidate-testing/tests/migrate/field_ignore_skip.source.proto
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2023 Buf Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto3"; | ||
|
||
package tests.migrate; | ||
|
||
import "validate/validate.proto"; | ||
|
||
message IgnoreAndSkips { | ||
string x = 1 [ | ||
(validate.rules).string = { | ||
ignore_empty: true, | ||
pattern: '^a+$', | ||
} | ||
]; | ||
repeated string y = 2 [ | ||
(validate.rules).repeated = { | ||
ignore_empty: true, | ||
unique: true, | ||
items: { string: { in: ['a', 'b'] } } | ||
} | ||
]; | ||
IgnoreAndSkips z = 3 [ | ||
(validate.rules).message = { skip: true } | ||
]; | ||
} |
This file contains 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
This file contains 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