openconfig / ygot

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

Having dot "." character in YANG identifier causes generator to give invalid Go code #333

Closed SeanCondon closed 4 years ago

SeanCondon commented 5 years ago

If there is a dot character . in a YANG identifier then generator will output invalid Go code.

For instance in ygot/demo/getting_started/yang/openconfig-interfaces.yang changing leaf out-unicast-pkts to leaf out-unicast-pk.ts at https://github.com/openconfig/ygot/blob/b14560776567988c832f9685af6f0e695ee95727/demo/getting_started/yang/openconfig-interfaces.yang#L639

generator will compile fine with (from README)

go run $GOPATH/src/github.com/openconfig/ygot/generator/generator.go -path=yang -output_file=pkg/ocdemo/oc.go -package_name=ocdemo -generate_fakeroot -fakeroot_name=device -compress_paths=true  -exclude_modules=ietf-interfaces yang/openconfig-interfaces.yang

but the generated code will contain

    OutUnicastPk.ts *uint64 `path:"out-unicast-pk.ts" module:"openconfig-interfaces"`

Something similar happens with container but is more complex.

The YANG standard RFC 6020 https://tools.ietf.org/html/rfc6020#section-6.2 says:

Each identifier starts with an uppercase or lowercase ASCII letter or an underscore character, followed by zero or more ASCII letters, digits, underscore characters, hyphens, and dots

The reason for bringing this up is that dot is used in a few places in commonly used YANGS e.g. search for container ieee-802.3ad in https://github.com/Juniper/yang/blob/master/19.3/19.3R1/junos/conf/junos-conf-interfaces%402019-01-01.yang

wenovus commented 4 years ago

Thanks Sean that's a good point, taking a look.

SeanCondon commented 4 years ago

This is great - thanks so much for addressing it

wenovus commented 4 years ago

openconfig/goyang#105 fixes this for both leaves and containers.