Skip to content

Commit

Permalink
Use proto2 Enum helper instead of toPointer
Browse files Browse the repository at this point in the history
My bad.
  • Loading branch information
jchadwick-buf committed Sep 16, 2024
1 parent 26836d7 commit 4bf8570
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions legacy/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func translateRules(rules protoreflect.Message) *pv.FieldConstraints {
if msgRules.Get(msgDesc.Fields().ByName("required")).Bool() {
constraints.Required = proto.Bool(true)
} else if msgRules.Get(msgDesc.Fields().ByName("skip")).Bool() {
constraints.Ignore = toPointer(pv.Ignore_IGNORE_ALWAYS)
constraints.Ignore = pv.Ignore_IGNORE_ALWAYS.Enum()
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func translateRule(
return true
} else if pgvDesc.Name() == "ignore_empty" && pgvDesc.Kind() == protoreflect.BoolKind && value.Bool() {
// old `ignore_empty` fields on the type rules need to be lifted to the top level
constraints.Ignore = toPointer(pv.Ignore_IGNORE_IF_UNPOPULATED)
constraints.Ignore = pv.Ignore_IGNORE_IF_UNPOPULATED.Enum()
return true
}

Expand Down Expand Up @@ -144,7 +144,3 @@ func translateRule(
}
return true
}

func toPointer[T any](value T) *T {
return &value
}
4 changes: 2 additions & 2 deletions legacy/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestTranslateFieldOptions(t *testing.T) {
msg: &examplev1.LegacySkipped{},
field: "x",
ex: &validate.FieldConstraints{
Ignore: toPointer(validate.Ignore_IGNORE_ALWAYS),
Ignore: validate.Ignore_IGNORE_ALWAYS.Enum(),
},
},
{
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestTranslateFieldOptions(t *testing.T) {
msg: &examplev1.LegacyIgnoreEmpty{},
field: "x",
ex: &validate.FieldConstraints{
Ignore: toPointer(validate.Ignore_IGNORE_IF_UNPOPULATED),
Ignore: validate.Ignore_IGNORE_IF_UNPOPULATED.Enum(),
Type: &validate.FieldConstraints_Int32{
Int32: &validate.Int32Rules{
GreaterThan: &validate.Int32Rules_Gt{
Expand Down

0 comments on commit 4bf8570

Please sign in to comment.