ygot icon indicating copy to clipboard operation
ygot copied to clipboard

Should choice and case identifiers be included in leafref path?

Open ythadhani opened this issue 2 years ago • 1 comments

I have the following YANG:

choice a-or-b { case a { list interface { key "name"; leaf name { type string; } } } }

leaf mgmt-interface { type leafref { path "../interface/name"; } }

I want the leaf "mgmt-interface" to reference the leaf "name". If I use the path "../interface/name", I run into the failure: ERROR Generating GoStruct Code: unable to resolve leafref field: could not resolve leafref path...

This occurs because the schemaTree at: https://github.com/openconfig/ygot/blob/master/ygen/schematree.go#L83 contains the choice and case identifiers: "a-or-b", "a" as branches. It works if I change my leafref path to: "../a-or-b/a/interface/name".

Should the schemaTree contain choice/case statements? If yes, should I update my leafref path to: "../a-or-b/a/interface/name" or should ygot be ignoring case/choice branches while walking the schema tree looking for leafs?

ythadhani avatar Oct 04 '22 08:10 ythadhani

Yes this does appear to be an oversight. When adding nodes to the schematree we should skip through choice/case elements instead of adding them.

I think fixing involves changing schemaTreeChildrenAdd() such that instead of calling util.Children, util.FindFirstNonChoiceOrCase is called instead.

wenovus avatar Oct 04 '22 17:10 wenovus