Repository navigation
Expand file tree
/
Copy pathNumberSchema.go
More file actions
106 lines (82 loc) · 2.11 KB
/
Copy pathNumberSchema.go
File metadata and controls
106 lines (82 loc) · 2.11 KB
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 a number, which may include floating point numbers.
*/
type NumberSchema struct {
Schema
Minimum *float64 `json:"minimum"`
Maximum *float64 `json:"maximum"`
ExclusiveMinimum *bool `json:"exclusiveMinimum"`
ExclusiveMaximum *bool `json:"exclusiveMaximum"`
MultipleOf *float64 `json:"multipleOf"`
Enum *[]float64 `json:"enum"`
}
func NewNumberSchema() *NumberSchema {
ret := new(NumberSchema)
ret.typeCode = SCHEMATYPE_NUMBER
return ret
}
/*
Creates a new integer schema from a byte slice that can be interpreted as json.
*/
func ParseNumberSchema(contents []byte, context *SchemaParseContext) (*NumberSchema, error) {
var ret *NumberSchema
var err error
ret = NewNumberSchema()
err = json.Unmarshal(contents, &ret)
if err != nil {
return ret, err
}
return ret, nil
}
func (this *NumberSchema) HasConstraints() bool {
return this.Minimum != nil ||
this.Maximum != nil ||
this.MultipleOf != nil ||
this.Enum != nil
}
func (this *NumberSchema) HasMinimum() bool {
return this.Minimum != nil
}
func (this *NumberSchema) HasMaximum() bool {
return this.Maximum != nil
}
func (this *NumberSchema) HasMultiple() bool {
return this.MultipleOf != nil
}
func (this *NumberSchema) HasEnum() bool {
return this.Enum != nil
}
func (this *NumberSchema) GetMinimum() interface{} {
return *this.Minimum
}
func (this *NumberSchema) GetMaximum() interface{} {
return *this.Maximum
}
func (this *NumberSchema) GetMultiple() interface{} {
return *this.MultipleOf
}
func (this *NumberSchema) GetEnum() []interface{} {
var ret []interface{}
var enumValues []float64
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 *NumberSchema) IsExclusiveMaximum() bool {
return this.ExclusiveMaximum != nil
}
func (this *NumberSchema) IsExclusiveMinimum() bool {
return this.ExclusiveMinimum != nil
}
func (this *NumberSchema) GetConstraintFormat() string {
return "%f"
}