@@ -212,7 +212,9 @@ func (s *sharedEntryAttributes) checkAndCreateKeysAsLeafs(ctx context.Context, i
212212 // if we're in the last level of keys, then we need to add the defaults
213213 if len (ancestorContainerSchema .Keys ) == levelsUp {
214214 // iterate through the keys
215- for idx , k := range ancestor .GetSchemaKeys () {
215+ schemaKeys := ancestor .GetSchemaKeys ()
216+ slices .Sort (schemaKeys )
217+ for idx , k := range schemaKeys {
216218 child , entryExists := s .childs .GetEntry (k )
217219 // if the key Leaf exists continue with next key
218220 if entryExists {
@@ -951,6 +953,9 @@ func (s *sharedEntryAttributes) Validate(ctx context.Context, resultChan chan<-
951953
952954 // validate the mandatory statement on this entry
953955 if s .remainsToExist () {
956+
957+ // TODO: Validate Enums
958+
954959 if ! vCfg .DisabledValidators .Mandatory {
955960 s .validateMandatory (ctx , resultChan )
956961 }
@@ -1137,13 +1142,13 @@ func (s *sharedEntryAttributes) ImportConfig(ctx context.Context, t importer.Imp
11371142 var exists bool
11381143 var actualEntry Entry = s
11391144 var keyChild Entry
1140- for _ , keySchema := range s .schema .GetContainer ().GetKeys () {
1145+ schemaKeys := s .GetSchemaKeys ()
1146+ slices .Sort (schemaKeys )
1147+ for _ , schemaKey := range schemaKeys {
11411148
1142- keyElemName := keySchema .Name
1143-
1144- keyTransf := t .GetElement (keyElemName )
1149+ keyTransf := t .GetElement (schemaKey )
11451150 if keyTransf == nil {
1146- return fmt .Errorf ("unable to find key attribute %s under %s" , keyElemName , s .Path ())
1151+ return fmt .Errorf ("unable to find key attribute %s under %s" , schemaKey , s .Path ())
11471152 }
11481153 keyElemValue , err := keyTransf .GetKeyValue ()
11491154 if err != nil {
@@ -1654,18 +1659,18 @@ func (s *sharedEntryAttributes) getKeyName() (string, error) {
16541659 return "" , fmt .Errorf ("error %s is a schema element, can only get KeyNames for key element" , strings .Join (s .Path (), " " ))
16551660 }
16561661
1657- // get ancestro schema
1662+ // get ancestor schema
16581663 ancestorWithSchema , levelUp := s .GetFirstAncestorWithSchema ()
16591664
1660- // only Contaieners have keys, so check for that
1661- switch sch := ancestorWithSchema .GetSchema (). GetSchema ().( type ) {
1662- case * sdcpb. SchemaElem_Container :
1663- // return the name of the levelUp-1 key
1664- return sch . Container . GetKeys ()[ levelUp - 1 ]. Name , nil
1665+ // only Containers have keys, so check for that
1666+ schemaKeys := ancestorWithSchema .GetSchemaKeys ()
1667+ if len ( schemaKeys ) == 0 {
1668+ // we probably called the function on a LeafList or LeafEntry which is not a valid call to be made.
1669+ return "" , fmt . Errorf ( "error LeafList and Field should not have keys %s" , strings . Join ( s . Path (), " " ))
16651670 }
16661671
1667- // we probably called the function on a LeafList or LeafEntry which is not a valid call to be made.
1668- return "" , fmt . Errorf ( "error LeafList and Field should not have keys %s" , strings . Join ( s . Path (), " " ))
1672+ slices . Sort ( schemaKeys )
1673+ return schemaKeys [ levelUp - 1 ], nil
16691674}
16701675
16711676func (s * sharedEntryAttributes ) getOrCreateChilds (ctx context.Context , path types.PathSlice ) (Entry , error ) {
0 commit comments