-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_exclusive_maximum.go
54 lines (44 loc) · 1.33 KB
/
c_exclusive_maximum.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
package constraint //nolint:dupl // Duplicates exclusive minimum with small differences.
import (
"strconv"
schema "github.com/jsightapi/jsight-schema-core"
"github.com/jsightapi/jsight-schema-core/bytes"
"github.com/jsightapi/jsight-schema-core/errs"
"github.com/jsightapi/jsight-schema-core/json"
)
type ExclusiveMaximum struct {
exclusive bool
}
var (
_ Constraint = ExclusiveMaximum{}
_ Constraint = (*ExclusiveMaximum)(nil)
)
func NewExclusiveMaximum(ruleValue bytes.Bytes) *ExclusiveMaximum {
c := ExclusiveMaximum{}
var err error
if c.exclusive, err = ruleValue.ParseBool(); err != nil {
panic(errs.ErrInvalidValueOfConstraint.F(ExclusiveMaximumConstraintType.String()))
}
return &c
}
func (ExclusiveMaximum) IsJsonTypeCompatible(t json.Type) bool {
return t == json.TypeInteger || t == json.TypeFloat
}
func (ExclusiveMaximum) Type() Type {
return ExclusiveMaximumConstraintType
}
func (c ExclusiveMaximum) String() string {
str := "[ UNVERIFIABLE CONSTRAINT ] " + ExclusiveMaximumConstraintType.String()
if c.exclusive {
str += colonTrue
} else {
str += colonFalse
}
return str
}
func (c ExclusiveMaximum) IsExclusive() bool {
return c.exclusive
}
func (c ExclusiveMaximum) ASTNode() schema.RuleASTNode {
return newRuleASTNode(schema.TokenTypeBoolean, strconv.FormatBool(c.exclusive), schema.RuleASTNodeSourceManual)
}