Skip to content

Commit e5276f5

Browse files
committed
example
1 parent fdc1698 commit e5276f5

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

Diff for: README.md

+32-25
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,50 @@ A basic example:
2222
package main
2323

2424
import (
25-
"fmt"
26-
"github.com/mcuadros/go-jsonschema-generator"
25+
"fmt"
26+
"github.com/mcuadros/go-jsonschema-generator"
2727
)
2828

2929
type ExampleBasic struct {
30-
Foo bool `json:"foo"`
31-
Bar string `json:",omitempty"`
32-
Qux int8
30+
Foo bool `json:"foo"`
31+
Bar string `json:",omitempty"`
32+
Qux int8
33+
Baz []string
3334
}
3435

3536
func main() {
36-
j := &jsonschema.JSONSchema{}
37-
j.Load(&ExampleBasic{})
38-
39-
fmt.Println(j)
37+
s := &jsonschema.Schema{}
38+
s.Load(&ExampleBasic{})
39+
fmt.Println(s)
4040
}
41-
4241
```
4342

4443
```json
4544
{
46-
"type": "object",
47-
"properties": {
48-
"Bar": {
49-
"type": "string"
50-
},
51-
"Qux": {
52-
"type": "integer"
45+
"$schema": "http://json-schema.org/schema#",
46+
"type": "object",
47+
"properties": {
48+
"Bar": {
49+
"type": "string"
50+
},
51+
"Baz": {
52+
"type": "array",
53+
"items": {
54+
"type": "string"
55+
}
56+
},
57+
"Qux": {
58+
"type": "integer"
59+
},
60+
"foo": {
61+
"type": "bool"
62+
}
5363
},
54-
"foo": {
55-
"type": "bool"
56-
}
57-
},
58-
"required": [
59-
"foo",
60-
"Qux"
61-
]
64+
"required": [
65+
"foo",
66+
"Qux",
67+
"Baz"
68+
]
6269
}
6370
```
6471

Diff for: example/simple.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ type ExampleBasic struct {
99
Foo bool `json:"foo"`
1010
Bar string `json:",omitempty"`
1111
Qux int8
12+
Baz []string
1213
}
1314

1415
func main() {
15-
j := &jsonschema.JSONSchema{}
16-
j.Load(&ExampleBasic{})
17-
18-
fmt.Println(j)
16+
s := &jsonschema.Schema{}
17+
s.Load(&ExampleBasic{})
18+
fmt.Println(s)
1919
}

0 commit comments

Comments
 (0)