Skip to content

Commit

Permalink
Consistently use goEnumPrefix and fix bug generating enum default val…
Browse files Browse the repository at this point in the history
…ue in wrapper union node. (#511)

Consistently use goEnumPrefix and fix bug generating enum default value in wrapper union node.

### Background
The recent union default value generation changes [removed a call to `enumDefaultValue`](https://github.com/openconfig/ygot/pull/496/files#diff-19ecb3e61250b63aaf93a11d7017203a90637b52bee811a021ab253b01c42748L275-L277) in order to use the *raw* default value string provided in the YANG file to look up the existence of the enum value in goyang's AST before accepting the default value as an enum type. The `yangDefaultValueToGo` function only processes these raw values for simplicity. However, this breaks generating typedef enums in wrapper union mode because a call to `enumDefaultValue` is required to make the output correct.

### This change
What this change does is that during the processing of both inline and typedef enumerated values by `yangTypeToGoType`, `enumDefaultValue` is **not called** when populating `MappedType`'s `DefaultValue` field. This means that **all** enumerated values that subsequently get processed by `yangDefaultValueToGo`, which come after the call to `yangTypeToGoType`, will see the raw default value. Most importantly, `goLeafDefault`, a call that happens in wrapper-union mode, can now transform the raw default values for enums into their "cooked" versions without discriminating between inline and typedef enumerated values. This is what fixes this problem.
  • Loading branch information
wenovus authored Mar 24, 2021
1 parent a6e5685 commit 25f3c35
Show file tree
Hide file tree
Showing 17 changed files with 106,277 additions and 105,112 deletions.
70,296 changes: 35,248 additions & 35,048 deletions exampleoc/oc.go

Large diffs are not rendered by default.

66 changes: 65 additions & 1 deletion exampleoc/ocpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Package exampleoc is a generated package which contains definitions
of structs which generate gNMI paths for a YANG schema. The generated paths are
based on a compressed form of the schema.

This package was generated by /Users/robjs/Code/go/src/github.com/openconfig/ygot/genutil/names.go
This package was generated by /usr/local/google/home/wenbli/gocode/src/github.com/openconfig/ygot/genutil/names.go
using the following YANG input files:
- public/release/models/network-instance/openconfig-network-instance.yang
- public/release/models/optical-transport/openconfig-optical-amplifier.yang
Expand Down Expand Up @@ -36526,6 +36526,28 @@ func (n *ComponentPathAny) SerialNo() *Component_SerialNoPathAny {
}
}

// SoftwareModule returns from ComponentPath the path struct for its child "software-module".
func (n *ComponentPath) SoftwareModule() *Component_SoftwareModulePath {
return &Component_SoftwareModulePath{
NodePath: ygot.NewNodePath(
[]string{"software-module"},
map[string]interface{}{},
n,
),
}
}

// SoftwareModule returns from ComponentPathAny the path struct for its child "software-module".
func (n *ComponentPathAny) SoftwareModule() *Component_SoftwareModulePathAny {
return &Component_SoftwareModulePathAny{
NodePath: ygot.NewNodePath(
[]string{"software-module"},
map[string]interface{}{},
n,
),
}
}

// SoftwareVersion returns from ComponentPath the path struct for its child "software-version".
func (n *ComponentPath) SoftwareVersion() *Component_SoftwareVersionPath {
return &Component_SoftwareVersionPath{
Expand Down Expand Up @@ -39662,6 +39684,16 @@ func (n *Component_PropertyPathAny) Value() *Component_Property_ValuePathAny {
}
}

// Component_SoftwareModulePath represents the /openconfig-platform/components/component/software-module YANG schema element.
type Component_SoftwareModulePath struct {
*ygot.NodePath
}

// Component_SoftwareModulePathAny represents the wildcard version of the /openconfig-platform/components/component/software-module YANG schema element.
type Component_SoftwareModulePathAny struct {
*ygot.NodePath
}

// Component_StoragePath represents the /openconfig-platform/components/component/storage YANG schema element.
type Component_StoragePath struct {
*ygot.NodePath
Expand Down Expand Up @@ -68728,6 +68760,16 @@ type NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_LsrIdPathAny struct {
*ygot.NodePath
}

// NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_SessionStatePath represents the /openconfig-network-instance/network-instances/network-instance/mpls/signaling-protocols/ldp/neighbors/neighbor/state/session-state YANG schema element.
type NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_SessionStatePath struct {
*ygot.NodePath
}

// NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_SessionStatePathAny represents the wildcard version of the /openconfig-network-instance/network-instances/network-instance/mpls/signaling-protocols/ldp/neighbors/neighbor/state/session-state YANG schema element.
type NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_SessionStatePathAny struct {
*ygot.NodePath
}

// Authentication returns from NetworkInstance_Mpls_SignalingProtocols_Ldp_NeighborPath the path struct for its child "authentication".
func (n *NetworkInstance_Mpls_SignalingProtocols_Ldp_NeighborPath) Authentication() *NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_AuthenticationPath {
return &NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_AuthenticationPath{
Expand Down Expand Up @@ -68890,6 +68932,28 @@ func (n *NetworkInstance_Mpls_SignalingProtocols_Ldp_NeighborPathAny) LsrId() *N
}
}

// SessionState returns from NetworkInstance_Mpls_SignalingProtocols_Ldp_NeighborPath the path struct for its child "session-state".
func (n *NetworkInstance_Mpls_SignalingProtocols_Ldp_NeighborPath) SessionState() *NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_SessionStatePath {
return &NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_SessionStatePath{
NodePath: ygot.NewNodePath(
[]string{"state", "session-state"},
map[string]interface{}{},
n,
),
}
}

// SessionState returns from NetworkInstance_Mpls_SignalingProtocols_Ldp_NeighborPathAny the path struct for its child "session-state".
func (n *NetworkInstance_Mpls_SignalingProtocols_Ldp_NeighborPathAny) SessionState() *NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_SessionStatePathAny {
return &NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_SessionStatePathAny{
NodePath: ygot.NewNodePath(
[]string{"state", "session-state"},
map[string]interface{}{},
n,
),
}
}

// NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_AuthenticationPath represents the /openconfig-network-instance/network-instances/network-instance/mpls/signaling-protocols/ldp/neighbors/neighbor/authentication YANG schema element.
type NetworkInstance_Mpls_SignalingProtocols_Ldp_Neighbor_AuthenticationPath struct {
*ygot.NodePath
Expand Down
Loading

0 comments on commit 25f3c35

Please sign in to comment.