Skip to content

Commit

Permalink
Generate ΛEnumTypes for shadow paths (#917)
Browse files Browse the repository at this point in the history
* Generate `ΛEnumTypes` for shadow paths

* Fixed unmarshalling union leafs for shadow paths.
* Use correct path for keying `ΛEnumTypes`.
* Re-generate exampleoc for schema test.

* Remove stale comment
  • Loading branch information
wenovus authored Sep 28, 2023
1 parent 2224a32 commit 23c9aac
Show file tree
Hide file tree
Showing 11 changed files with 143,866 additions and 130,505 deletions.
93,551 changes: 49,129 additions & 44,422 deletions exampleoc/oc.go

Large diffs are not rendered by default.

4,895 changes: 4,307 additions & 588 deletions exampleoc/ocpath.go

Large diffs are not rendered by default.

92,494 changes: 48,488 additions & 44,006 deletions exampleoc/opstateoc/oc.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions exampleoc/opstateoc/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ go run ../../generator/generator.go -path=public,deps -output_file=oc.go \
public/release/models/optical-transport/openconfig-terminal-device.yang \
public/release/models/optical-transport/openconfig-transport-line-protection.yang \
public/release/models/platform/openconfig-platform.yang \
public/release/models/bgp/openconfig-bgp-policy.yang \
public/release/models/policy/openconfig-routing-policy.yang \
public/release/models/lacp/openconfig-lacp.yang \
public/release/models/system/openconfig-system.yang \
Expand Down
1 change: 1 addition & 0 deletions exampleoc/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ go run ../generator/generator.go -path=public,deps -output_file=oc.go \
public/release/models/optical-transport/openconfig-terminal-device.yang \
public/release/models/optical-transport/openconfig-transport-line-protection.yang \
public/release/models/platform/openconfig-platform.yang \
public/release/models/bgp/openconfig-bgp-policy.yang \
public/release/models/policy/openconfig-routing-policy.yang \
public/release/models/lacp/openconfig-lacp.yang \
public/release/models/system/openconfig-system.yang \
Expand Down
5 changes: 5 additions & 0 deletions exampleoc/wrapperunionoc/oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ It should not be used within your application, as it WILL change,
without warning. Rather, you should generate structs directly from
OpenConfig models using the ygot package.

NOTE WELL: This is an example code file that is distributed with ygot.
It should not be used within your application, as it WILL change,
without warning. Rather, you should generate structs directly from
OpenConfig models using the ygot package.

This package was generated by github.com/openconfig/ygot
using the following YANG input files:
- public/release/models/network-instance/openconfig-network-instance.yang
Expand Down
9 changes: 6 additions & 3 deletions gogen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"sort"
"strings"

"github.com/openconfig/ygot/internal/igenutil"
"github.com/openconfig/ygot/util"
Expand Down Expand Up @@ -274,8 +273,7 @@ func (cg *CodeGenerator) Generate(yangFiles, includePaths []string) (*GeneratedC
for _, fn := range dir.OrderedFieldNames() {
field := dir.Fields[fn]

// Strip the module name from the path.
schemaPath := util.SlicePathToString(append([]string{""}, strings.Split(field.YANGDetails.Path, "/")[2:]...))
schemaPath := field.YANGDetails.SchemaPath
switch {
case field.LangType == nil:
// This is a directory, so we continue.
Expand Down Expand Up @@ -304,6 +302,11 @@ func (cg *CodeGenerator) Generate(yangFiles, includePaths []string) (*GeneratedC
return field.LangType.UnionTypes[enumTypeMap[schemaPath][i]].Index < field.LangType.UnionTypes[enumTypeMap[schemaPath][j]].Index
})
}
if v, ok := enumTypeMap[schemaPath]; ok {
if shadowPath := field.YANGDetails.ShadowSchemaPath; shadowPath != "" {
enumTypeMap[shadowPath] = v
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,8 @@ func initΛEnumTypes(){
"/parent/child/config/three": []reflect.Type{
reflect.TypeOf((E_Child_Three)(0)),
},
"/parent/child/state/three": []reflect.Type{
reflect.TypeOf((E_Child_Three)(0)),
},
}
}
Loading

0 comments on commit 23c9aac

Please sign in to comment.