-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_someof.go
99 lines (80 loc) · 1.89 KB
/
type_someof.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
package goschema
import "strconv"
type someOf struct {
baseType
subtypes []Type
}
func NewSomeOf(subTypes func(m SomeOf)) SomeOf {
gom := &someOf{
baseType: baseType{},
}
subTypes(gom)
return gom
}
func (g *someOf) asJSONSchema() map[string]interface{} {
data := map[string]interface{}{}
data["title"] = g.description
sts := []interface{}{}
for _, st := range g.subtypes {
sts = append(sts, st.asJSONSchema())
}
data["anyOf"] = sts
return data
}
func (g *someOf) docString(field string, docPrefix string) string {
dstr := docString(field, "", docPrefix, "any of")
for i, st := range g.subtypes {
dstr += st.docString(field+" ("+strconv.Itoa(i)+")", "")
}
return dstr
}
func (g *someOf) Bool(desc string) BoolType {
t := NewBoolType(desc)
g.subtypes = append(g.subtypes, t)
return t
}
func (g *someOf) String(desc string) StringType {
t := NewStringType(desc)
g.subtypes = append(g.subtypes, t)
return t
}
func (g *someOf) Null(desc string) NullType {
t := NewNullType(desc)
g.subtypes = append(g.subtypes, t)
return t
}
func (g *someOf) Any(desc string) AnyType {
t := NewAnyType(desc)
g.subtypes = append(g.subtypes, t)
return t
}
func (g *someOf) Object(desc string, ops func(ObjectType)) ObjectType {
t := NewObjectType(desc, ops)
g.subtypes = append(g.subtypes, t)
return t
}
func (g *someOf) SomeOf(ops func(SomeOf)) SomeOf {
t := NewSomeOf(ops)
g.subtypes = append(g.subtypes, t)
return t
}
func (g *someOf) Enum(desc string) EnumType {
t := NewEnumType(desc)
g.subtypes = append(g.subtypes, t)
return t
}
func (g *someOf) Int(desc string) IntType {
t := NewIntType(desc)
g.subtypes = append(g.subtypes, t)
return t
}
func (g *someOf) List(ops func(ListType)) ListType {
t := NewListType(ops)
g.subtypes = append(g.subtypes, t)
return t
}
func (g *someOf) Map(ops func(MapType)) MapType {
t := NewMapType("", ops)
g.subtypes = append(g.subtypes, t)
return t
}