-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadme_test.go
38 lines (35 loc) · 1.05 KB
/
readme_test.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
package goschema_test
import (
"fmt"
"testing"
"github.com/creichlin/goschema"
)
func TestReadmeExample(t *testing.T) {
person = goschema.NewObjectType("example schema", func(p goschema.ObjectType) {
p.Attribute("firstName").String("")
p.Optional("lastName").String("")
p.Optional("is-old").Bool("is set when the person is considered to be old")
p.Optional("age").Int("in years").Min(0).Max(5)
p.Attribute("gender").Enum("describes the persons sex").
Add("male", "specimen").
Add("female", "specimen")
p.Attribute("hobbies").List(func(p goschema.ListType) {
p.String("all my hobbies")
})
p.Attribute("siblings").List(func(p goschema.ListType) {
p.Object("all my siblings", func(p goschema.ObjectType) {
p.Attribute("firstName").String("")
p.Optional("lastName").String("")
})
})
p.Attribute("results").Map(func(g goschema.MapType) {
g.SomeOf(func(g goschema.SomeOf) {
g.String("prosa")
g.Bool("technical")
})
})
})
fmt.Println(goschema.Doc(person))
fmt.Println()
fmt.Println(goschema.AsJSONSchema(person))
}