@@ -394,6 +394,10 @@ func checkSpecStructure(path string) error {
394
394
return err
395
395
}
396
396
397
+ analyzerFields := listFieldNames (& troubleshootv1beta2.Analyze {})
398
+
399
+ analyzeFieldsInLowerCamelCase := strings .ToLower (strings .Join (analyzerFields , " " ))
400
+
397
401
for _ , n := range node .Content [0 ].Content { // Traverse the root map
398
402
if n .Kind == yaml .MappingNode && n .Tag == "!!map" {
399
403
for i := 0 ; i < len (n .Content ); i += 2 {
@@ -404,11 +408,15 @@ func checkSpecStructure(path string) error {
404
408
for j := 0 ; j < len (specNode .Content ); j += 2 {
405
409
analyzerKey := specNode .Content [j ]
406
410
analyzerVal := specNode .Content [j + 1 ]
407
- if analyzerKey .Value == "distribution" {
411
+ if strings . Contains ( analyzeFieldsInLowerCamelCase , strings . ToLower ( analyzerKey .Value )) {
408
412
if len (analyzerVal .Content ) == 0 {
409
- fmt .Println ("distribution is empty" )
410
- if specNode .Content [j + 2 ] != nil && specNode .Content [j + 2 ].Value == "outcomes" {
411
- fmt .Println ("outcomes is misaligned in distribution" )
413
+ fmt .Println ("====================" )
414
+ fmt .Printf ("%s analyzer is empty\n " , analyzerKey .Value )
415
+ fmt .Println ("--------------------" )
416
+ for k := j + 2 ; k < len (specNode .Content ); k += 2 {
417
+ if specNode .Content [k ].Value != "" && ! strings .Contains (analyzeFieldsInLowerCamelCase , strings .ToLower (specNode .Content [k ].Value )) {
418
+ fmt .Printf ("%s is misaligned in %s\n " , specNode .Content [k ].Value , analyzerKey .Value )
419
+ }
412
420
}
413
421
}
414
422
}
@@ -419,10 +427,18 @@ func checkSpecStructure(path string) error {
419
427
}
420
428
}
421
429
}
422
-
423
430
return nil
424
431
}
425
432
433
+ func listFieldNames (v interface {}) []string {
434
+ val := reflect .ValueOf (v ).Elem ()
435
+ fieldNames := make ([]string , val .NumField ())
436
+ for i := 0 ; i < val .NumField (); i ++ {
437
+ fieldNames [i ] = val .Type ().Field (i ).Name
438
+ }
439
+ return fieldNames
440
+ }
441
+
426
442
func isStructEmpty (s interface {}) bool {
427
443
val := reflect .ValueOf (s ).Elem ()
428
444
for i := 0 ; i < val .NumField (); i ++ {
0 commit comments