forked from Jonathan-Rosenberg/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tag_diff.go
35 lines (26 loc) · 1001 Bytes
/
tag_diff.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
package diff
import (
"github.com/getkin/kin-openapi/openapi3"
)
// TagDiff describes the changes between a pair of tag objects: https://swagger.io/specification/#tag-object
type TagDiff struct {
NameDiff *ValueDiff `json:"name,omitempty" yaml:"name,omitempty"`
DescriptionDiff *ValueDiff `json:"description,omitempty" yaml:"description,omitempty"`
}
// Empty indicates whether a change was found in this element
func (diff *TagDiff) Empty() bool {
return diff == nil || *diff == TagDiff{}
}
func getTagDiff(config *Config, state *state, tag1, tag2 *openapi3.Tag) *TagDiff {
diff := getTagDiffInternal(config, state, tag1, tag2)
if diff.Empty() {
return nil
}
return diff
}
func getTagDiffInternal(config *Config, state *state, tag1, tag2 *openapi3.Tag) *TagDiff {
result := TagDiff{}
result.NameDiff = getValueDiff(tag1.Name, tag2.Name)
result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), tag1.Description, tag2.Description)
return &result
}