-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcustomcheckers.go
More file actions
57 lines (49 loc) · 2.28 KB
/
Copy pathcustomcheckers.go
File metadata and controls
57 lines (49 loc) · 2.28 KB
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
package customcheckers
import (
"fmt"
"github.com/oasdiff/oasdiff/checker"
"github.com/oasdiff/oasdiff/utils"
)
func GetAllChecks() checker.BackwardCompatibilityChecks {
return rulesToChecks(getAllRules())
}
func GetAllRules() checker.BackwardCompatibilityRules {
rules := []checker.BackwardCompatibilityRule{
newRule(XXgenOperationIdOverrideAddedId, checker.ERR, "", APIXXgenOperationIdOverrideUpdatedCheck, checker.DirectionNone, checker.LocationNone, checker.ActionAdd),
newRule(XXgenOperationIdOverrideRemovedId, checker.ERR, "", APIXXgenOperationIdOverrideUpdatedCheck, checker.DirectionNone, checker.LocationNone, checker.ActionRemove),
newRule(XXgenOperationIdOverrideModifiedId, checker.ERR, "", APIXXgenOperationIdOverrideUpdatedCheck, checker.DirectionNone, checker.LocationNone, checker.ActionChange),
}
return rules
}
func getAllRules() checker.BackwardCompatibilityRules {
rules := []checker.BackwardCompatibilityRule{
newRule(XXgenOperationIdOverrideAddedId, checker.ERR, "", APIXXgenOperationIdOverrideUpdatedCheck, checker.DirectionNone, checker.LocationNone, checker.ActionAdd),
newRule(XXgenOperationIdOverrideRemovedId, checker.ERR, "", APIXXgenOperationIdOverrideUpdatedCheck, checker.DirectionNone, checker.LocationNone, checker.ActionRemove),
newRule(XXgenOperationIdOverrideModifiedId, checker.ERR, "", APIXXgenOperationIdOverrideUpdatedCheck, checker.DirectionNone, checker.LocationNone, checker.ActionChange),
}
return rules
}
func newRule(id string, level checker.Level, description string, check checker.BackwardCompatibilityCheck, direction checker.Direction, location checker.Location, action checker.Action) checker.BackwardCompatibilityRule {
return checker.BackwardCompatibilityRule{
Id: id,
Level: level,
Description: description,
Handler: check,
Direction: direction,
Location: location,
Action: action,
}
}
func rulesToChecks(rules checker.BackwardCompatibilityRules) checker.BackwardCompatibilityChecks {
result := checker.BackwardCompatibilityChecks{}
m := utils.StringSet{}
for _, rule := range rules {
// functions are not comparable, so we convert them to strings
pStr := fmt.Sprintf("%v", rule.Handler)
if !m.Contains(pStr) {
m.Add(pStr)
result = append(result, rule.Handler)
}
}
return result
}