openconfig / ygot

A YANG-centric Go toolkit - Go/Protobuf Code Generation; Validation; Marshaling/Unmarshaling
Apache License 2.0
284 stars 106 forks source link

Can't generate OC-YANG network-instance #977

Closed qin-nz closed 2 months ago

qin-nz commented 2 months ago

ygot version: latest c52408e2 OC-YANG version: latest c00868ed

Run following command:

OC_ROOT='~/code/github.com/openconfig/public'
go run ~/code/github.com/openconfig/ygot/generator/generator.go \
  -generate_fakeroot -fakeroot_name=device -compress_paths=true -shorten_enum_leaf_names -typedef_enum_with_defmod \
  -output_file=./ocyang.go -package_name=ocyang -path=$OC_ROOT -exclude_modules=ietf-interfaces \
  $OC_ROOT/release/models/network-instance/openconfig-network-instance.yang

Got errors:

F0617 14:33:56.501129 4170258 generator.go:384] ERROR Generating GoStruct Code: path "/openconfig-network-instance/network-instances/network-instance/protocols/protocol/isis/interfaces/interface/weighted-ecmp/config/load-balancing-weight": default value not supported for wrapper union values, please generate using simplified union leaves

Is it a bug ? (Maybe releate to #582 #613 #961 )

wenovus commented 2 months ago

This was due to a feature addition for union leaf defaults some time ago.

Are you able to modify your downstream code to use the flag generate_simple_unions?

The recommended list of enum flags to use is

 -shorten_enum_leaf_names \ 
 -trim_enum_openconfig_prefix \ 
 -typedef_enum_with_defmod \ 
 -enum_suffix_for_simple_union_enums \ 
 -generate_simple_unions \

https://github.com/openconfig/ygot/blob/c52408e2a236e6b15aa25ed28247200f64a4b8f7/exampleoc/update.sh#L18-L29

qin-nz commented 2 months ago

Thanks a lot ~