-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathcheck_new_request_non_path_default_parameter.go
55 lines (47 loc) · 1.52 KB
/
check_new_request_non_path_default_parameter.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
package checker
import (
"github.com/tufin/oasdiff/diff"
)
const (
NewRequiredRequestDefaultParameterToExistingPathId = "new-required-request-default-parameter-to-existing-path"
NewOptionalRequestDefaultParameterToExistingPathId = "new-optional-request-default-parameter-to-existing-path"
)
func NewRequestNonPathDefaultParameterCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config *Config) Changes {
result := make(Changes, 0)
if diffReport.PathsDiff == nil || len(diffReport.PathsDiff.Modified) == 0 {
return result
}
for path, pathItem := range diffReport.PathsDiff.Modified {
if pathItem.ParametersDiff == nil || pathItem.Revision == nil || len(pathItem.Revision.Operations()) == 0 {
continue
}
for paramLoc, paramNameList := range pathItem.ParametersDiff.Added {
if paramLoc == "path" {
continue
}
for _, param := range pathItem.Revision.Parameters {
if !paramNameList.Contains(param.Value.Name) {
continue
}
id := NewRequiredRequestDefaultParameterToExistingPathId
if !param.Value.Required {
id = NewOptionalRequestDefaultParameterToExistingPathId
}
for operation, operationItem := range pathItem.Revision.Operations() {
// TODO: if base operation had this param individually (not through the path) - continue
result = append(result, NewApiChange(
id,
config,
[]any{paramLoc, param.Value.Name},
"",
operationsSources,
operationItem,
operation,
path,
))
}
}
}
}
return result
}