Isn't re-usability lost when xpaths is used in nodes which are under grouping?

There are cases where in we use xpaths in must or when statements under leaf or container.
say,

> leaf A {
>   when "../xyz";
>   type uint8;
> }

So here the xpath specified in the leaf A is referring to another node xyz under its parent.

So using xpath in this way, makes the model kind of hard-coded taking away the flexibility of reusing.

Doesn’t it restrict it from making it as grouping?
Because if I keep this under a grouping and want to reuse this grouping under different branches of the schema tree, then it poses problem as ../xyz may not be applicable in all the places where this grouping would be used.

Agreed - relative paths (whether from must, when, or leafref) in a grouping, that refer to nodes outside the grouping, are in general a Bad Idea™ - i.e. if a “group of statements” has such references, it is not a good candidate for a “grouping” statement. There may be special cases where it makes sense due to the overall structure of a YANG module, but in those cases it would probably make more sense to have also the referenced nodes included in the grouping - relative paths within the grouping is not a problem.

Absolute paths refering to nodes outside the grouping (e.g. /interfaces/interface/name) should be fine though - the semantics of such paths don’t change depending on where in the schema tree the grouping is used.

1 Like

Thanks @per. That is the good suggestion.