-
Notifications
You must be signed in to change notification settings - Fork 1
/
StringSchema.go
72 lines (57 loc) · 1.39 KB
/
StringSchema.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
package presilo
import (
"encoding/json"
)
/*
A schema which describes an integer.
*/
type StringSchema struct {
Schema
MaxLength *int `json:"maxLength"`
MinLength *int `json:"minLength"`
Pattern *string `json:"pattern"`
MaxByteLength *int `json:"maxByteLength"`
MinByteLength *int `json:"minByteLength"`
Enum *[]string `json:"enum"`
}
func NewStringSchema() *StringSchema {
ret := new(StringSchema)
ret.typeCode = SCHEMATYPE_STRING
return ret
}
/*
Creates a new integer schema from a byte slice that can be interpreted as json.
*/
func ParseStringSchema(contents []byte, context *SchemaParseContext) (*StringSchema, error) {
var ret *StringSchema
var err error
ret = NewStringSchema()
err = json.Unmarshal(contents, &ret)
if err != nil {
return ret, err
}
return ret, nil
}
func (this *StringSchema) HasConstraints() bool {
return this.Enum != nil ||
this.MinLength != nil ||
this.MaxLength != nil ||
this.Pattern != nil ||
this.MaxByteLength != nil ||
this.MinByteLength != nil
}
func (this *StringSchema) HasEnum() bool {
return this.Enum != nil
}
func (this *StringSchema) GetEnum() []interface{} {
var ret []interface{}
var enumValues []string
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
}