From 6a86800994e0ce07fa7b2d7b376ab6adc1d54bf0 Mon Sep 17 00:00:00 2001 From: John Chadwick Date: Mon, 25 Nov 2024 12:25:17 -0500 Subject: [PATCH] Implement tweaked map support in FieldPathElement --- Makefile | 2 +- go.mod | 2 +- go.sum | 4 ++-- internal/errors/utils.go | 2 -- internal/evaluator/map.go | 7 ++++--- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 1aa2b53..6d1191d 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/go.mod b/go.mod index 85d8353..510454c 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 5e81f9c..dc03c7e 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/errors/utils.go b/internal/errors/utils.go index ac23fd4..3e6ddca 100644 --- a/internal/errors/utils.go +++ b/internal/errors/utils.go @@ -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: diff --git a/internal/evaluator/map.go b/internal/evaluator/map.go index 168252f..c3a76a4 100644 --- a/internal/evaluator/map.go +++ b/internal/evaluator/map.go @@ -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()}