From what you describe it seems to me like you want to create a reusable definition of a structure that has two fields: a single uri
and a list of addresses
. The best tool for this job is YANG's grouping. The RFC says that "grouping is like a "structure" or a "record" in conventional programming languages". The below grouping should be what you are looking for:
grouping mapping {
leaf uri {
type inet:uri;
}
list address {
type inet:IpAddress;
}
}
Then you can reference such grouping
by the uses
statement like in the following examples:
container specific_mapping {
uses mapping;
}
and
list my_mapping {
key "uri";
uses mapping;
}
The following instance documents are compatible with the above:
<specific_mapping>
<uri>some uri</uri>
<address>address 1</address>
<address>address 2</address>
</specific_mapping>
and
<my_mapping>
<uri>some uri</uri>
<address>address 1</address>
<address>address 2</address>
</my_mapping>
<my_mapping>
<uri>other uri</uri>
<address>address 3</address>
<address>address 4</address>
</my_mapping>
The typedef
statement is explained in this section of YANG 1.1. RFC 7950. It is meant to specify a type of a single leaf so it cannot be used to create the structure you want to have. When you use typedef
you define the set of all possible values for that type. This is called value space. The union
built-in type that you tried to use is meant to combine value spaces of types listed inside it. list
is not a type, so it cannot be used there.