ygot icon indicating copy to clipboard operation
ygot copied to clipboard

anydata error when trying to generate from openconfig-config.yang

Open preetjuniper opened this issue 11 months ago • 1 comments

Hi,

Does ygot have support for generating go code from yang that uses anydata? I encountered an error using the generator with a yang file that has an anydata leaf in it. Poking around the ygot repo, I see there's a testdata/module/openconfig-complex.yang file referenced in some tests. When trying the generator with this file, I get the following:

>> generator -path=testdata/modules -output_file=openconfig_complex.go -package_name=occomplex -generate_fakeroot -fakeroot_name=root -shorten_enum_leaf_names -trim_enum_openconfig_prefix -typedef_enum_with_defmod -generate_simple_unions openconfig-complex.yang
F0403 10:05:16.677285   24213 generator.go:384] ERROR Generating GoStruct Code: unknown entity type for mapping to Go: /openconfig-complex/model/anydata-leaf, Kind: anydata

preetjuniper avatar Apr 03 '25 17:04 preetjuniper

Today, ygot only supports anydata when transpiling to protobuf rather than Go. We map to google.protobuf.any in the proto case -- we didn't add something similar in Go, since there hasn't been a feature request AFAIK.

We could add something here, but we need to think about what the marshal + unmarshal expectations are for a user.

I'm happy to review a design proposal here.

robshakir avatar May 31 '25 02:05 robshakir