freeconf / yang

Standards-based management for Golang microservices
Apache License 2.0
38 stars 15 forks source link

Leaf of type union wrongly inherits default and units from typedef #80

Closed raghavendramayagundi closed 1 year ago

raghavendramayagundi commented 1 year ago

As per https://datatracker.ietf.org/doc/html/rfc7950#section-9.12 : "Any default value or "units" property defined in the member types is not inherited by the union type".

For below example, leaf "leaf-union" is getting "default" (=7) and "units" (=gbp) from the typedef definition: `typedef new_type_leafref { type leafref { path "/root-container/leaf-1"; } default 7; units gbp; description "This is new_type_leafref"; }

container root-container {
    leaf leaf-derived-type {
        type new_type_leafref;
        description "This is leaf-derived-type";
    }
    leaf leaf-union {
        type union {
            type int16;
            type new_type_leafref;
        }
    }
    leaf leaf-1 {
        type int16 {
            range "1..100" {
                error-message "ERROR";
            }
        }
        default 10;
        units initial-units;
        description "This is referenced leaf";
    }
}`

Looks like compile.go => compileType() has to be updated to exclude calling of parent.setDefault() & parent.setUnits() for union type. I am using the latest master version v0.0.0-20230804003402-7593854e7f4d

dhubler commented 1 year ago

thanks for reporting and finding likely culprit. i'll take a look next day or so.

dhubler commented 1 year ago

little behind, but i'll take a look in next few days

dhubler commented 1 year ago

fixed