@@ -2,8 +2,9 @@ package validate
2
2
3
3
import (
4
4
"fmt"
5
- "github.com/devfile/api/v2/pkg/validation"
5
+ v2Validation "github.com/devfile/api/v2/pkg/validation"
6
6
devfileData "github.com/devfile/library/pkg/devfile/parser/data"
7
+ v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
7
8
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
8
9
"strings"
9
10
)
@@ -23,43 +24,53 @@ func ValidateDevfileData(data devfileData.DevfileData) error {
23
24
if err != nil {
24
25
return err
25
26
}
26
- //starterProjects, err := data.GetStarterProjects(common.DevfileOptions{})
27
- //if err != nil {
28
- // return err
29
- //}
30
-
31
- var errstrings []string
32
- // validate components
33
- err = validation .ValidateComponents (components )
27
+ starterProjects , err := data .GetStarterProjects (common.DevfileOptions {})
34
28
if err != nil {
35
- errstrings = append ( errstrings , err . Error ())
29
+ return err
36
30
}
37
31
38
- // validate commands
39
- err = validation .ValidateCommands (commands , components )
40
- if err != nil {
41
- errstrings = append (errstrings , err .Error ())
42
- }
32
+ var errstrings []string
33
+ switch d := data .(type ) {
34
+ case * v2.DevfileV2 :
35
+ // validate components
36
+ err = v2Validation .ValidateComponents (components )
37
+ if err != nil {
38
+ errstrings = append (errstrings , err .Error ())
39
+ }
43
40
44
- err = validation .ValidateEvents (data .GetEvents (), commands )
45
- if err != nil {
46
- errstrings = append (errstrings , err .Error ())
47
- }
41
+ // validate commands
42
+ err = v2Validation .ValidateCommands (commands , components )
43
+ if err != nil {
44
+ errstrings = append (errstrings , err .Error ())
45
+ }
48
46
49
- err = validation . ValidateProjects ( projects )
50
- if err != nil {
51
- errstrings = append (errstrings , err .Error ())
52
- }
47
+ err = v2Validation . ValidateEvents ( data . GetEvents (), commands )
48
+ if err != nil {
49
+ errstrings = append (errstrings , err .Error ())
50
+ }
53
51
54
- //err = validation.ValidateStarterProjects(starterProjects)
55
- //if err != nil {
56
- // errstrings = append(errstrings, err.Error())
57
- //}
52
+ err = v2Validation .ValidateProjects (projects )
53
+ if err != nil {
54
+ errstrings = append (errstrings , err .Error ())
55
+ }
56
+
57
+ err = v2Validation .ValidateStarterProjects (starterProjects )
58
+ if err != nil {
59
+ errstrings = append (errstrings , err .Error ())
60
+ }
61
+
62
+ if len (errstrings ) > 0 {
63
+ return fmt .Errorf (strings .Join (errstrings , "\n " ))
64
+ } else {
65
+ return nil
66
+ }
67
+ default :
68
+ return fmt .Errorf ("unknown devfile type %T" , d )
69
+ }
58
70
59
71
if len (errstrings ) > 0 {
60
72
return fmt .Errorf (strings .Join (errstrings , "\n " ))
61
- } else {
62
- return nil
63
73
}
64
74
75
+ return nil
65
76
}
0 commit comments