forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-api-added.go
45 lines (38 loc) · 1.07 KB
/
check-api-added.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
package checker
import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/tufin/oasdiff/diff"
)
const (
EndpointAddedId = "endpoint-added"
)
func APIAddedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config *Config) Changes {
result := make(Changes, 0)
if diffReport.PathsDiff == nil {
return result
}
appendErr := func(path, opName string, opConfig *openapi3.Operation) {
result = append(result, ApiChange{
Id: EndpointAddedId,
Level: INFO,
Operation: opName,
OperationId: opConfig.OperationID,
Path: path,
Source: (*operationsSources)[opConfig],
})
}
for _, path := range diffReport.PathsDiff.Added {
for opName, op := range diffReport.PathsDiff.Revision.Value(path).Operations() {
appendErr(path, opName, op)
}
}
for path, pathDiff := range diffReport.PathsDiff.Modified {
for opName, op := range pathDiff.Revision.Operations() {
if _, foundInBase := pathDiff.Base.Operations()[opName]; foundInBase {
continue
}
appendErr(path, opName, op)
}
}
return result
}