-
Notifications
You must be signed in to change notification settings - Fork 28
/
rule_datatype_int_format_standard_exist.go
47 lines (40 loc) · 1.39 KB
/
rule_datatype_int_format_standard_exist.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
package ruleintstdformat
import (
oas3 "github.com/getkin/kin-openapi/openapi3"
"github.com/grokify/mogo/net/urlutil"
"github.com/grokify/spectrum/openapi3"
"github.com/grokify/spectrum/openapi3lint/lintutil"
)
type RuleDatatypeIntFormatStandardExist struct {
name string
}
func NewRule() RuleDatatypeIntFormatStandardExist {
return RuleDatatypeIntFormatStandardExist{
name: lintutil.RulenameDatatypeIntFormatStandardExist}
}
func (rule RuleDatatypeIntFormatStandardExist) Name() string {
return rule.name
}
func (rule RuleDatatypeIntFormatStandardExist) Scope() string {
return lintutil.ScopeSpecification
}
func (rule RuleDatatypeIntFormatStandardExist) ProcessOperation(spec *openapi3.Spec, op *oas3.Operation, opPointer, path, method string) []lintutil.PolicyViolation {
return []lintutil.PolicyViolation{}
}
func (rule RuleDatatypeIntFormatStandardExist) ProcessSpec(spec *openapi3.Spec, pointerBase string) []lintutil.PolicyViolation {
vios := []lintutil.PolicyViolation{}
openapi3.VisitTypesFormats(
spec,
func(jsonPointerRoot, oasType, oasFormat string) {
if oasType == openapi3.TypeInteger &&
oasFormat != openapi3.FormatInt32 &&
oasFormat != openapi3.FormatInt64 {
vios = append(vios, lintutil.PolicyViolation{
RuleName: rule.Name(),
Location: urlutil.JoinAbsolute(pointerBase+jsonPointerRoot, "format"),
Value: oasFormat})
}
},
)
return vios
}