CESNET / libyang

YANG data modeling language library
BSD 3-Clause "New" or "Revised" License
368 stars 292 forks source link

YANG extension nodes paths #2069

Open peckato1 opened 1 year ago

peckato1 commented 1 year ago

Hello,

I was recently trying to work with YANG nodes defined in extension instance. I was looking at this libyang unit test and I don't understand the format of the path for the lyd_new_path call. Why can't I use absolute path to the z leaf, i.e., /ext:c/z? The return is then LY_EVALID with a log message Not found node "c" in path.

Also, documentation of lyd_new_path that * If creating data nodes defined inside an extension instance, use ::lyd_new_ext_path(). which is not entirely true according to this paragraph which states that only first node must be created using the lyd_new_ext_* functions.

michalvasko commented 1 year ago

Why can't I use absolute path to the z leaf, i.e., /ext:c/z?

What if the module ext also defined

container c {
  leaf z {
    type string;
  }
}

You would then get an ambiguity, hence the special functions. The exact extension instance is required because you may even have several extension instances with the same data nodes.

If creating data nodes defined inside an extension instance, use ::lyd_new_ext_path().

It does not say you must use the function for all the nodes but you can :)