protoc-gen-validate
protoc-gen-validate copied to clipboard
Generated field missing or undefined
I have the following protobuf definition:
syntax = "proto3";
package reignite.types;
import "validate/validate.proto";
// Kernel represents the configuration for a kernel.
message Kernel {
// Image is the container image to use.
string image = 1;
// Cmdline is the kernel command line args.
string cmdline = 2;
// Filename is used to specify the name of the kernel file
// in the Image.
optional string filename = 3;
// AddNetworkConfig if set to true indicates that the network-config kernel argument should be generated.
bool add_network_config = 4;
}
I haven't actually added any validation rules yet, but the generated <name>.pb.validate.go
file:
// Validate checks the field values on Kernel with the rules defined in the
// proto definition for this message. If any rules are violated, an error is returned.
func (m *Kernel) Validate() error {
if m == nil {
return nil
}
// no validation rules for Image
// no validation rules for Cmdline
// no validation rules for AddNetworkConfig
switch m.XFilename.(type) {
case *Kernel_Filename:
// no validation rules for Filename
}
return nil
}
Appears to generate a validation on a field that doesn't exist:
m.XFilename undefined (type *Kernel has no field or method XFilename) (MissingFieldOrMethod)
Is it something to do with the fact it is an optional
field? Is there a way around this?
I also encountered this problem. Have you solved this problem?
Has anyone solved this problem?
Looking closer at this, it is almost certainly due to the optional modifier (which is modeled under the hood as a oneof prefixed with X). This is tracked over in: #431
@rodaine Hi, I notice the pr has been merged into 0.6.3. but this issue(generating X* for optional field) still exits. Please help to take a look.
I am currently using this pr
@gopkg-dev could like to share how to use your pr? Is there any plan to merge it in master?
Any status on this? We're still getting this error.
Has there been anymore movement on this? The issue(generating X* for optional field) is still preventing us from using this.
@jrkt I just updated to v0.6.7 and the issue seems to be fixed at least for the Go implementation. You might want to check it out.
Issue confirmed not present in v0.6.8