This YANG definition is broken:


 

    leaf name {
        type union {
          type vlan-id-type;
          type string;
          type uint16;
          type binary {
            length 7;
          }
        }
     }




Notice how the "string" type appears before the "binary" and "uint16" types?

The XML encoding of uint16 and binary (base64) are both valid strings.

The YANG tool that processes the input will never encode input as uint16 or binary.


This is how YANG is defined to work.

The member types are evaluated in order.


Always place member types in a union from most selective to least selective.

Plain "string" is the catch-all that will match anything, so put it last.


Correct order for this typedef:


    leaf name {
        type union {
          type vlan-id-type;
          type uint16;
          type binary {
            length 7;
          }
          type string;
        }
     }