-
Notifications
You must be signed in to change notification settings - Fork 6
/
object.go
72 lines (59 loc) · 1.46 KB
/
object.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 builder
import (
"github.com/lestrrat-go/jsschema"
"github.com/lestrrat-go/jsval"
"github.com/lestrrat-go/pdebug"
)
func buildObjectConstraint(ctx *buildctx, c *jsval.ObjectConstraint, s *schema.Schema) error {
if pdebug.Enabled {
g := pdebug.IPrintf("START ObjectConstraint.FromSchema")
defer g.IRelease("END ObjectConstraint.FromSchema")
}
if l := s.Required; len(l) > 0 {
c.Required(l...)
}
if s.MinProperties.Initialized {
c.MinProperties(s.MinProperties.Val)
}
if s.MaxProperties.Initialized {
c.MaxProperties(s.MaxProperties.Val)
}
for pname, pdef := range s.Properties {
cprop, err := buildFromSchema(ctx, pdef)
if err != nil {
return err
}
c.AddProp(pname, cprop)
}
for rx, pdef := range s.PatternProperties {
cprop, err := buildFromSchema(ctx, pdef)
if err != nil {
return err
}
c.PatternProperties(rx, cprop)
}
if aprops := s.AdditionalProperties; aprops != nil {
if sc := aprops.Schema; sc != nil {
aitem, err := buildFromSchema(ctx, sc)
if err != nil {
return err
}
c.AdditionalProperties(aitem)
} else {
c.AdditionalProperties(jsval.EmptyConstraint)
}
}
for from, to := range s.Dependencies.Names {
c.PropDependency(from, to...)
}
if depschemas := s.Dependencies.Schemas; len(depschemas) > 0 {
for pname, depschema := range depschemas {
depc, err := buildFromSchema(ctx, depschema)
if err != nil {
return err
}
c.SchemaDependency(pname, depc)
}
}
return nil
}