-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIntegerSchema.go
106 lines (82 loc) · 2.07 KB
/
IntegerSchema.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
package presilo
import (
"encoding/json"
)
/*
A schema which describes an integer.
*/
type IntegerSchema struct {
Schema
Minimum *int `json:"minimum"`
Maximum *int `json:"maximum"`
ExclusiveMaximum *bool `json:"exclusiveMaximum"`
ExclusiveMinimum *bool `json:"exclusiveMinimum"`
MultipleOf *int `json:"multipleOf"`
Enum *[]int `json:"enum"`
}
func NewIntegerSchema() *IntegerSchema {
ret := new(IntegerSchema)
ret.typeCode = SCHEMATYPE_INTEGER
return ret
}
/*
Creates a new integer schema from a byte slice that can be interpreted as json.
*/
func ParseIntegerSchema(contents []byte, context *SchemaParseContext) (*IntegerSchema, error) {
var ret *IntegerSchema
var err error
ret = NewIntegerSchema()
err = json.Unmarshal(contents, &ret)
if err != nil {
return ret, err
}
return ret, nil
}
func (this *IntegerSchema) HasConstraints() bool {
return this.Minimum != nil ||
this.Maximum != nil ||
this.MultipleOf != nil ||
this.Enum != nil
}
func (this *IntegerSchema) HasMinimum() bool {
return this.Minimum != nil
}
func (this *IntegerSchema) HasMaximum() bool {
return this.Maximum != nil
}
func (this *IntegerSchema) HasEnum() bool {
return this.Enum != nil
}
func (this *IntegerSchema) HasMultiple() bool {
return this.MultipleOf != nil
}
func (this *IntegerSchema) GetMinimum() interface{} {
return *this.Minimum
}
func (this *IntegerSchema) GetMaximum() interface{} {
return *this.Maximum
}
func (this *IntegerSchema) GetMultiple() interface{} {
return *this.MultipleOf
}
func (this *IntegerSchema) GetEnum() []interface{} {
var ret []interface{}
var enumValues []int
var length int
length = len(*this.Enum)
ret = make([]interface{}, length)
enumValues = *this.Enum
for i := 0; i < length; i++ {
ret[i] = enumValues[i]
}
return ret
}
func (this *IntegerSchema) IsExclusiveMaximum() bool {
return this.ExclusiveMaximum != nil
}
func (this *IntegerSchema) IsExclusiveMinimum() bool {
return this.ExclusiveMinimum != nil
}
func (this *IntegerSchema) GetConstraintFormat() string {
return "%d"
}