forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
component_change.go
114 lines (88 loc) · 3 KB
/
component_change.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package checker
import (
"fmt"
"strings"
"github.com/TwiN/go-color"
)
// ComponentChange represnts a change in the Components Section: https://swagger.io/docs/specification/components/
type ComponentChange struct {
Id string `json:"id,omitempty" yaml:"id,omitempty"`
Args []any `json:"-" yaml:"-"`
Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
Level Level `json:"level" yaml:"level"`
Component string `json:"component,omitempty" yaml:"component,omitempty"`
SourceFile string `json:"-" yaml:"-"`
SourceLine int `json:"-" yaml:"-"`
SourceLineEnd int `json:"-" yaml:"-"`
SourceColumn int `json:"-" yaml:"-"`
SourceColumnEnd int `json:"-" yaml:"-"`
}
func (c ComponentChange) GetSection() string {
return "components"
}
func (c ComponentChange) IsBreaking() bool {
return c.GetLevel().IsBreaking()
}
func (c ComponentChange) MatchIgnore(ignorePath, ignoreLine string, l Localizer) bool {
return strings.Contains(ignoreLine, strings.ToLower(c.GetUncolorizedText(l))) &&
strings.Contains(ignoreLine, "components")
}
func (c ComponentChange) GetId() string {
return c.Id
}
func (c ComponentChange) GetText(l Localizer) string {
return l(c.Id, colorizedValues(c.Args)...)
}
func (c ComponentChange) GetArgs() []any {
return c.Args
}
func (c ComponentChange) GetUncolorizedText(l Localizer) string {
return l(c.Id, quotedValues(c.Args)...)
}
func (c ComponentChange) GetComment(l Localizer) string {
return l(c.Comment)
}
func (c ComponentChange) GetLevel() Level {
return c.Level
}
func (ComponentChange) GetOperation() string {
return ""
}
func (ComponentChange) GetOperationId() string {
return ""
}
func (ComponentChange) GetPath() string {
return ""
}
func (c ComponentChange) GetSource() string {
return ""
}
func (c ComponentChange) GetSourceFile() string {
return c.SourceFile
}
func (c ComponentChange) GetSourceLine() int {
return c.SourceLine
}
func (c ComponentChange) GetSourceLineEnd() int {
return c.SourceLineEnd
}
func (c ComponentChange) GetSourceColumn() int {
return c.SourceColumn
}
func (c ComponentChange) GetSourceColumnEnd() int {
return c.SourceColumnEnd
}
func (c ComponentChange) SingleLineError(l Localizer, colorMode ColorMode) string {
const format = "%s, %s components/%s %s [%s]. %s"
if isColorEnabled(colorMode) {
return fmt.Sprintf(format, c.Level.PrettyString(), l("in"), c.Component, c.GetText(l), color.InYellow(c.Id), c.GetComment(l))
}
return fmt.Sprintf(format, c.Level.String(), l("in"), c.Component, c.GetUncolorizedText(l), c.Id, c.GetComment(l))
}
func (c ComponentChange) MultiLineError(l Localizer, colorMode ColorMode) string {
const format = "%s\t[%s] \t\n\t%s components/%s\n\t\t%s%s"
if isColorEnabled(colorMode) {
return fmt.Sprintf(format, c.Level.PrettyString(), color.InYellow(c.Id), l("in"), c.Component, c.GetText(l), multiLineComment(c.GetComment(l)))
}
return fmt.Sprintf(format, c.Level.String(), c.Id, l("in"), c.Component, c.GetUncolorizedText(l), multiLineComment(c.GetComment(l)))
}