From ac9f049ec76f1bca40bb89be9df82f56a7a5f42f Mon Sep 17 00:00:00 2001 From: Wen Bo Li <50884368+wenovus@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:19:09 -0500 Subject: [PATCH] Support skipping any-xml using -ignore_unsupported. (#931) Currently it fails because containers are being detected via the `default` case, so they're being classified as containers. --- testdata/modules/openconfig-simple-with-unsupported.yang | 3 +++ ygen/directory.go | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/testdata/modules/openconfig-simple-with-unsupported.yang b/testdata/modules/openconfig-simple-with-unsupported.yang index fb4c8a75e..2a1e86850 100644 --- a/testdata/modules/openconfig-simple-with-unsupported.yang +++ b/testdata/modules/openconfig-simple-with-unsupported.yang @@ -17,6 +17,9 @@ module openconfig-simple { leaf four { type binary; } + anyxml xml-data { + description "updated stuff"; + } } container parent { diff --git a/ygen/directory.go b/ygen/directory.go index 2a205745a..a2fef10e8 100644 --- a/ygen/directory.go +++ b/ygen/directory.go @@ -23,6 +23,7 @@ import ( "reflect" "sort" + log "github.com/golang/glog" "github.com/openconfig/goyang/pkg/yang" "github.com/openconfig/ygot/genutil" "github.com/openconfig/ygot/util" @@ -295,7 +296,7 @@ func getOrderedDirDetails(langMapper LangMapper, directory map[string]*Directory nd.YANGDetails.OrderedByUser = field.ListAttr.OrderedByUser case util.IsAnydata(field): nd.Type = AnyDataNode - default: + case field.IsContainer(): nd.Type = ContainerNode // TODO(wenovus): // a presence container is an unimplemented keyword in goyang. @@ -307,6 +308,12 @@ func getOrderedDirDetails(langMapper LangMapper, directory map[string]*Directory return nil, fmt.Errorf("unable to retrieve presence statement, expected non-nil *yang.Value, got %v", dir.Entry.Extra["presence"][0]) } } + default: + if opts.ParseOptions.IgnoreUnsupportedStatements { + log.Infof("Unsupported field type (%v) ignored: %s", field.Kind, field.Path()) + continue + } + return nil, fmt.Errorf("unsupported field type (%v) at: %s", field.Kind, field.Path()) } nd.Flags = langMapper.PopulateFieldFlags(*nd, field)