forked from goadesign/gorma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.go
72 lines (62 loc) · 1.86 KB
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package gorma
import (
"fmt"
"github.com/goadesign/goa/dslengine"
)
// Validate tests whether the StorageGroup definition is consistent.
func (a *StorageGroupDefinition) Validate() *dslengine.ValidationErrors {
fmt.Println("Validating Group")
verr := new(dslengine.ValidationErrors)
if a.Name == "" {
verr.Add(a, "storage group name not defined")
}
a.IterateStores(func(store *RelationalStoreDefinition) error {
verr.Merge(store.Validate())
return nil
})
return verr.AsError()
}
// Validate tests whether the RelationalStore definition is consistent.
func (a *RelationalStoreDefinition) Validate() *dslengine.ValidationErrors {
fmt.Println("Validating Store")
verr := new(dslengine.ValidationErrors)
if a.Name == "" {
verr.Add(a, "store name not defined")
}
if a.Parent == nil {
verr.Add(a, "missing storage group parent")
}
a.IterateModels(func(model *RelationalModelDefinition) error {
verr.Merge(model.Validate())
return nil
})
return verr.AsError()
}
// Validate tests whether the RelationalModel definition is consistent.
func (a *RelationalModelDefinition) Validate() *dslengine.ValidationErrors {
fmt.Println("Validating Model")
verr := new(dslengine.ValidationErrors)
if a.ModelName == "" {
verr.Add(a, "model name not defined")
}
if a.Parent == nil {
verr.Add(a, "missing relational store parent")
}
a.IterateFields(func(field *RelationalFieldDefinition) error {
verr.Merge(field.Validate())
return nil
})
return verr.AsError()
}
// Validate tests whether the RelationalField definition is consistent.
func (field *RelationalFieldDefinition) Validate() *dslengine.ValidationErrors {
fmt.Println("Validing Field")
verr := new(dslengine.ValidationErrors)
if field.Parent == nil {
verr.Add(field, "missing relational model parent")
}
if field.FieldName == "" {
verr.Add(field, "field name not defined")
}
return verr.AsError()
}