How to check that a leaf contains only any value from a leaf-list from yang


i want to add a must statement in yang that leaf should have only the values from a particular leaf list.


Have a look at the leafref type (see section 9.9. The leafref Built-In Type in RFC 7950 and sections 3.10 and 3.11 in the ConfD UG).

This could not help. Actually, in my data model a leaf list is there, and a leaf is there which can only be set as member of that leaf list. I donot want leafref, I want to add a must statement for the same validation that leaf a should get values from that leaf list. Is it possible

From your description, I don’t see why a leafref as @jjohansson points to won’t work for you. A leafref will be a simpler way to check that the leaf value exists in the leaflist.
Perhaps you can share a YANG example to show the leaf and leafref nodes and explain why you need a must statement instead of a leafref?

I cannot use leafref because the leaf can have possible values from a leaf list or a list. Is there any way to give two leafrefs path for the same leaf.

Suppose following:
leaf-list a of type string
and a list with key b of type string
and a leaf c

The leaf c can be set with any of the possible values of leaf list a or any of the list b’s key

You can try something like this for example:

leaf-list a { type string; }

list bs {
  key b;
  leaf b { type string; }
  leaf c {
    type string;
    must ". = ../../a or . = ../../bs/b" {
      error-message "c must exist in a or in bs";