Symmetric dependency between Yang leafs

I’ m looking for some help in creating a use case synario using yang,
Trying to implement a Yang model for a table having 4 keys say key-1, key-2, key-3, key-4.

key-1 has possible leaf options as p1, q1,
key-2 has possible leaf options as k1, k2, k3, k4

So requirement here is leaf options k1, k2 options should available only p1 leaf from key-1 is configured, k3,k4 should available only q1 leaf from key-1 is configured.

Any suggestions on how to make this work?


List keys are mandatory leafs.
RFC 7950 YANG 1.1 - The list’s “key” statement

edit: i misread your original post, if the list has 4 keys, then what @cohult stated is true. You cannot condition presence of keys, only limit values of the mandatory keys via must statements…
thus my response further below is not your scenario…, but keeping it for now in case it could be applied as some workaround to limit key values…

I assume that by leaf options, you mean leaf type - enumeration for the key…
This sounds like regular use-case for must statement for leaf/list.
quick pseudo-code:

list mylist {
  must "./key1 == 'p1' and ./key2 != 'k3' and ./key2 != 'k4'" {
    error-message "p1 entry cannot use k3/k4!";
  must "./key1 == 'q1' and ./key2 != 'k1' and ./key2 != 'k2'" {
    error-message "q1 entry cannot use k1/k2!";
  key "key1 key2";
  leaf key1 { .... }
  leaf key2 { .... }

There are probably more performance efficient forms of above must statements.
It also depends on how many values of enumerations you have etc., but it should give a rough idea how to approach it…