Skip to content

Commit

Permalink
Implement tweaked map support in FieldPathElement
Browse files Browse the repository at this point in the history
  • Loading branch information
jchadwick-buf committed Nov 25, 2024
1 parent 6b1ec55 commit 6a86800
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ $(BIN)/golangci-lint: $(BIN) Makefile
$(BIN)/protovalidate-conformance: $(BIN) Makefile
# TODO: DO NOT MERGE
GOBIN=$(abspath $(BIN)) $(GO) install \
github.com/bufbuild/protovalidate/tools/protovalidate-conformance@fab41785ae5758b533d64e40b3f400d84ebbba61
github.com/bufbuild/protovalidate/tools/protovalidate-conformance@a4d7e113cc9e8944fb22098123eddc5413500381

.PHONY: protovalidate-conformance-go
protovalidate-conformance-go: $(BIN)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ require (
)

// DO NOT MERGE!
replace buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go => buf.build/gen/go/jchadwick-buf/protovalidate/protocolbuffers/go v1.35.1-20241107000346-6ecee89ee0c9.1
replace buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go => buf.build/gen/go/jchadwick-buf/protovalidate/protocolbuffers/go v1.35.2-20241125171308-fd74cad4128d.1
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buf.build/gen/go/jchadwick-buf/protovalidate/protocolbuffers/go v1.35.1-20241107000346-6ecee89ee0c9.1 h1:AG/SqE0AfoVJpTJeiOIZ1HnfpR+nYWdbW/vDB3qAKlk=
buf.build/gen/go/jchadwick-buf/protovalidate/protocolbuffers/go v1.35.1-20241107000346-6ecee89ee0c9.1/go.mod h1:Cy8tc4XPqN8l0D+F/Jf4Hy9X9a3somHIH9BTkmJJTmo=
buf.build/gen/go/jchadwick-buf/protovalidate/protocolbuffers/go v1.35.2-20241125171308-fd74cad4128d.1 h1:0chXnVxmZm4tHhfMzhU9ge2ppgIDRon6qyKTJyq+hxo=
buf.build/gen/go/jchadwick-buf/protovalidate/protocolbuffers/go v1.35.2-20241125171308-fd74cad4128d.1/go.mod h1:o4wyuJgZD4vOujqo012KwMjMv9PqJw/jk6swwGw3XIo=
cel.dev/expr v0.18.0 h1:CJ6drgk+Hf96lkLikr4rFf19WrU0BOWEihyZnI2TAzo=
cel.dev/expr v0.18.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
Expand Down
2 changes: 0 additions & 2 deletions internal/errors/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ func FieldPathString(path []*validate.FieldPathElement) string {
result.WriteString(strconv.FormatBool(value.BoolKey))
case *validate.FieldPathElement_IntKey:
result.WriteString(strconv.FormatInt(value.IntKey, 10))
case *validate.FieldPathElement_SintKey:
result.WriteString(strconv.FormatInt(value.SintKey, 10))
case *validate.FieldPathElement_UintKey:
result.WriteString(strconv.FormatUint(value.UintKey, 10))
case *validate.FieldPathElement_StringKey:
Expand Down
7 changes: 4 additions & 3 deletions internal/evaluator/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ func (m kvPairs) Evaluate(val protoreflect.Value, failFast bool) (err error) {
evalErr := m.evalPairs(key, value, failFast)
if evalErr != nil {
element := errors.FieldPathElement(m.Descriptor)
element.KeyType = descriptorpb.FieldDescriptorProto_Type(m.Descriptor.MapKey().Kind()).Enum()
element.ValueType = descriptorpb.FieldDescriptorProto_Type(m.Descriptor.MapValue().Kind()).Enum()
switch m.Descriptor.MapKey().Kind() {
case protoreflect.BoolKind:
element.Subscript = &validate.FieldPathElement_BoolKey{BoolKey: key.Bool()}
case protoreflect.Int32Kind, protoreflect.Int64Kind,
protoreflect.Sfixed32Kind, protoreflect.Sfixed64Kind:
protoreflect.Sfixed32Kind, protoreflect.Sfixed64Kind,
protoreflect.Sint32Kind, protoreflect.Sint64Kind:
element.Subscript = &validate.FieldPathElement_IntKey{IntKey: key.Int()}
case protoreflect.Sint32Kind, protoreflect.Sint64Kind:
element.Subscript = &validate.FieldPathElement_SintKey{SintKey: key.Int()}
case protoreflect.Uint32Kind, protoreflect.Uint64Kind,
protoreflect.Fixed32Kind, protoreflect.Fixed64Kind:
element.Subscript = &validate.FieldPathElement_UintKey{UintKey: key.Uint()}
Expand Down

0 comments on commit 6a86800

Please sign in to comment.