leaf name and type name can be same in yang

507 Views Asked by At

Below example is correct yang statement or not? it is valid by pyang but JNC is unable to process

grouping TLId {
leaf age {
type Age;
mandatory true;
}
}

typedef Age {
type string {
pattern '[0-9][0-9]';
}
}

Please suggest

1

There are 1 best solutions below

0
On

Your YANG snippet is valid.

Typedefs are assigned to a different namespace compared to schema node identifiers - there can never be a name conflict between a leaf identifier and a typedef identifier, as decribed in Section 6.2.1 of RFC7950:

Each identifier is valid in a namespace that depends on the type of the YANG item being defined. All identifiers defined in a namespace MUST be unique.

o All derived type names defined within a parent node or at the top level of the module or its submodules share the same type identifier namespace. This namespace is scoped to all descendant nodes of the parent node or module. This means that any descendant node may use that typedef, and it MUST NOT define a typedef with the same name.

o All leafs, leaf-lists, lists, containers, choices, rpcs, actions, notifications, anydatas, and anyxmls defined (directly or through a "uses" statement) within a parent node or at the top level of the module or its submodules share the same identifier namespace. This namespace is scoped to the parent node or module, unless the parent node is a case node. In that case, the namespace is scoped to the closest ancestor node that is not a case or choice node.