Skip to content

Commit

Permalink
example
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Nov 24, 2014
1 parent fdc1698 commit e5276f5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
57 changes: 32 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,50 @@ A basic example:
package main

import (
"fmt"
"github.com/mcuadros/go-jsonschema-generator"
"fmt"
"github.com/mcuadros/go-jsonschema-generator"
)

type ExampleBasic struct {
Foo bool `json:"foo"`
Bar string `json:",omitempty"`
Qux int8
Foo bool `json:"foo"`
Bar string `json:",omitempty"`
Qux int8
Baz []string
}

func main() {
j := &jsonschema.JSONSchema{}
j.Load(&ExampleBasic{})

fmt.Println(j)
s := &jsonschema.Schema{}
s.Load(&ExampleBasic{})
fmt.Println(s)
}

```

```json
{
"type": "object",
"properties": {
"Bar": {
"type": "string"
},
"Qux": {
"type": "integer"
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"Bar": {
"type": "string"
},
"Baz": {
"type": "array",
"items": {
"type": "string"
}
},
"Qux": {
"type": "integer"
},
"foo": {
"type": "bool"
}
},
"foo": {
"type": "bool"
}
},
"required": [
"foo",
"Qux"
]
"required": [
"foo",
"Qux",
"Baz"
]
}
```

Expand Down
8 changes: 4 additions & 4 deletions example/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ type ExampleBasic struct {
Foo bool `json:"foo"`
Bar string `json:",omitempty"`
Qux int8
Baz []string
}

func main() {
j := &jsonschema.JSONSchema{}
j.Load(&ExampleBasic{})

fmt.Println(j)
s := &jsonschema.Schema{}
s.Load(&ExampleBasic{})
fmt.Println(s)
}

0 comments on commit e5276f5

Please sign in to comment.