ygot icon indicating copy to clipboard operation
ygot copied to clipboard

How to merge generated go structs from 2 different yang models

Open dlakshma opened this issue 1 year ago • 1 comments

Hi,

I have 2 different sets of yang files, which are converted into go structs, both having parent node as Device. But when i tried to merge the go structs using ygot.MergeStructs() API, getting error as cannot merge structs that are not of matching types, *openconfig.Device != *openconfig.Device

For Example:

 type Device struct {
   abc *Testabc_abc `path:"abc" module:"test-abc"`
 }

 type Device struct {
   xyz *Testxyz_xyz `path:"xyz" module:"test-xyz"`
 }

want to merge these 2 ygot structs into single tree, where both abc and xyz are under single Device struct

Is there a way or an API, which can be used to merge 2 generated go structs.

TestCode :

func TestMergeGoStruct(t *testing.T) {
        appgs, err := yocapp.LookUpGoStruct("/")
        require.Nil(t, err)
       
        tosgs, err := yoc.LookUpGoStruct("/")
        require.Nil(t, err)
        merged, err := ygot.MergeStructs(tosgs, appgs)
        require.Nil(t, err)
        t.Logf("merged:%+v", merged)
}

Thanks, Deepak

dlakshma avatar May 16 '23 17:05 dlakshma

If you want generated ygot GoStructs to represent two different trees then you would need to generate with both sets of YANG files at the same time.

wenovus avatar Jun 05 '23 22:06 wenovus