mwitkow/go-proto-validators

validator generate incorrect type

vtolstov opened this issue · 7 comments

in my message is have

string size = 2;

when i'm try to generate code

this.Size_ undefined (type *XXX has no field or method Size_)

why filed name changed from Size to Size_ ?

Hello. I am picking up this repo so apologies for the long delay in responding to your issue.

Having a bit more details would help narrow down to what the issue is.

  • Is it still reproducible with the most recent version of go-proto-validators?
  • How can we achieve a minimal reproduction? With what .proto file and what protobuf toolchain / version?

This problem still exists.

See https://github.com/vegaprotocol/testprotosize for a test repo.

Proto

syntax = "proto3";

package proto;
option go_package = "[somerepo]/proto";

import "github.com/mwitkow/go-proto-validators/validator.proto";

message ThingWithSize {
  uint64 size = 1 [(validator.field) = {int_gt: 0}];
}

Script to generate

cd proto
protoc \
	-I. \
	-Ivendor \
	-Ivendor/github.com/protocolbuffers/protobuf/src \
	--go_out=plugins=grpc,paths=source_relative:. \
	--govalidators_out=paths=source_relative:. \
	testsize.proto

Generated validator

func (this *ThingWithSize) Validate() error {
	if !(this.Size_ > 0) {
		return github_com_mwitkow_go_proto_validators.FieldError("Size_", fmt.Errorf(`value '%v' must be greater than '0'`, this.Size_))
	}
	return nil
}

Note: The check is on a non-existent field Size_.

Compile error

proto/testsize.validator.pb.go:20:11: this.Size_ undefined (type *ThingWithSize has no field or method Size_)
proto/testsize.validator.pb.go:21:123: this.Size_ undefined (type *ThingWithSize has no field or method Size_)

Versions

  • go-proto-validators: v0.3.2 (32a686a)

@mwitkow / @Helcaraxan Any chance one of you can look at this one again, please?

@mwitkow / @Helcaraxan ⌛ Any chance one of you can look at this one again, please?

bug still exists