Leaf element data type to be either type-a or type-b

How do we define a leaf element data-type to be either of type-a or type-b

ipaddr x netmask y

Where x can be of 2 different types.

–> ipaddr 1.1.1.1 netmask 255.255.255.0 : netmask explicitly given : ipaddr leaf element is inet:ipv4-address
-> ipaddr 1.1.1.1/24 : netmask derived using mask provided : ipaddr leaf element is inet:ipv4-prefix

And is it possible to suppress “netmask” if ipaddr takes type-a and be allowed if it is type-b

tried using choice

choice addr {
case type1 {
leaf ipaddr {
type inet:ipv4-prefix;
}
}
case type2 {
leaf ipaddr { <<<<<<<<<<<<<<<<<< gives error as defined under case type1
type inet:ipv4-address;
}
leaf netmask {
type inet:ipv4-address;
}
}
}

Hello,

did you try to use union type?
https://tools.ietf.org/html/rfc7950#section-9.12