openconfig / ygot

A YANG-centric Go toolkit - Go/Protobuf Code Generation; Validation; Marshaling/Unmarshaling
Apache License 2.0
284 stars 107 forks source link

Validate with LeafrefOptions should allow a path mask to be specified. #151

Open robshakir opened 6 years ago

robshakir commented 6 years ago

Currently, LeafrefOptions allows missing references to be ignored during a Validate call. For example, where a leafref references some entity that is missing. However, it does this over the whole tree - essentially turning off all reference validation.

Some callers may know the subset of the tree that they expect to be populated - e.g., a method that is populating all of the BGP subtree may expect peer groups to exist, but doesn't know that routing policy has been populated. Given that this is the case, we should extend the LeafrefOptions struct to take a set of path expressions that specify a mask for the paths that are validated.

The API to this feature is suggested to look something like the following:

d := &oc.Device{}
// populate d.
if err := d.Validate(&ytypes.LeafrefOpts{Paths: []string{"/network-instances/network-instance/protocols/bgp.*"}}); err != nil {
  // handle error
}

Where the Paths field is a string slice containing a set of regular expressions which match gNMI path format strings.

ostromart commented 6 years ago

sgtm, my only suggestion would be to consider IgnorePaths since this may be a more common scenario? i.e. validate all refs except these ones I'm excluding.

mum4k commented 6 years ago

+1 on what ostromart said, I thought about this again and I think that we will need the option to specify what to ignore. Maybe the API can support both includes and ignores?

robshakir commented 6 years ago

SGTM -- it's pretty trivial to implement both.