forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth_flow.go
69 lines (52 loc) · 2.14 KB
/
oauth_flow.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
package diff
import "github.com/rjmohammad/kin-openapi/openapi3"
// OAuthFlowDiff describes the changes between a pair of oauth flow objects: https://swagger.io/specification/#oauth-flow-object
type OAuthFlowDiff struct {
Added bool `json:"added,omitempty" yaml:"added,omitempty"`
Deleted bool `json:"deleted,omitempty" yaml:"deleted,omitempty"`
ExtensionsDiff *ExtensionsDiff `json:"extensions,omitempty" yaml:"extensions,omitempty"`
AuthorizationURLDiff *ValueDiff `json:"authorizationURL,omitempty" yaml:"authorizationURL,omitempty"`
TokenURLDiff *ValueDiff `json:"tokenURL,omitempty" yaml:"tokenURL,omitempty"`
RefreshURLDiff *ValueDiff `json:"refresh,omitempty" yaml:"refresh,omitempty"`
ScopesDiff *StringMapDiff `json:"scopes,omitempty" yaml:"scopes,omitempty"`
}
// Empty indicates whether a change was found in this element
func (diff *OAuthFlowDiff) Empty() bool {
return diff == nil || *diff == OAuthFlowDiff{}
}
func (diff *OAuthFlowDiff) removeNonBreaking() {
if diff.Empty() {
return
}
diff.ExtensionsDiff = nil
}
func getOAuthFlowDiff(config *Config, state *state, flow1, flow2 *openapi3.OAuthFlow) *OAuthFlowDiff {
diff := getOAuthFlowDiffInternal(config, state, flow1, flow2)
if config.BreakingOnly {
diff.removeNonBreaking()
}
if diff.Empty() {
return nil
}
return diff
}
func getOAuthFlowDiffInternal(config *Config, state *state, flow1, flow2 *openapi3.OAuthFlow) *OAuthFlowDiff {
if flow1 == nil && flow2 == nil {
return nil
}
result := OAuthFlowDiff{}
if flow1 == nil && flow2 != nil {
result.Added = true
return &result
}
if flow1 != nil && flow2 == nil {
result.Deleted = true
return &result
}
result.ExtensionsDiff = getExtensionsDiff(config, state, flow1.ExtensionProps, flow2.ExtensionProps)
result.AuthorizationURLDiff = getValueDiff(flow1.AuthorizationURL, flow2.AuthorizationURL)
result.TokenURLDiff = getValueDiff(flow1.TokenURL, flow2.TokenURL)
result.RefreshURLDiff = getValueDiff(flow1.RefreshURL, flow2.RefreshURL)
result.ScopesDiff = getStringMapDiff(flow1.Scopes, flow2.Scopes)
return &result
}