Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
774 changes: 774 additions & 0 deletions exampleoc/a/a-0.go

Large diffs are not rendered by default.

507 changes: 261 additions & 246 deletions exampleoc/schema.go

Large diffs are not rendered by default.

230 changes: 230 additions & 0 deletions exampleoc/structs-0.go
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,7 @@ type Model_SingleKey struct {
Counter Binary `path:"state/counter" module:"openconfig-withlistval/openconfig-withlistval"`
Counters []Binary `path:"state/counters" module:"openconfig-withlistval/openconfig-withlistval"`
Key *string `path:"state/key|key" module:"openconfig-withlistval/openconfig-withlistval|openconfig-withlistval" shadow-path:"config/key|key" shadow-module:"openconfig-withlistval/openconfig-withlistval|openconfig-withlistval"`
NestedList map[string]*Model_SingleKey_NestedList `path:"nested-lists/nested-list" module:"openconfig-withlistval/openconfig-withlistval"`
OrderedList *Model_SingleKey_OrderedList_OrderedMap `path:"ordered-lists/ordered-list" module:"openconfig-withlistval/openconfig-withlistval"`
SingleKey map[string]*Model_SingleKey_SingleKey `path:"inner-a/single-key" module:"openconfig-withlistval/openconfig-withlistval"`
Value *int64 `path:"state/value" module:"openconfig-withlistval/openconfig-withlistval" shadow-path:"config/value" shadow-module:"openconfig-withlistval/openconfig-withlistval"`
Expand All @@ -1662,6 +1663,133 @@ type Model_SingleKey struct {
// identify it as being generated by ygen.
func (*Model_SingleKey) IsYANGGoStruct() {}

// NewNestedList creates a new entry in the NestedList list of the
// Model_SingleKey struct. The keys of the list are populated from the input
// arguments.
func (t *Model_SingleKey) NewNestedList(Key string) (*Model_SingleKey_NestedList, error) {

// Initialise the list within the receiver struct if it has not already been
// created.
if t.NestedList == nil {
t.NestedList = make(map[string]*Model_SingleKey_NestedList)
}

key := Key

// Ensure that this key has not already been used in the
// list. Keyed YANG lists do not allow duplicate keys to
// be created.
if _, ok := t.NestedList[key]; ok {
return nil, fmt.Errorf("duplicate key %v for list NestedList", key)
}

t.NestedList[key] = &Model_SingleKey_NestedList{
Key: &Key,
}

return t.NestedList[key], nil
}

// RenameNestedList renames an entry in the list NestedList within
// the Model_SingleKey struct. The entry with key oldK is renamed to newK updating
// the key within the value.
func (t *Model_SingleKey) RenameNestedList(oldK, newK string) error {
if _, ok := t.NestedList[newK]; ok {
return fmt.Errorf("key %v already exists in NestedList", newK)
}

e, ok := t.NestedList[oldK]
if !ok {
return fmt.Errorf("key %v not found in NestedList", oldK)
}
e.Key = &newK

t.NestedList[newK] = e
delete(t.NestedList, oldK)
return nil
}

// GetOrCreateNestedListMap returns the list (map) from Model_SingleKey.
//
// It initializes the field if not already initialized.
func (t *Model_SingleKey) GetOrCreateNestedListMap() map[string]*Model_SingleKey_NestedList {
if t.NestedList == nil {
t.NestedList = make(map[string]*Model_SingleKey_NestedList)
}
return t.NestedList
}

// GetOrCreateNestedList retrieves the value with the specified keys from
// the receiver Model_SingleKey. If the entry does not exist, then it is created.
// It returns the existing or new list member.
func (t *Model_SingleKey) GetOrCreateNestedList(Key string) *Model_SingleKey_NestedList {

key := Key

if v, ok := t.NestedList[key]; ok {
return v
}
// Panic if we receive an error, since we should have retrieved an existing
// list member. This allows chaining of GetOrCreate methods.
v, err := t.NewNestedList(Key)
if err != nil {
panic(fmt.Sprintf("GetOrCreateNestedList got unexpected error: %v", err))
}
return v
}

// GetNestedList retrieves the value with the specified key from
// the NestedList map field of Model_SingleKey. If the receiver is nil, or
// the specified key is not present in the list, nil is returned such that Get*
// methods may be safely chained.
func (t *Model_SingleKey) GetNestedList(Key string) *Model_SingleKey_NestedList {

if t == nil {
return nil
}

key := Key

if lm, ok := t.NestedList[key]; ok {
return lm
}
return nil
}

// DeleteNestedList deletes the value with the specified keys from
// the receiver Model_SingleKey. If there is no such element, the function
// is a no-op.
func (t *Model_SingleKey) DeleteNestedList(Key string) {
key := Key

delete(t.NestedList, key)
}

// AppendNestedList appends the supplied Model_SingleKey_NestedList struct to the
// list NestedList of Model_SingleKey. If the key value(s) specified in
// the supplied Model_SingleKey_NestedList already exist in the list, an error is
// returned.
func (t *Model_SingleKey) AppendNestedList(v *Model_SingleKey_NestedList) error {
if v.Key == nil {
return fmt.Errorf("invalid nil key received for Key")
}

key := *v.Key

// Initialise the list within the receiver struct if it has not already been
// created.
if t.NestedList == nil {
t.NestedList = make(map[string]*Model_SingleKey_NestedList)
}

if _, ok := t.NestedList[key]; ok {
return fmt.Errorf("duplicate key for list NestedList %v", key)
}

t.NestedList[key] = v
return nil
}

// NewSingleKey creates a new entry in the SingleKey list of the
// Model_SingleKey struct. The keys of the list are populated from the input
// arguments.
Expand Down Expand Up @@ -2058,6 +2186,9 @@ func (t *Model_SingleKey) PopulateDefaults() {
return
}
ygot.BuildEmptyTree(t)
for _, e := range t.NestedList {
e.PopulateDefaults()
}
for _, e := range t.SingleKey {
e.PopulateDefaults()
}
Expand Down Expand Up @@ -2100,6 +2231,105 @@ func (*Model_SingleKey) ΛBelongingModule() string {
return "openconfig-withlistval"
}

// Model_SingleKey_NestedList represents the /openconfig-withlistval/model/a/single-key/nested-lists/nested-list YANG schema element.
type Model_SingleKey_NestedList struct {
Key *string `path:"state/key|key" module:"openconfig-withlistval/openconfig-withlistval|openconfig-withlistval" shadow-path:"config/key|key" shadow-module:"openconfig-withlistval/openconfig-withlistval|openconfig-withlistval"`
Value *int64 `path:"state/value" module:"openconfig-withlistval/openconfig-withlistval" shadow-path:"config/value" shadow-module:"openconfig-withlistval/openconfig-withlistval"`
}

// IsYANGGoStruct ensures that Model_SingleKey_NestedList implements the yang.GoStruct
// interface. This allows functions that need to handle this struct to
// identify it as being generated by ygen.
func (*Model_SingleKey_NestedList) IsYANGGoStruct() {}

// GetKey retrieves the value of the leaf Key from the Model_SingleKey_NestedList
// struct. If the field is unset but has a default value in the YANG schema,
// then the default value will be returned.
// Caution should be exercised whilst using this method since when without a
// default value, it will return the Go zero value if the field is explicitly
// unset. If the caller explicitly does not care if Key is set, it can
// safely use t.GetKey() to retrieve the value. In the case that the
// caller has different actions based on whether the leaf is set or unset, it
// should use 'if t.Key == nil' before retrieving the leaf's value.
func (t *Model_SingleKey_NestedList) GetKey() string {
if t == nil || t.Key == nil {
return ""
}
return *t.Key
}

// GetValue retrieves the value of the leaf Value from the Model_SingleKey_NestedList
// struct. If the field is unset but has a default value in the YANG schema,
// then the default value will be returned.
// Caution should be exercised whilst using this method since when without a
// default value, it will return the Go zero value if the field is explicitly
// unset. If the caller explicitly does not care if Value is set, it can
// safely use t.GetValue() to retrieve the value. In the case that the
// caller has different actions based on whether the leaf is set or unset, it
// should use 'if t.Value == nil' before retrieving the leaf's value.
func (t *Model_SingleKey_NestedList) GetValue() int64 {
if t == nil || t.Value == nil {
return 0
}
return *t.Value
}

// SetKey sets the value of the leaf Key in the Model_SingleKey_NestedList
// struct.
func (t *Model_SingleKey_NestedList) SetKey(v string) {
t.Key = &v
}

// SetValue sets the value of the leaf Value in the Model_SingleKey_NestedList
// struct.
func (t *Model_SingleKey_NestedList) SetValue(v int64) {
t.Value = &v
}

// PopulateDefaults recursively populates unset leaf fields in the Model_SingleKey_NestedList
// with default values as specified in the YANG schema, instantiating any nil
// container fields.
func (t *Model_SingleKey_NestedList) PopulateDefaults() {
if t == nil {
return
}
ygot.BuildEmptyTree(t)
}

// ΛListKeyMap returns the keys of the Model_SingleKey_NestedList struct, which is a YANG list entry.
func (t *Model_SingleKey_NestedList) ΛListKeyMap() (map[string]interface{}, error) {
if t.Key == nil {
return nil, fmt.Errorf("nil value for key Key")
}

return map[string]interface{}{
"key": *t.Key,
}, nil
}

// Validate validates s against the YANG schema corresponding to its type.
func (t *Model_SingleKey_NestedList) ΛValidate(opts ...ygot.ValidationOption) error {
if err := ytypes.Validate(SchemaTree["Model_SingleKey_NestedList"], t, opts...); err != nil {
return err
}
return nil
}

// Validate validates s against the YANG schema corresponding to its type.
func (t *Model_SingleKey_NestedList) Validate(opts ...ygot.ValidationOption) error {
return t.ΛValidate(opts...)
}

// ΛEnumTypeMap returns a map, keyed by YANG schema path, of the enumerated types
// that are included in the generated code.
func (t *Model_SingleKey_NestedList) ΛEnumTypeMap() map[string][]reflect.Type { return ΛEnumTypes }

// ΛBelongingModule returns the name of the module that defines the namespace
// of Model_SingleKey_NestedList.
func (*Model_SingleKey_NestedList) ΛBelongingModule() string {
return "openconfig-withlistval"
}

// Model_SingleKey_OrderedList represents the /openconfig-withlistval/model/a/single-key/ordered-lists/ordered-list YANG schema element.
type Model_SingleKey_OrderedList struct {
Key *string `path:"state/key|key" module:"openconfig-withlistval/openconfig-withlistval|openconfig-withlistval" shadow-path:"config/key|key" shadow-module:"openconfig-withlistval/openconfig-withlistval|openconfig-withlistval"`
Expand Down
Loading
Loading