-
Notifications
You must be signed in to change notification settings - Fork 5
/
api.go
52 lines (42 loc) · 1.14 KB
/
api.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
package api
import (
"github.com/samber/lo"
"github.com/teamkeel/keel/schema/parser"
"github.com/teamkeel/keel/schema/query"
"github.com/teamkeel/keel/schema/validation/errorhandling"
)
func UniqueAPINamesRule(asts []*parser.AST) (errs errorhandling.ValidationErrors) {
seenAPINames := map[string]bool{}
for _, api := range query.APIs(asts) {
if _, ok := seenAPINames[api.Name.Value]; ok {
errs.Append(errorhandling.ErrorUniqueAPIGlobally,
map[string]string{
"Name": api.Name.Value,
},
api.Name,
)
continue
}
seenAPINames[api.Name.Value] = true
}
return
}
func NamesCorrespondToModels(asts []*parser.AST) (errs errorhandling.ValidationErrors) {
modelNames := query.ModelNames(asts)
for _, api := range query.APIs(asts) {
for _, section := range api.Sections {
for _, model := range section.Models {
if !lo.Contains(modelNames, model.Name.Value) {
errs.Append(errorhandling.ErrorModelNotFound,
map[string]string{
"API": api.Name.Value,
"Model": model.Name.Value,
},
model.Name, // will highlight the name node in the preview
)
}
}
}
}
return errs
}