freeconf / yang

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

bit information for 'bits' datatype is not found if a typedef is used. #84

Closed davidmat50 closed 1 year ago

davidmat50 commented 1 year ago

If a leaf or leaf-list is having type as typedef, and if the internal type of the typedef is 'bits', then the bit information is not received.

example given below.

file: type-bit1.yang

module type_bit1 {

    namespace "urn:params:type_bit";
    prefix type_bit;

    yang-version 1.1;

    typedef new_type_bits {
        type bits {
            bit seventh-bit {
                position 0;
            }
            bit eighth-bit {
                position 1;
            }
            bit ninth-bit {
                position 2;
            }
        }
        default ninth-bit;
        units gbp;
        description "This is new_type_bits";
    }

    container root-container {
        leaf leaf-bits {
            type bits {
                bit first-bit {
                    position 0;
                }
                bit second-bit {
                    position 1;
                }
                bit third-bit {
                    position 2;
                }
            }
            default first-bit;
            units dollars;
            description "This is leaf-bits";
        }
        leaf-list leaf-list-bits {
            type bits {
                bit forth-bit {
                    position 0;
                }
                bit fifth-bit {
                    position 1;
                }
                bit sixth-bit {
                    position 2;
                }
            }
            default fifth-bit;
            units usd;
        }
        leaf leaf-derived-type {
            type new_type_bits;
            default seventh-bit;
            description "This is leaf-derived-type";
        }
        leaf-list leaf-list-derived-type {
            type new_type_bits;
            default eighth-bit;
            description "This is leaf-list-derived-type";
        }
    }
}

In the above example with typedef, for nodes leaf-derived-type and leaf-list-derived-type , Type() method returns a type data without 'bit' information. so BIts() method also returns empty. In the cases where typedef was not used ie leaf-bits and leaf-list-bits , the bits information was received as expected.

davidmat50 commented 1 year ago

This problem exists if the typedef of bits datatype is used within an union also.

sample file for union case:

module my-bit-test2 {

    namespace "urn:params:type_bit";
    prefix type_bit;

    yang-version 1.1;

    typedef new_type_bits {
        type bits {
            bit seventh-bit {
                position 0;
            }
            bit eighth-bit {
                position 1;
            }
            bit ninth-bit {
                position 2;
            }
        }
        default ninth-bit;
        units gbp;
        description "This is new_type_bits";
    }

    container root-container {
        leaf leaf-bits {
            type bits {
                bit first-bit {
                    position 0;
                }
                bit second-bit {
                    position 1;
                }
                bit third-bit {
                    position 2;
                }
            }
            default first-bit;
            units dollars;
            description "This is leaf-bits";
        }
        leaf-list leaf-list-bits {
            type bits {
                bit forth-bit {
                    position 0;
                }
                bit fifth-bit {
                    position 1;
                }
                bit sixth-bit {
                    position 2;
                }
            }
            default fifth-bit;
            units usd;
            /*description "This is leaf-list-bits";*/
        }
        leaf leaf-derived-type {
            type new_type_bits;
            default seventh-bit;
            description "This is leaf-derived-type";
        }
        leaf-list leaf-list-derived-type {
            type new_type_bits;
            default eighth-bit;
            description "This is leaf-list-derived-type";
        }
        leaf leaf-union {
            type union {
                type new_type_bits;
                type boolean;
            }   
        }

        leaf-list leaf-list-union {
            type union {
                type new_type_bits;
                type boolean;
            }   
        }
    }
}

For this file, if we try tofetch the type of new_type_bits under union , the bits details is empty. Bits() method will return empy.

dhubler commented 1 year ago

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

dhubler commented 1 year ago

fixed